Migration DotNetCore
This commit is contained in:
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}")]
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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<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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user