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;
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);
}
}

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));
}