/// <summary>Loads the challenges from database asynchronous.</summary> /// <returns></returns> public async Task LoadChallengesFromDBAsync() { if (AudienceChallenges.Count == 0) { AudienceChallenges.AddRange(await ChallengesDataAccess.GetAudienceChallengesAsync()); } if (CrewChallenges.Count == 0) { CrewChallenges.AddRange(await ChallengesDataAccess.GetCrewChallengesAsync()); } if (MultipleChoiceChallenges.Count == 0) { MultipleChoiceChallenges.AddRange(await ChallengesDataAccess.GetMultipleChoiceChallengesAsync()); } if (MusicChallenges.Count == 0) { MusicChallenges.AddRange(await ChallengesDataAccess.GetMusicChallengesAsync()); } if (QuizChallenges.Count == 0) { QuizChallenges.AddRange(await ChallengesDataAccess.GetQuizChallengesAsync()); } if (ScreenshotChallenges.Count == 0) { ScreenshotChallenges.AddRange(await ChallengesDataAccess.GetScreenshotChallengesAsync()); } if (SilhouetteChallenges.Count == 0) { SilhouetteChallenges.AddRange(await ChallengesDataAccess.GetSilhouetteChallengesAsync()); } if (SologameChallenges.Count == 0) { SologameChallenges.AddRange(await ChallengesDataAccess.GetSologameChallengesAsync()); } await ObjectsViewModel.LoadObjectsFromDBAsync(); foreach (Game game in CreateObjectsViewModel.Games) { Games.Add(game); } foreach (Image image in CreateObjectsViewModel.Images) { Images.Add(image); } foreach (Music music in CreateObjectsViewModel.Music) { Music.Add(music); } foreach (AudienceChallenge challenge in AudienceChallenges) { foreach (Game game in Games) { if (game.ID.Equals(challenge.GameID)) { challenge.Game = game; break; } } } foreach (CrewChallenge challenge in CrewChallenges) { foreach (Game game in Games) { if (game.ID.Equals(challenge.GameID)) { challenge.Game = game; break; } } } foreach (MusicChallenge challenge in MusicChallenges) { foreach (Music music in Music) { if (music.ID.Equals(challenge.SongID)) { challenge.Song = music; break; } } } foreach (ScreenshotChallenge challenge in ScreenshotChallenges) { foreach (Image image in Images) { if (image.ID.Equals(challenge.ImageID)) { challenge.Image = image; break; } } } foreach (SilhouetteChallenge challenge in SilhouetteChallenges) { foreach (Image image in Images) { if (image.ID.Equals(challenge.ImageID)) { challenge.Image = image; break; } } } foreach (SologameChallenge challenge in SologameChallenges) { foreach (Game game in Games) { if (game.ID.Equals(challenge.GameID)) { challenge.Game = game; break; } } } CreateNewObjectPlaceholder(); }
/// <summary>Initializes a new instance of the <see cref="CreateChallengesViewModel"/> class.</summary> public CreateChallengesViewModel() { EditCommand = new RelayCommand <ChallengeBase>(async param => { switch (param.GetDiscriminator()) { case "AudienceChallenge": case "CrewChallenge": case "SologameChallenge": ObjectsViewModel.EditCommand.Execute((param as GameChallenge).Game); break; case "MultipleChoiceChallenge": case "QuizChallenge": await AnswersDataAccess.EditAnswersAsync((param as QuestionChallenge).Answers); break; case "MusicChallenge": ObjectsViewModel.EditCommand.Execute((param as MusicChallenge).Song); break; case "ScreenshotChallenge": case "SilhouetteChallenge": ObjectsViewModel.EditCommand.Execute((param as ImageChallenge).Image); break; } await ChallengesDataAccess.EditChallengeAsync(param); }, param => param != null); DeleteCommand = new RelayCommand <ChallengeBase>(async param => { if (await ChallengesDataAccess.DeleteChallengeAsync(param)) { switch (param.GetDiscriminator()) { case "AudienceChallenge": AudienceChallenges.Remove(param as AudienceChallenge); FilteredAudience.Remove(param as AudienceChallenge); break; case "CrewChallenge": CrewChallenges.Remove(param as CrewChallenge); FilteredCrew.Remove(param as CrewChallenge); break; case "MultipleChoiceChallenge": MultipleChoiceChallenges.Remove(param as MultipleChoiceChallenge); FilteredMulti.Remove(param as MultipleChoiceChallenge); break; case "MusicChallenge": MusicChallenges.Remove(param as MusicChallenge); FilteredMusic.Remove(param as MusicChallenge); break; case "QuizChallenge": QuizChallenges.Remove(param as QuizChallenge); FilteredQuiz.Remove(param as QuizChallenge); break; case "ScreenshotChallenge": ScreenshotChallenges.Remove(param as ScreenshotChallenge); FilteredScreen.Remove(param as ScreenshotChallenge); break; case "SilhouetteChallenge": SilhouetteChallenges.Remove(param as SilhouetteChallenge); FilteredSilhu.Remove(param as SilhouetteChallenge); break; case "SologameChallenge": SologameChallenges.Remove(param as SologameChallenge); FilteredSolo.Remove(param as SologameChallenge); break; } } }, param => param != null); }