Add AutoMapper
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LaDOSE.Business.Interface;
|
||||
using LaDOSE.DTO;
|
||||
using LaDOSE.Entity;
|
||||
using LaDOSE.Entity.Context;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -13,7 +14,7 @@ namespace LaDOSE.Api.Controllers
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[Produces("application/json")]
|
||||
public class GameController : GenericController<IGameService, Game>
|
||||
public class GameController : GenericControllerDTO<IGameService, Game, GameDTO>
|
||||
{
|
||||
public GameController(IGameService service) : base(service)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LaDOSE.Api.Controllers
|
||||
{
|
||||
public class GenericController<T,TU> :Controller where TU : Entity.Context.Entity where T : IBaseService<TU>
|
||||
public class GenericController<T, TU> : Controller where TU : Entity.Context.Entity where T : IBaseService<TU>
|
||||
{
|
||||
protected T _service;
|
||||
|
||||
@@ -16,10 +16,11 @@ namespace LaDOSE.Api.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public TU Post([FromBody]TU dto)
|
||||
public TU Post([FromBody] TU dto)
|
||||
{
|
||||
return _service.AddOrUpdate(dto);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<TU> Get()
|
||||
{
|
||||
@@ -27,6 +28,7 @@ namespace LaDOSE.Api.Controllers
|
||||
return _service.GetAll().ToList();
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public TU Get(int id)
|
||||
{
|
||||
|
||||
37
LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs
Normal file
37
LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LaDOSE.Business.Interface;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LaDOSE.Api.Controllers
|
||||
{
|
||||
public class GenericControllerDTO<T, TU, D> : Controller where TU : Entity.Context.Entity where T : IBaseService<TU>
|
||||
{
|
||||
protected T _service;
|
||||
|
||||
public GenericControllerDTO(T service)
|
||||
{
|
||||
_service = service;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public D Post([FromBody]D dto)
|
||||
{
|
||||
TU entity = AutoMapper.Mapper.Map<TU>(dto);
|
||||
return AutoMapper.Mapper.Map<D>(_service.AddOrUpdate(entity));
|
||||
}
|
||||
[HttpGet]
|
||||
public List<D> Get()
|
||||
{
|
||||
|
||||
return AutoMapper.Mapper.Map<List<D>>(_service.GetAll().ToList());
|
||||
|
||||
}
|
||||
[HttpGet("{id}")]
|
||||
public D Get(int id)
|
||||
{
|
||||
return AutoMapper.Mapper.Map<D>(_service.GetById(id));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using AutoMapper;
|
||||
using LaDOSE.Business.Interface;
|
||||
using LaDOSE.DTO;
|
||||
using LaDOSE.Entity.Wordpress;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -24,7 +26,7 @@ namespace LaDOSE.Api.Controllers
|
||||
|
||||
|
||||
[HttpGet("WPEvent")]
|
||||
public List<WPEvent> Event()
|
||||
public List<WPEventDTO> Event()
|
||||
{
|
||||
var wpEvents = _service.GetWpEvent();
|
||||
foreach (var wpEvent in wpEvents)
|
||||
@@ -36,22 +38,22 @@ namespace LaDOSE.Api.Controllers
|
||||
wpEventWpBooking.WPUser.WPBookings = null;
|
||||
}
|
||||
}
|
||||
return wpEvents;
|
||||
return Mapper.Map<List<WPEventDTO>>(wpEvents);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("GetUsers/{wpEventId}/{gameId}")]
|
||||
public List<WPUser> GetUsers(int wpEventId, int gameId)
|
||||
public List<WPUserDTO> GetUsers(int wpEventId, int gameId)
|
||||
{
|
||||
var game = GameService.GetById(gameId);
|
||||
return _service.GetBooking(wpEventId, game);
|
||||
return Mapper.Map<List<WPUserDTO>>(_service.GetBooking(wpEventId, game));
|
||||
|
||||
}
|
||||
[HttpGet("GetUsersOptions/{wpEventId}/{gameId}")]
|
||||
public List<WPUser> GetUsersOptions(int wpEventId, int gameId)
|
||||
public List<WPUserDTO> GetUsersOptions(int wpEventId, int gameId)
|
||||
{
|
||||
var game = GameService.GetById(gameId);
|
||||
return _service.GetBookingOptions(wpEventId, game);
|
||||
return Mapper.Map<List<WPUserDTO>>(_service.GetBookingOptions(wpEventId, game));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user