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

76 lines
1.9 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using Caliburn.Micro;
using LaDOSE.DesktopApp.Services;
using LaDOSE.DTO;
namespace LaDOSE.DesktopApp.ViewModels
{
public class GameViewModel : Screen
{
2019-03-09 14:03:25 +01:00
public override string DisplayName => "Games";
2019-03-12 22:23:38 +01:00
private GameDTO _currentGame;
private List<GameDTO> _games;
private RestService RestService { get; set; }
public GameViewModel(RestService restService)
{
this.RestService = restService;
2019-03-12 22:23:38 +01:00
this.Games=new List<GameDTO>();
2019-03-12 21:41:30 +01:00
}
protected override void OnInitialize()
{
LoadGames();
base.OnInitialize();
}
public void LoadGames()
{
2019-03-09 14:03:25 +01:00
this.Games.Clear();
this.Games = this.RestService.GetGames();
NotifyOfPropertyChange("Games");
}
2019-03-12 22:23:38 +01:00
public List<GameDTO> Games
2019-03-09 14:03:25 +01:00
{
get => _games;
set
{
_games = value;
NotifyOfPropertyChange(()=>this.Games);
}
}
2019-03-12 22:23:38 +01:00
public GameDTO CurrentGame
2019-03-09 14:03:25 +01:00
{
get => _currentGame;
set
{
_currentGame = value;
NotifyOfPropertyChange(()=>CurrentGame);
2019-03-14 01:31:56 +01:00
NotifyOfPropertyChange(() => CanDeleteGame);
2019-03-09 14:03:25 +01:00
}
}
public void Update()
{
this.RestService.UpdateGame(this.CurrentGame);
this.Games = RestService.GetGames();
}
public void AddGame()
{
2019-03-12 22:23:38 +01:00
var item = new GameDTO();
2019-03-14 01:31:56 +01:00
this.RestService.UpdateGame(item);
LoadGames();
2019-03-09 14:03:25 +01:00
}
2019-03-14 01:31:56 +01:00
public void DeleteGame()
{
this.RestService.DeleteGame(this.CurrentGame.Id);
LoadGames();
}
public bool CanDeleteGame => CurrentGame != null;
}
}