/// <summary>Initializes a new instance of the <see cref="MainViewModel" /> class.</summary> public MainViewModel() { AddGameProfileCommand = new RelayCommand <GameProfile>(async param => { param = await GameProfilesDataAccess.CreateNewGame(param); GameProfiles.Add(new ListItemMainPage { GameProfile = await GameProfilesDataAccess.GetGameProfileAsync(param.ID) }); }, param => param != null); EditCommand = new RelayCommand <GameProfile>(async param => { await GameProfilesDataAccess.EditGameProfileAsync(param); }, param => param != null); RefreshSaveGame = new RelayCommand <ListItemMainPage>(async param => { var success = await GameProfilesDataAccess.RefreshSaveGameAsync(param.GameProfile.ID); if (success) { param.GameProfile.SaveGame.Challenges.Clear(); } RefreshSaveDone.Invoke(this, new PropertyChangedEventArgs("RefreshSaveDone")); }, param => param != null); DeleteGameProfileCommand = new RelayCommand <ListItemMainPage>(async param => { if (await GameProfilesDataAccess.DeleteGameProfileAsync(param.GameProfile)) { GameProfiles.Remove(param); } }, param => param != null); }
/// <summary>Loads the game profiles from database asynchronous.</summary> /// <returns></returns> internal async Task LoadGameProfilesFromDBAsync() { if (GameProfiles.Count == 0) { var gameProfiles = await GameProfilesDataAccess.GetGameProfilesAsync(); foreach (GameProfile gameProfile in gameProfiles) { GameProfiles.Add(new ListItemMainPage { GameProfile = gameProfile, DeleteCommandGameProfile = DeleteGameProfileCommand }); } } }