diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs index 58398cf..b2955c0 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GameController.cs @@ -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 + public class GameController : GenericControllerDTO { public GameController(IGameService service) : base(service) { diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs index afd7840..7a2b7aa 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc; namespace LaDOSE.Api.Controllers { - public class GenericController :Controller where TU : Entity.Context.Entity where T : IBaseService + public class GenericController : Controller where TU : Entity.Context.Entity where T : IBaseService { 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 Get() { @@ -27,6 +28,7 @@ namespace LaDOSE.Api.Controllers return _service.GetAll().ToList(); } + [HttpGet("{id}")] public TU Get(int id) { diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs new file mode 100644 index 0000000..747e1a1 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs @@ -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 : Controller where TU : Entity.Context.Entity where T : IBaseService + { + protected T _service; + + public GenericControllerDTO(T service) + { + _service = service; + } + + [HttpPost] + public D Post([FromBody]D dto) + { + TU entity = AutoMapper.Mapper.Map(dto); + return AutoMapper.Mapper.Map(_service.AddOrUpdate(entity)); + } + [HttpGet] + public List Get() + { + + return AutoMapper.Mapper.Map>(_service.GetAll().ToList()); + + } + [HttpGet("{id}")] + public D Get(int id) + { + return AutoMapper.Mapper.Map(_service.GetById(id)); + + } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs index b5be32b..4733ad7 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/WordPressController.cs @@ -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 Event() + public List 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>(wpEvents); } [HttpGet("GetUsers/{wpEventId}/{gameId}")] - public List GetUsers(int wpEventId, int gameId) + public List GetUsers(int wpEventId, int gameId) { var game = GameService.GetById(gameId); - return _service.GetBooking(wpEventId, game); + return Mapper.Map>(_service.GetBooking(wpEventId, game)); } [HttpGet("GetUsersOptions/{wpEventId}/{gameId}")] - public List GetUsersOptions(int wpEventId, int gameId) + public List GetUsersOptions(int wpEventId, int gameId) { var game = GameService.GetById(gameId); - return _service.GetBookingOptions(wpEventId, game); + return Mapper.Map>(_service.GetBookingOptions(wpEventId, game)); } diff --git a/LaDOSE.Src/LaDOSE.Api/Helpers/AutoMapperTwoWay.cs b/LaDOSE.Src/LaDOSE.Api/Helpers/AutoMapperTwoWay.cs new file mode 100644 index 0000000..92acf05 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Api/Helpers/AutoMapperTwoWay.cs @@ -0,0 +1,15 @@ +using AutoMapper; +using AutoMapper.Configuration; + +namespace LaDOSE.Api.Helpers +{ + public static class AutoMapperTwoWay + { + public static void CreateMapTwoWay(this IMapperConfigurationExpression mapper) + { + mapper.CreateMap().IgnoreAllPropertiesWithAnInaccessibleSetter().IgnoreAllSourcePropertiesWithAnInaccessibleSetter(); + mapper.CreateMap().IgnoreAllPropertiesWithAnInaccessibleSetter().IgnoreAllSourcePropertiesWithAnInaccessibleSetter(); + + } + } +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj index c0e2e74..efe903b 100644 --- a/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj +++ b/LaDOSE.Src/LaDOSE.Api/LaDOSE.Api.csproj @@ -5,11 +5,11 @@ - + @@ -17,6 +17,7 @@ + diff --git a/LaDOSE.Src/LaDOSE.Api/Startup.cs b/LaDOSE.Src/LaDOSE.Api/Startup.cs index 7f37150..bf6f8c7 100644 --- a/LaDOSE.Src/LaDOSE.Api/Startup.cs +++ b/LaDOSE.Src/LaDOSE.Api/Startup.cs @@ -23,6 +23,9 @@ using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; using Pomelo.EntityFrameworkCore.MySql; using Pomelo.EntityFrameworkCore.MySql.Infrastructure; +using AutoMapper; +using LaDOSE.Api.Helpers; +using LaDOSE.Entity.Wordpress; namespace LaDOSE.Api { @@ -56,7 +59,7 @@ namespace LaDOSE.Api Console.WriteLine($"Fix Gentoo NOK : {exception.Message}"); } } - + services.AddCors(); services.AddMvc().AddJsonOptions(x => { @@ -105,9 +108,19 @@ namespace LaDOSE.Api ValidateAudience = false }; }); - + // configure DI for application services AddDIConfig(services); + Mapper.Initialize(cfg => + { + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMapTwoWay(); + + }); } private void AddDIConfig(IServiceCollection services) diff --git a/LaDOSE.Src/LaDOSE.DTO/Game.cs b/LaDOSE.Src/LaDOSE.DTO/GameDTO.cs similarity index 91% rename from LaDOSE.Src/LaDOSE.DTO/Game.cs rename to LaDOSE.Src/LaDOSE.DTO/GameDTO.cs index 65e9468..309c233 100644 --- a/LaDOSE.Src/LaDOSE.DTO/Game.cs +++ b/LaDOSE.Src/LaDOSE.DTO/GameDTO.cs @@ -1,6 +1,6 @@ namespace LaDOSE.DTO { - public class Game + public class GameDTO { public int Id { get; set; } public string Name { get; set; } diff --git a/LaDOSE.Src/LaDOSE.DTO/WpBooking.cs b/LaDOSE.Src/LaDOSE.DTO/WPBookingDTO.cs similarity index 62% rename from LaDOSE.Src/LaDOSE.DTO/WpBooking.cs rename to LaDOSE.Src/LaDOSE.DTO/WPBookingDTO.cs index c2ced85..0b3484c 100644 --- a/LaDOSE.Src/LaDOSE.DTO/WpBooking.cs +++ b/LaDOSE.Src/LaDOSE.DTO/WPBookingDTO.cs @@ -1,8 +1,8 @@ namespace LaDOSE.DTO { - public class WPBooking + public class WPBookingDTO { - public WPUser WpUser { get; set; } + public WPUserDTO WpUser { get; set; } public string Message { get; set; } public string Meta { get; set; } diff --git a/LaDOSE.Src/LaDOSE.DTO/WPEvent.cs b/LaDOSE.Src/LaDOSE.DTO/WPEventDTO.cs similarity index 76% rename from LaDOSE.Src/LaDOSE.DTO/WPEvent.cs rename to LaDOSE.Src/LaDOSE.DTO/WPEventDTO.cs index 5b08cfe..c44af4e 100644 --- a/LaDOSE.Src/LaDOSE.DTO/WPEvent.cs +++ b/LaDOSE.Src/LaDOSE.DTO/WPEventDTO.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; namespace LaDOSE.DTO { - public class WPEvent + public class WPEventDTO { // Id, Name, Slug, Date @@ -12,6 +12,6 @@ namespace LaDOSE.DTO public string Name { get; set; } public string Slug { get; set; } public DateTime? Date { get; set; } - public List WpBookings { get; set; } + public List WpBookings { get; set; } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DTO/WPUser.cs b/LaDOSE.Src/LaDOSE.DTO/WPUserDTO.cs similarity index 80% rename from LaDOSE.Src/LaDOSE.DTO/WPUser.cs rename to LaDOSE.Src/LaDOSE.DTO/WPUserDTO.cs index 85b305f..61b68db 100644 --- a/LaDOSE.Src/LaDOSE.DTO/WPUser.cs +++ b/LaDOSE.Src/LaDOSE.DTO/WPUserDTO.cs @@ -1,6 +1,6 @@ namespace LaDOSE.DTO { - public class WPUser + public class WPUserDTO { public string Id { get; set; } public string Name { get; set; } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs index f2f810f..7597dcf 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs @@ -17,7 +17,9 @@ namespace LaDOSE.DesktopApp.Services public RestService() { - +#if DEBUG + MessageBox.Show("WAIT"); +#endif var appSettings = ConfigurationManager.AppSettings; string url = (string) appSettings["ApiUri"]; string user = (string)appSettings["ApiUser"]; @@ -95,10 +97,10 @@ namespace LaDOSE.DesktopApp.Services #endregion #region WordPress - public List GetEvents() + public List GetEvents() { var restRequest = new RestRequest("/api/wordpress/WPEvent", Method.GET); - var restResponse = Client.Get>(restRequest); + var restResponse = Client.Get>(restRequest); return restResponse.Data; } @@ -109,10 +111,10 @@ namespace LaDOSE.DesktopApp.Services var restResponse = Client.Get(restRequest); return restResponse.Content; } - public string CreateChallonge2(int gameId, int eventId, List optionalPlayers) + public string CreateChallonge2(int gameId, int eventId, List optionalPlayers) { - var restResponse = Post,string>($"/api/wordpress/CreateChallonge/{gameId}/{eventId}",optionalPlayers); + var restResponse = Post,string>($"/api/wordpress/CreateChallonge/{gameId}/{eventId}",optionalPlayers); return restResponse; } public bool RefreshDb() @@ -122,17 +124,17 @@ namespace LaDOSE.DesktopApp.Services return restResponse.Data; } - public List GetUsers(int wpEventId, int gameId) + public List GetUsers(int wpEventId, int gameId) { var restRequest = new RestRequest($"/api/Wordpress/GetUsers/{wpEventId}/{gameId}", Method.GET); - var restResponse = Client.Get>(restRequest); + var restResponse = Client.Get>(restRequest); return restResponse.Data; } - public List GetUsersOptions(int wpEventId, int gameId) + public List GetUsersOptions(int wpEventId, int gameId) { var restRequest = new RestRequest($"/api/Wordpress/GetUsersOptions/{wpEventId}/{gameId}", Method.GET); - var restResponse = Client.Get>(restRequest); + var restResponse = Client.Get>(restRequest); return restResponse.Data; } @@ -140,14 +142,14 @@ namespace LaDOSE.DesktopApp.Services #endregion #region Games - public List GetGames() + public List GetGames() { var restRequest = new RestRequest("/api/Game", Method.GET); - var restResponse = Client.Get>(restRequest); + var restResponse = Client.Get>(restRequest); return restResponse.Data; } - public Game UpdateGame(Game eventUpdate) + public GameDTO UpdateGame(GameDTO eventUpdate) { return Post("Api/Game", eventUpdate); } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs index 75ac9d6..6ff7298 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs @@ -9,13 +9,13 @@ namespace LaDOSE.DesktopApp.ViewModels { public override string DisplayName => "Games"; - private Game _currentGame; - private List _games; + private GameDTO _currentGame; + private List _games; private RestService RestService { get; set; } public GameViewModel(RestService restService) { this.RestService = restService; - this.Games=new List(); + this.Games=new List(); } @@ -32,7 +32,7 @@ namespace LaDOSE.DesktopApp.ViewModels NotifyOfPropertyChange("Games"); } - public List Games + public List Games { get => _games; set @@ -42,7 +42,7 @@ namespace LaDOSE.DesktopApp.ViewModels } } - public Game CurrentGame + public GameDTO CurrentGame { get => _currentGame; set @@ -59,7 +59,7 @@ namespace LaDOSE.DesktopApp.ViewModels } public void AddGame() { - var item = new Game(); + var item = new GameDTO(); this.Games.Add(item); this.CurrentGame = item; } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs index 3137fc6..e6813d3 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs @@ -18,20 +18,20 @@ namespace LaDOSE.DesktopApp.ViewModels public class WordPressViewModel : Screen { public override string DisplayName => "Events"; - private WPEvent _selectedWpEvent; - private Game _selectedGame; - private ObservableCollection _players; - private ObservableCollection _playersOptions; - private ObservableCollection _optionalPlayers; + private WPEventDTO _selectedWpEvent; + private GameDTO _selectedGame; + private ObservableCollection _players; + private ObservableCollection _playersOptions; + private ObservableCollection _optionalPlayers; private RestService RestService { get; set; } public WordPressViewModel(RestService restService) { this.RestService = restService; - Players = new ObservableCollection(); - PlayersOptions = new ObservableCollection(); - OptionalPlayers = new ObservableCollection(); + Players = new ObservableCollection(); + PlayersOptions = new ObservableCollection(); + OptionalPlayers = new ObservableCollection(); } #region Auto Property @@ -49,9 +49,9 @@ namespace LaDOSE.DesktopApp.ViewModels get { return SelectedWpEvent != null && SelectedGame != null && Players?.Count() > 0; } } - public List Events { get; set; } + public List Events { get; set; } - public WPEvent SelectedWpEvent + public WPEventDTO SelectedWpEvent { get => _selectedWpEvent; set @@ -62,7 +62,7 @@ namespace LaDOSE.DesktopApp.ViewModels } } - public Game SelectedGame + public GameDTO SelectedGame { get => _selectedGame; set @@ -82,7 +82,7 @@ namespace LaDOSE.DesktopApp.ViewModels } } - public ObservableCollection Players + public ObservableCollection Players { get => _players; set @@ -92,7 +92,7 @@ namespace LaDOSE.DesktopApp.ViewModels } } - public ObservableCollection PlayersOptions + public ObservableCollection PlayersOptions { get => _playersOptions; set @@ -102,7 +102,7 @@ namespace LaDOSE.DesktopApp.ViewModels } } - public ObservableCollection OptionalPlayers + public ObservableCollection OptionalPlayers { get => _optionalPlayers; set @@ -112,8 +112,8 @@ namespace LaDOSE.DesktopApp.ViewModels } } - public ObservableCollection GamesFound { get; set; } - public List Games { get; set; } + public ObservableCollection GamesFound { get; set; } + public List Games { get; set; } #endregion @@ -136,7 +136,7 @@ namespace LaDOSE.DesktopApp.ViewModels public void Generate() { - List test = new List(); + List test = new List(); test = OptionalPlayers.ToList(); var messageBoxText = this.RestService.CreateChallonge2(SelectedGame.Id, SelectedWpEvent.Id, test); @@ -163,7 +163,7 @@ namespace LaDOSE.DesktopApp.ViewModels #endregion - private void ParseGame(WPEvent selectedWpEvent) + private void ParseGame(WPEventDTO selectedWpEvent) { var reservation = SelectedWpEvent.WpBookings.FirstOrDefault(); var games = WpEventDeserialize.Parse(reservation.Meta); @@ -210,7 +210,7 @@ namespace LaDOSE.DesktopApp.ViewModels { Application.Current.Dispatcher.Invoke(() => System.Windows.Input.Mouse.OverrideCursor = Cursors.Wait); - GamesFound = new ObservableCollection(); + GamesFound = new ObservableCollection(); this.Games = this.RestService.GetGames(); this.Events = this.RestService.GetEvents(); @@ -219,15 +219,15 @@ namespace LaDOSE.DesktopApp.ViewModels System.Windows.Input.Mouse.OverrideCursor = null); } - public List FindUser(int wpEventId, Game game,bool optional = false) + public List FindUser(int wpEventId, GameDTO game,bool optional = false) { string[] selectedGameWpId; selectedGameWpId = !optional ? game.WordPressTag.Split(';') : game.WordPressTagOs.Split(';'); var currentWpEvent = this.Events.Where(e => e.Id == wpEventId).ToList(); - List bookings = currentWpEvent.SelectMany(e => e.WpBookings).ToList(); - List users = new List(); + List bookings = currentWpEvent.SelectMany(e => e.WpBookings).ToList(); + List users = new List(); foreach (var booking in bookings) { var reservations = WpEventDeserialize.Parse(booking.Meta); diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml index 8a3dbba..2e3615d 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml @@ -46,7 +46,7 @@ + x:Name="BookingList" IsTextSearchEnabled="True" TextSearch.TextPath="WpUserDto.Name"> diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/IBaseServiceDTO.cs b/LaDOSE.Src/LaDOSE.Service/Interface/IBaseServiceDTO.cs new file mode 100644 index 0000000..face1d1 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.Service/Interface/IBaseServiceDTO.cs @@ -0,0 +1,5 @@ +using System.Collections.Generic; + +namespace LaDOSE.Business.Interface +{ +} \ No newline at end of file