Add AutoMapper

This commit is contained in:
2019-03-12 22:23:38 +01:00
parent 3b16c5feaf
commit 30f64257e7
16 changed files with 137 additions and 59 deletions

View File

@@ -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<WPEvent> GetEvents()
public List<WPEventDTO> GetEvents()
{
var restRequest = new RestRequest("/api/wordpress/WPEvent", Method.GET);
var restResponse = Client.Get<List<WPEvent>>(restRequest);
var restResponse = Client.Get<List<WPEventDTO>>(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<WPUser> optionalPlayers)
public string CreateChallonge2(int gameId, int eventId, List<WPUserDTO> optionalPlayers)
{
var restResponse = Post<List<WPUser>,string>($"/api/wordpress/CreateChallonge/{gameId}/{eventId}",optionalPlayers);
var restResponse = Post<List<WPUserDTO>,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<WPUser> GetUsers(int wpEventId, int gameId)
public List<WPUserDTO> GetUsers(int wpEventId, int gameId)
{
var restRequest = new RestRequest($"/api/Wordpress/GetUsers/{wpEventId}/{gameId}", Method.GET);
var restResponse = Client.Get<List<WPUser>>(restRequest);
var restResponse = Client.Get<List<WPUserDTO>>(restRequest);
return restResponse.Data;
}
public List<WPUser> GetUsersOptions(int wpEventId, int gameId)
public List<WPUserDTO> GetUsersOptions(int wpEventId, int gameId)
{
var restRequest = new RestRequest($"/api/Wordpress/GetUsersOptions/{wpEventId}/{gameId}", Method.GET);
var restResponse = Client.Get<List<WPUser>>(restRequest);
var restResponse = Client.Get<List<WPUserDTO>>(restRequest);
return restResponse.Data;
}
@@ -140,14 +142,14 @@ namespace LaDOSE.DesktopApp.Services
#endregion
#region Games
public List<Game> GetGames()
public List<GameDTO> GetGames()
{
var restRequest = new RestRequest("/api/Game", Method.GET);
var restResponse = Client.Get<List<Game>>(restRequest);
var restResponse = Client.Get<List<GameDTO>>(restRequest);
return restResponse.Data;
}
public Game UpdateGame(Game eventUpdate)
public GameDTO UpdateGame(GameDTO eventUpdate)
{
return Post("Api/Game", eventUpdate);
}

View File

@@ -9,13 +9,13 @@ namespace LaDOSE.DesktopApp.ViewModels
{
public override string DisplayName => "Games";
private Game _currentGame;
private List<Game> _games;
private GameDTO _currentGame;
private List<GameDTO> _games;
private RestService RestService { get; set; }
public GameViewModel(RestService restService)
{
this.RestService = restService;
this.Games=new List<Game>();
this.Games=new List<GameDTO>();
}
@@ -32,7 +32,7 @@ namespace LaDOSE.DesktopApp.ViewModels
NotifyOfPropertyChange("Games");
}
public List<Game> Games
public List<GameDTO> 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;
}

View File

@@ -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<WPUser> _players;
private ObservableCollection<WPUser> _playersOptions;
private ObservableCollection<WPUser> _optionalPlayers;
private WPEventDTO _selectedWpEvent;
private GameDTO _selectedGame;
private ObservableCollection<WPUserDTO> _players;
private ObservableCollection<WPUserDTO> _playersOptions;
private ObservableCollection<WPUserDTO> _optionalPlayers;
private RestService RestService { get; set; }
public WordPressViewModel(RestService restService)
{
this.RestService = restService;
Players = new ObservableCollection<WPUser>();
PlayersOptions = new ObservableCollection<WPUser>();
OptionalPlayers = new ObservableCollection<WPUser>();
Players = new ObservableCollection<WPUserDTO>();
PlayersOptions = new ObservableCollection<WPUserDTO>();
OptionalPlayers = new ObservableCollection<WPUserDTO>();
}
#region Auto Property
@@ -49,9 +49,9 @@ namespace LaDOSE.DesktopApp.ViewModels
get { return SelectedWpEvent != null && SelectedGame != null && Players?.Count() > 0; }
}
public List<WPEvent> Events { get; set; }
public List<WPEventDTO> 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<WPUser> Players
public ObservableCollection<WPUserDTO> Players
{
get => _players;
set
@@ -92,7 +92,7 @@ namespace LaDOSE.DesktopApp.ViewModels
}
}
public ObservableCollection<WPUser> PlayersOptions
public ObservableCollection<WPUserDTO> PlayersOptions
{
get => _playersOptions;
set
@@ -102,7 +102,7 @@ namespace LaDOSE.DesktopApp.ViewModels
}
}
public ObservableCollection<WPUser> OptionalPlayers
public ObservableCollection<WPUserDTO> OptionalPlayers
{
get => _optionalPlayers;
set
@@ -112,8 +112,8 @@ namespace LaDOSE.DesktopApp.ViewModels
}
}
public ObservableCollection<Game> GamesFound { get; set; }
public List<Game> Games { get; set; }
public ObservableCollection<GameDTO> GamesFound { get; set; }
public List<GameDTO> Games { get; set; }
#endregion
@@ -136,7 +136,7 @@ namespace LaDOSE.DesktopApp.ViewModels
public void Generate()
{
List<WPUser> test = new List<WPUser>();
List<WPUserDTO> test = new List<WPUserDTO>();
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<Game>();
GamesFound = new ObservableCollection<GameDTO>();
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<WPUser> FindUser(int wpEventId, Game game,bool optional = false)
public List<WPUserDTO> 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<WPBooking> bookings = currentWpEvent.SelectMany(e => e.WpBookings).ToList();
List<WPUser> users = new List<WPUser>();
List<WPBookingDTO> bookings = currentWpEvent.SelectMany(e => e.WpBookings).ToList();
List<WPUserDTO> users = new List<WPUserDTO>();
foreach (var booking in bookings)
{
var reservations = WpEventDeserialize.Parse(booking.Meta);

View File

@@ -46,7 +46,7 @@
<ColumnDefinition Width="2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<ListView Grid.Column="0" ItemsSource="{Binding ElementName=EventsList,Path=SelectedItem.WpBookings}"
x:Name="BookingList" IsTextSearchEnabled="True" TextSearch.TextPath="WpUser.Name">
x:Name="BookingList" IsTextSearchEnabled="True" TextSearch.TextPath="WpUserDto.Name">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">