Beispiel #1
0
        private async void InitializeFlashcardsCollection()
        {
            if (await CheckInternetConnection())
            {
                FlashcardsCollection.Clear();
                List <Flashcard> _flashcardLists = new List <Flashcard>();
                IsDataLoading = true;

                try
                {
                    _flashcardLists = await _restService.GetFlashcards(_deckInstance.ID);

                    if (_flashcardLists != null)
                    {
                        _flashcardLists.ForEach(x => FlashcardsCollection.Add(x));
                    }
                }
                catch (Exception ex)
                {
                    Messenger.Default.Send <MessageToMessageBoxControl>(new MessageToMessageBoxControl(true, false, StringResources.GetString("OperationFailed")));
                }
                finally
                {
                    IsDataLoading = 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;
        }