From 30ec8ae90ba51567eb70a95b1cd6a7a2a75ac811 Mon Sep 17 00:00:00 2001 From: Darkstack <1835601+darkstack@users.noreply.github.com> Date: Thu, 14 Mar 2019 01:31:56 +0100 Subject: [PATCH] Modification Zarghatt --- .../Controllers/GenericController.cs | 19 ++++++++++- .../Controllers/GenericControllerDTO.cs | 15 +++++++- .../LaDOSE.Api/Controllers/UsersController.cs | 34 +++++++++---------- .../LaDOSE.DesktopApp/Services/RestService.cs | 10 ++++-- .../ViewModels/GameViewModel.cs | 13 +++++-- .../ViewModels/WordPressViewModel.cs | 4 +-- .../LaDOSE.DesktopApp/Views/GameView.xaml | 4 ++- .../Views/WordPressView.xaml | 2 +- .../LaDOSE.Service/Service/BaseService.cs | 2 ++ 9 files changed, 76 insertions(+), 27 deletions(-) diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs index 7a2b7aa..10dc41d 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericController.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using LaDOSE.Business.Interface; using LaDOSE.Entity; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace LaDOSE.Api.Controllers @@ -35,5 +37,20 @@ namespace LaDOSE.Api.Controllers return _service.GetById(id); } + + [HttpGet("{id}/delete")] + public IActionResult Delete(int id) + { + try + { + return _service.Delete((int) id) ? (IActionResult) NoContent() : NotFound(); + } + catch (Exception) + { + return BadRequest(); + } + + + } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs index 747e1a1..cb6d49e 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/GenericControllerDTO.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using LaDOSE.Business.Interface; using Microsoft.AspNetCore.Mvc; @@ -33,5 +34,17 @@ namespace LaDOSE.Api.Controllers return AutoMapper.Mapper.Map(_service.GetById(id)); } + [HttpDelete("{id}")] + public IActionResult Delete(int id) + { + try + { + return _service.Delete((int)id) ? (IActionResult)NoContent() : NotFound(); + } + catch (Exception) + { + return BadRequest(); + } + } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/UsersController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/UsersController.cs index 19c865b..f0efb58 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/UsersController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/UsersController.cs @@ -68,24 +68,24 @@ namespace LaDOSE.Api.Controllers } //[AllowAnonymous] - //[HttpPost("register")] - //public IActionResult Register([FromBody]ApplicationUser userDto) - //{ - // // map dto to entity - + [HttpPost("register")] + public IActionResult Register([FromBody]ApplicationUser userDto) + { + // map dto to entity - // try - // { - // // save - // _userService.Create(userDto, userDto.Password); - // return Ok(); - // } - // catch (Exception ex) - // { - // // return error message if there was an exception - // return BadRequest(new { message = ex.Message }); - // } - //} + + try + { + // save + _userService.Create(userDto, userDto.Password); + return Ok(); + } + catch (Exception ex) + { + // return error message if there was an exception + return BadRequest(new { message = ex.Message }); + } + } } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs index 7597dcf..e1e02dc 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Services/RestService.cs @@ -149,9 +149,15 @@ namespace LaDOSE.DesktopApp.Services return restResponse.Data; } - public GameDTO UpdateGame(GameDTO eventUpdate) + public GameDTO UpdateGame(GameDTO game) { - return Post("Api/Game", eventUpdate); + return Post("Api/Game", game); + } + public bool DeleteGame(int gameId) + { + var restRequest = new RestRequest($"/api/Game/{gameId}", Method.DELETE); + var restResponse = Client.Execute(restRequest); + return restResponse.IsSuccessful; } #endregion diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs index 6ff7298..e2ceb47 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/GameViewModel.cs @@ -49,6 +49,7 @@ namespace LaDOSE.DesktopApp.ViewModels { _currentGame = value; NotifyOfPropertyChange(()=>CurrentGame); + NotifyOfPropertyChange(() => CanDeleteGame); } } @@ -60,8 +61,16 @@ namespace LaDOSE.DesktopApp.ViewModels public void AddGame() { var item = new GameDTO(); - this.Games.Add(item); - this.CurrentGame = item; + this.RestService.UpdateGame(item); + LoadGames(); } + public void DeleteGame() + { + + this.RestService.DeleteGame(this.CurrentGame.Id); + LoadGames(); + } + + public bool CanDeleteGame => CurrentGame != null; } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs index 686b649..ada6330 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs @@ -197,8 +197,8 @@ namespace LaDOSE.DesktopApp.ViewModels var findUser = FindUser(SelectedWpEvent.Id, SelectedGame); var findUser2 = FindUser(SelectedWpEvent.Id, SelectedGame,true); - findUser.ForEach((e) => this.Players.AddUI(e,()=>NotifyOfPropertyChange(() => this.CanGenerate))); - findUser2.ForEach((e) => this.PlayersOptions.AddUI(e,null)); + findUser.OrderBy(e=>e.Name).ToList().ForEach((e) => this.Players.AddUI(e,()=>NotifyOfPropertyChange(() => this.CanGenerate))); + findUser2.OrderBy(e => e.Name).ToList().ForEach((e) => this.PlayersOptions.AddUI(e,null)); } } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/GameView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/GameView.xaml index 535d051..d843241 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/GameView.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/GameView.xaml @@ -42,7 +42,9 @@ - + + + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml index 6d6507d..994fed2 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/WordPressView.xaml @@ -45,7 +45,7 @@ - diff --git a/LaDOSE.Src/LaDOSE.Service/Service/BaseService.cs b/LaDOSE.Src/LaDOSE.Service/Service/BaseService.cs index 7d6a1f4..febe803 100644 --- a/LaDOSE.Src/LaDOSE.Service/Service/BaseService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Service/BaseService.cs @@ -35,6 +35,7 @@ namespace LaDOSE.Business.Service public virtual bool Update(T entity) { var entityEntry = _context.Update(entity); + this._context.SaveChanges(); return _context.Entry(entityEntry).State == EntityState.Unchanged; } @@ -42,6 +43,7 @@ namespace LaDOSE.Business.Service { var find = _context.Find(id); _context.Remove(find); + this._context.SaveChanges(); return _context.Entry(find).State == EntityState.Deleted; }