From 488431c1239949584832eddf326e4e23bbc677bf Mon Sep 17 00:00:00 2001 From: Darkstack <1835601+darkstack@users.noreply.github.com> Date: Sun, 13 Sep 2020 22:50:52 +0200 Subject: [PATCH] Migration DotNetCore --- .../LaDOSE.Api/Controllers/GameController.cs | 3 ++- .../Controllers/GenericControllerDTO.cs | 13 ++++++++----- .../LaDOSE.Api/Controllers/TodoController.cs | 5 +++-- .../Controllers/TournamentController.cs | 12 ++++++++---- .../Controllers/WordPressController.cs | 12 +++++++----- LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj | 14 ++++++++------ LaDOSE.Src/LaDOSE.Api/Program.cs | 2 +- LaDOSE.Src/LaDOSE.Api/Startup.cs | 18 ++++++++++++------ .../LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj | 4 ++-- LaDOSE.Src/LaDOSE.DesktopApp/packages.config | 2 +- .../LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj | 6 +++--- LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj | 4 ++-- LaDOSE.Src/LaDOSE.REST/LaDOSE.REST.csproj | 2 +- .../LaDOSE.Service/LaDOSE.Business.csproj | 2 +- 14 files changed, 59 insertions(+), 40 deletions(-) diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs index b2955c0..f9e7c1d 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using AutoMapper; using LaDOSE.Business.Interface; using LaDOSE.DTO; using LaDOSE.Entity; @@ -16,7 +17,7 @@ namespace LaDOSE.Api.Controllers [Produces("application/json")] public class GameController : GenericControllerDTO { - public GameController(IGameService service) : base(service) + public GameController(IMapper mapper,IGameService service) : base(mapper,service) { } } diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs index cb6d49e..98e7715 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using AutoMapper; using LaDOSE.Business.Interface; using Microsoft.AspNetCore.Mvc; @@ -8,30 +9,32 @@ namespace LaDOSE.Api.Controllers { public class GenericControllerDTO : Controller where TU : Entity.Context.Entity where T : IBaseService { + protected IMapper _mapper; protected T _service; - public GenericControllerDTO(T service) + public GenericControllerDTO(IMapper mapper, T service) { + _mapper = mapper; _service = service; } [HttpPost] public D Post([FromBody]D dto) { - TU entity = AutoMapper.Mapper.Map(dto); - return AutoMapper.Mapper.Map(_service.AddOrUpdate(entity)); + TU entity = _mapper.Map(dto); + return _mapper.Map(_service.AddOrUpdate(entity)); } [HttpGet] public List Get() { - return AutoMapper.Mapper.Map>(_service.GetAll().ToList()); + return _mapper.Map>(_service.GetAll().ToList()); } [HttpGet("{id}")] public D Get(int id) { - return AutoMapper.Mapper.Map(_service.GetById(id)); + return _mapper.Map(_service.GetById(id)); } [HttpDelete("{id}")] diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/TodoController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/TodoController.cs index 2c7843b..f012803 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/TodoController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/TodoController.cs @@ -1,4 +1,5 @@ -using LaDOSE.Business.Interface; +using AutoMapper; +using LaDOSE.Business.Interface; using LaDOSE.DTO; using LaDOSE.Entity; using Microsoft.AspNetCore.Authorization; @@ -11,7 +12,7 @@ namespace LaDOSE.Api.Controllers [Produces("application/json")] public class TodoController : GenericControllerDTO { - public TodoController(ITodoService service) : base(service) + public TodoController(IMapper mapper,ITodoService service) : base(mapper,service) { } diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs index 533cb83..8d08b86 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using AutoMapper; using LaDOSE.Business.Interface; using LaDOSE.DTO; using Microsoft.AspNetCore.Authorization; @@ -15,10 +16,13 @@ namespace LaDOSE.Api.Controllers { private ITournamentService _service; + + private IMapper _mapper; + // GET - public TournamentController(ITournamentService service) + public TournamentController(IMapper mapper,ITournamentService service) { - + _mapper = mapper; _service = service; } //This may be a get , but i dont know what the RFC State for Get request with Body @@ -30,7 +34,7 @@ namespace LaDOSE.Api.Controllers if (dto.To.HasValue | dto.From.HasValue) { var tournaments = await _service.GetTournaments(dto.From, dto.To); - return AutoMapper.Mapper.Map>(tournaments); + return _mapper.Map>(tournaments); } @@ -47,7 +51,7 @@ namespace LaDOSE.Api.Controllers } var tournamentsResult = await _service.GetTournamentsResult(ids); - return AutoMapper.Mapper.Map(tournamentsResult); + return _mapper.Map(tournamentsResult); } } diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs index a9cf763..473b807 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs @@ -13,13 +13,15 @@ namespace LaDOSE.Api.Controllers [Route("api/[controller]")] public class WordPressController : Controller { + private readonly IMapper _mapper; public IGameService GameService { get; } private IWordPressService _service; // GET - public WordPressController(IWordPressService service, IGameService gameService) + public WordPressController(IMapper mapper,IWordPressService service, IGameService gameService) { + _mapper = mapper; GameService = gameService; _service = service; } @@ -38,7 +40,7 @@ namespace LaDOSE.Api.Controllers } } - return Mapper.Map>(wpEvents); + return _mapper.Map>(wpEvents); } @@ -54,21 +56,21 @@ namespace LaDOSE.Api.Controllers wpEventWpBooking.WPUser.WPBookings = null; } - return Mapper.Map(wpEvents); + return _mapper.Map(wpEvents); } [HttpGet("GetUsers/{wpEventId}/{gameId}")] public List GetUsers(int wpEventId, int gameId) { var game = GameService.GetById(gameId); - return Mapper.Map>(_service.GetBooking(wpEventId, game)); + return _mapper.Map>(_service.GetBooking(wpEventId, game)); } [HttpGet("GetUsersOptions/{wpEventId}/{gameId}")] public List GetUsersOptions(int wpEventId, int gameId) { var game = GameService.GetById(gameId); - return Mapper.Map>(_service.GetBookingOptions(wpEventId, game)); + return _mapper.Map>(_service.GetBookingOptions(wpEventId, game)); } diff --git a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj index 1672d1d..6bff4ba 100644 --- a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj +++ b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0 + netcoreapp3.1 AnyCPU;x64 @@ -10,11 +10,13 @@ - - - - - + + + + + + + diff --git a/LaDOSE.Src/LaDOSE.Api/Program.cs b/LaDOSE.Src/LaDOSE.Api/Program.cs index 5de33ec..cfc7cce 100644 --- a/LaDOSE.Src/LaDOSE.Api/Program.cs +++ b/LaDOSE.Src/LaDOSE.Api/Program.cs @@ -7,7 +7,7 @@ using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Internal; +//using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace LaDOSE.Api diff --git a/LaDOSE.Src/LaDOSE.Api/Startup.cs b/LaDOSE.Src/LaDOSE.Api/Startup.cs index b51c744..be962ab 100644 --- a/LaDOSE.Src/LaDOSE.Api/Startup.cs +++ b/LaDOSE.Src/LaDOSE.Api/Startup.cs @@ -63,7 +63,7 @@ namespace LaDOSE.Api } services.AddCors(); - services.AddMvc().AddJsonOptions(x => + services.AddMvc().AddNewtonsoftJson(x => { x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; x.SerializerSettings.MaxDepth= 4; @@ -114,7 +114,7 @@ namespace LaDOSE.Api // configure DI for application services AddDIConfig(services); - Mapper.Initialize(cfg => + var mapperConfig = new MapperConfiguration(cfg => { cfg.CreateMap(); cfg.CreateMap(); @@ -131,6 +131,9 @@ namespace LaDOSE.Api cfg.CreateMapTwoWay(); }); + IMapper mapper = mapperConfig.CreateMapper(); + services.AddSingleton(mapper); + } private void AddDIConfig(IServiceCollection services) @@ -151,8 +154,8 @@ namespace LaDOSE.Api // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - loggerFactory.AddConsole(Configuration.GetSection("Logging")); - loggerFactory.AddDebug(); + //loggerFactory.AddConsole(Configuration.GetSection("Logging")); + //loggerFactory.AddDebug(); if (env.IsDevelopment()) { @@ -160,14 +163,17 @@ namespace LaDOSE.Api } app.UseCors(x => x - .AllowAnyOrigin() + //.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() + .SetIsOriginAllowed(origin => true) .AllowCredentials()); //app.UseHttpsRedirection(); + app.UseRouting(); app.UseAuthentication(); - app.UseMvc(); + app.UseAuthorization(); + app.UseEndpoints(x => x.MapControllers()); } } } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj b/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj index f464ecd..e9dfe24 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj +++ b/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj @@ -81,8 +81,8 @@ ..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.Core.dll - - ..\packages\RestSharp.106.6.9\lib\net452\RestSharp.dll + + ..\packages\RestSharp.106.11.4\lib\net452\RestSharp.dll diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/packages.config b/LaDOSE.Src/LaDOSE.DesktopApp/packages.config index 774893c..675d27b 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/packages.config +++ b/LaDOSE.Src/LaDOSE.DesktopApp/packages.config @@ -6,6 +6,6 @@ - + \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj b/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj index d5a04aa..10cd81d 100644 --- a/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj +++ b/LaDOSE.Src/LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + netcoreapp3.1 AnyCPU;x64 @@ -10,8 +10,8 @@ - - + + diff --git a/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj b/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj index 4284f6e..df42621 100644 --- a/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj +++ b/LaDOSE.Src/LaDOSE.Entity/LaDOSE.Entity.csproj @@ -1,12 +1,12 @@ - netcoreapp2.0 + netcoreapp3.1 AnyCPU;x64 - + diff --git a/LaDOSE.Src/LaDOSE.REST/LaDOSE.REST.csproj b/LaDOSE.Src/LaDOSE.REST/LaDOSE.REST.csproj index cff4de8..2393b06 100644 --- a/LaDOSE.Src/LaDOSE.REST/LaDOSE.REST.csproj +++ b/LaDOSE.Src/LaDOSE.REST/LaDOSE.REST.csproj @@ -6,7 +6,7 @@ - + diff --git a/LaDOSE.Src/LaDOSE.Service/LaDOSE.Business.csproj b/LaDOSE.Src/LaDOSE.Service/LaDOSE.Business.csproj index 959911e..21919f3 100644 --- a/LaDOSE.Src/LaDOSE.Service/LaDOSE.Business.csproj +++ b/LaDOSE.Src/LaDOSE.Service/LaDOSE.Business.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0 + netcoreapp3.1 LaDOSE.Business LaDOSE.Business AnyCPU;x64