private void LeaveForm() { switch (_mode) { case Mode.CreateFlashcardAndDeck: NavigationService.NavigateTo("DecksListView"); Messenger.Default.Send <ReloadMessageToDecksList>(new ReloadMessageToDecksList(true)); Messenger.Default.Send <MessageToMenuControl>(new MessageToMenuControl(false, false)); break; default: NavigationService.NavigateTo("ManageDeckView"); Messenger.Default.Send <MessageToMenuControl>(new MessageToMenuControl(false, false)); Messenger.Default.Send <DataMessageToMenageDeck>(new DataMessageToMenageDeck(_deck)); break; } FlashcardsCollection.Clear(); TipsCollection.Clear(); IsRemoveButtonVisible = false; IsPaneVisible = false; }
private async void HandleDataMessage(Deck deckInstance, Flashcard flashcardInstance) { FlashcardsCollection.Clear(); TipsCollection.Clear(); IsDataLoading = false; if (deckInstance != null) { if (flashcardInstance != null) { _mode = Mode.EditFlashcard; Question = flashcardInstance.Question; Answer = flashcardInstance.Answer; IsPublic = deckInstance.IsPublic; IsRemoveButtonVisible = true; HeaderMessage = StringResources.GetString("EditFlashcard"); SubmitFormMessage = StringResources.GetString("Edit");; try { var tips = await _restService.GetTips(deckInstance.ID, flashcardInstance.Id); if (tips != null) { foreach (var tip in tips) { TipsCollection.Add(new TipViewModel(tip.ID, tip.Essence)); } } } catch (Exception ex) { Messenger.Default.Send <MessageToMessageBoxControl>(new MessageToMessageBoxControl(true, false, StringResources.GetString("OperationFailed"))); } _flashcard = flashcardInstance; } else { _mode = Mode.AddNewFlashcardToDeck; Question = ""; Answer = ""; IsRemoveButtonVisible = false; _flashcard = new Flashcard(); HeaderMessage = StringResources.GetString("AddFlashcard"); SubmitFormMessage = StringResources.GetString("AddFlashcard"); TipsCollection = new ObservableCollection <TipViewModel>(); } try { var flashcards = await _restService.GetFlashcards(deckInstance.ID); if (flashcards != null && flashcards.Count > 0) { foreach (var f in flashcards) { FlashcardsCollection.Add(f); } } } catch { FlashcardsCollection = new ObservableCollection <Flashcard>(); } HandleTipsCountChanged(); DeckName = deckInstance.Name; IsPublic = deckInstance.IsPublic; _deck = deckInstance; } else { _mode = Mode.CreateFlashcardAndDeck; Question = ""; Answer = ""; DeckName = ""; IsRemoveButtonVisible = false; _deck = new Deck(); _flashcard = new Flashcard(); HeaderMessage = StringResources.GetString("CreateNewDeck"); SubmitFormMessage = StringResources.GetString("CreateNewDeck"); FlashcardsCollection = new ObservableCollection <Flashcard>(); TipsCollection = new ObservableCollection <TipViewModel>(); HandleTipsCountChanged(); } IsGeneralError = false; IsPaneVisible = false; }