Migration DotNetCore

This commit is contained in:
2020-09-13 22:50:52 +02:00
parent be9a2f2815
commit 488431c123
14 changed files with 59 additions and 40 deletions

View File

@@ -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<IGameService, Game, GameDTO>
{
public GameController(IGameService service) : base(service)
public GameController(IMapper mapper,IGameService service) : base(mapper,service)
{
}
}

View File

@@ -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<T, TU, D> : Controller where TU : Entity.Context.Entity where T : IBaseService<TU>
{
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<TU>(dto);
return AutoMapper.Mapper.Map<D>(_service.AddOrUpdate(entity));
TU entity = _mapper.Map<TU>(dto);
return _mapper.Map<D>(_service.AddOrUpdate(entity));
}
[HttpGet]
public List<D> Get()
{
return AutoMapper.Mapper.Map<List<D>>(_service.GetAll().ToList());
return _mapper.Map<List<D>>(_service.GetAll().ToList());
}
[HttpGet("{id}")]
public D Get(int id)
{
return AutoMapper.Mapper.Map<D>(_service.GetById(id));
return _mapper.Map<D>(_service.GetById(id));
}
[HttpDelete("{id}")]

View File

@@ -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<ITodoService, Todo, TodoDTO>
{
public TodoController(ITodoService service) : base(service)
public TodoController(IMapper mapper,ITodoService service) : base(mapper,service)
{
}

View File

@@ -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;
// GET
public TournamentController(ITournamentService service)
{
private IMapper _mapper;
// GET
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<List<TournamentDTO>>(tournaments);
return _mapper.Map<List<TournamentDTO>>(tournaments);
}
@@ -47,7 +51,7 @@ namespace LaDOSE.Api.Controllers
}
var tournamentsResult = await _service.GetTournamentsResult(ids);
return AutoMapper.Mapper.Map<TournamentsResultDTO>(tournamentsResult);
return _mapper.Map<TournamentsResultDTO>(tournamentsResult);
}
}

View File

@@ -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<List<WPEventDTO>>(wpEvents);
return _mapper.Map<List<WPEventDTO>>(wpEvents);
}
@@ -54,21 +56,21 @@ namespace LaDOSE.Api.Controllers
wpEventWpBooking.WPUser.WPBookings = null;
}
return Mapper.Map<WPEventDTO>(wpEvents);
return _mapper.Map<WPEventDTO>(wpEvents);
}
[HttpGet("GetUsers/{wpEventId}/{gameId}")]
public List<WPUserDTO> GetUsers(int wpEventId, int gameId)
{
var game = GameService.GetById(gameId);
return Mapper.Map<List<WPUserDTO>>(_service.GetBooking(wpEventId, game));
return _mapper.Map<List<WPUserDTO>>(_service.GetBooking(wpEventId, game));
}
[HttpGet("GetUsersOptions/{wpEventId}/{gameId}")]
public List<WPUserDTO> GetUsersOptions(int wpEventId, int gameId)
{
var game = GameService.GetById(gameId);
return Mapper.Map<List<WPUserDTO>>(_service.GetBookingOptions(wpEventId, game));
return _mapper.Map<List<WPUserDTO>>(_service.GetBookingOptions(wpEventId, game));
}

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
@@ -10,11 +10,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.2" />
<PackageReference Include="AutoMapper" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.2" />
</ItemGroup>
<ItemGroup>

View File

@@ -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

View File

@@ -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<WPUser, LaDOSE.DTO.WPUserDTO>();
cfg.CreateMap<WPUser, LaDOSE.DTO.WPUserDTO>();
@@ -131,6 +131,9 @@ namespace LaDOSE.Api
cfg.CreateMapTwoWay<Todo, LaDOSE.DTO.TodoDTO>();
});
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());
}
}
}

View File

@@ -81,8 +81,8 @@
<Reference Include="Caliburn.Micro.Platform.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.Core.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=106.6.9.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.106.6.9\lib\net452\RestSharp.dll</HintPath>
<Reference Include="RestSharp, Version=106.11.4.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.106.11.4\lib\net452\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />

View File

@@ -6,6 +6,6 @@
<package id="cef.redist.x86" version="73.1.13" targetFramework="net461" />
<package id="CefSharp.Common" version="73.1.130" targetFramework="net461" />
<package id="CefSharp.Wpf" version="73.1.130" targetFramework="net461" />
<package id="RestSharp" version="106.6.9" targetFramework="net461" />
<package id="RestSharp" version="106.11.4" targetFramework="net461" />
<package id="WPFThemes.DarkBlend" version="1.0.8" targetFramework="net461" />
</packages>

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
@@ -10,8 +10,8 @@
<PackageReference Include="DSharpPlus" Version="3.2.3" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="3.2.3" />
<PackageReference Include="DSharpPlus.Interactivity" Version="3.2.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.1.2" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.2" />
</ItemGroup>
</Project>

View File

@@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RestSharp" Version="106.6.9" />
<PackageReference Include="RestSharp" Version="106.11.4" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>LaDOSE.Business</AssemblyName>
<RootNamespace>LaDOSE.Business</RootNamespace>
<Platforms>AnyCPU;x64</Platforms>