Files
LaDOSE/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/TournamentResultViewModel.cs

112 lines
3.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Caliburn.Micro;
2019-05-30 01:03:42 +02:00
using LaDOSE.DesktopApp.Utils;
using LaDOSE.DTO;
using LaDOSE.REST;
2019-05-27 23:18:27 +02:00
namespace LaDOSE.DesktopApp.ViewModels
{
public class TournamentResultViewModel : Screen
{
public override string DisplayName => "Tournament Result";
private RestService RestService { get; set; }
public TournamentResultViewModel(RestService restService)
{
this.RestService = restService;
_selectedTournaments = new ObservableCollection<TournamentDTO>();
Tournaments = new List<TournamentDTO>();
}
2019-05-30 01:03:42 +02:00
private TournamentsResultDTO _results;
public List<TournamentDTO> Tournaments { get; set; }
public TournamentsResultDTO Results
{
get => _results;
set
{
_results = value;
NotifyOfPropertyChange(() => Results);
}
}
2019-05-30 01:03:42 +02:00
private ObservableCollection<TournamentDTO> _selectedTournaments;
public ObservableCollection<TournamentDTO> SelectedTournaments
{
get { return _selectedTournaments; }
set
{
_selectedTournaments = value;
NotifyOfPropertyChange(() => SelectedTournaments);
}
}
private GameDTO _selectedGame;
2019-05-30 01:03:42 +02:00
public GameDTO SelectedGame
{
get { return _selectedGame; }
set
{
_selectedGame = value;
//TODO: QUICK AND DIRTY
2019-05-30 01:03:42 +02:00
List<ResultDTO> resultForGame = this.Results.Results.Where(e => e.GameId == SelectedGame.Id).ToList();
First = resultForGame.OrderByDescending(e=>e.Point).First().Player;
2019-05-30 01:03:42 +02:00
SelectedGameResult = new ObservableCollection<ResultDTO>(resultForGame);
NotifyOfPropertyChange(() => SelectedGame);
}
}
2019-05-30 01:03:42 +02:00
private ObservableCollection<ResultDTO> _selectedGameResult;
public ObservableCollection<ResultDTO> SelectedGameResult
{
get { return _selectedGameResult; }
set
{
_selectedGameResult = value;
NotifyOfPropertyChange(() => SelectedGameResult);
}
}
private String _first;
public String First
{
get { return _first; }
set
{
_first = value;
NotifyOfPropertyChange(() => First);
}
}
protected override void OnInitialize()
{
LoadTournaments();
base.OnInitialize();
}
public void LoadTournaments()
{
var tournamentDtos = this.RestService.GetTournaments().ToList();
this.Tournaments = tournamentDtos;
NotifyOfPropertyChange("Tournaments");
}
public void Select()
{
var tournamentsIds = SelectedTournaments.Select(e => e.Id).ToList();
var resultsDto = this.RestService.GetResults(tournamentsIds);
this.Results = resultsDto;
}
2019-05-27 23:18:27 +02:00
}
2019-05-27 23:18:27 +02:00
}