101 lines
2.5 KiB
C#
101 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using LaDOSE.DesktopApp.Avalonia.Utils;
|
|
using LaDOSE.DesktopApp.Avalonia.ViewModels;
|
|
using LaDOSE.DTO;
|
|
using LaDOSE.REST;
|
|
using ReactiveUI;
|
|
using Splat;
|
|
|
|
namespace LaDOSE.DesktopApp.Avalonia.ViewModels
|
|
{
|
|
public class GamesViewModel : BaseViewModel
|
|
{
|
|
|
|
public string DisplayName => "Games";
|
|
|
|
private GameDTO _currentGame;
|
|
private List<GameDTO> _games;
|
|
private List<GameDTO> _Searchgames;
|
|
private RestService RestService { get; set; }
|
|
public GamesViewModel(IScreen screen): base(screen,"Games")
|
|
{
|
|
this.RestService = Locator.Current.GetService<RestService>();
|
|
this.Games=new List<GameDTO>();
|
|
OnInitialize();
|
|
}
|
|
|
|
|
|
void OnInitialize()
|
|
{
|
|
LoadGames();
|
|
this.CurrentGame = Games.First();
|
|
}
|
|
|
|
public void LoadGames()
|
|
{
|
|
var gameDtos = this.RestService.GetGames().OrderBy(e=>e.Order).ToList();
|
|
this.Games = gameDtos;
|
|
RaisePropertyChanged(nameof(this.Games));
|
|
}
|
|
|
|
public List<GameDTO> Games
|
|
{
|
|
get => _games;
|
|
set
|
|
{
|
|
_games = value;
|
|
RaisePropertyChanged(nameof(this.Games));
|
|
}
|
|
}
|
|
|
|
public List<GameDTO> SearchGame
|
|
{
|
|
get => _Searchgames;
|
|
set
|
|
{
|
|
_Searchgames = value;
|
|
RaisePropertyChanged(nameof(this.SearchGame));
|
|
}
|
|
}
|
|
public GameDTO CurrentGame
|
|
{
|
|
get => _currentGame;
|
|
set
|
|
{
|
|
_currentGame = value;
|
|
RaisePropertyChanged(nameof(this.CurrentGame));
|
|
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
this.RestService.UpdateGame(this.CurrentGame);
|
|
LoadGames();
|
|
|
|
}
|
|
public void AddGame()
|
|
{
|
|
var item = new GameDTO();
|
|
this.RestService.UpdateGame(item);
|
|
LoadGames();
|
|
}
|
|
public void DeleteGame()
|
|
{
|
|
|
|
this.RestService.DeleteGame(this.CurrentGame.Id);
|
|
LoadGames();
|
|
}
|
|
|
|
public void GetGame()
|
|
{
|
|
SearchGame = this.RestService.GetSmashGames(this.CurrentGame.LongName);
|
|
}
|
|
public bool CanDeleteGame => CurrentGame != null;
|
|
|
|
|
|
}
|
|
} |