Beispiel #1
0
        private async void HandleConfirmMessage(bool shouldBeRemoved)
        {
            if (shouldBeRemoved)
            {
                if (await CheckInternetConnection())
                {
                    IsDataLoading = true;
                    try
                    {
                        bool success = await _restService.RemoveDeck(_selectedID);

                        if (success)
                        {
                            DecksCollection.Remove(DecksCollection.Where(x => x.ID == _selectedID).First());
                        }
                    }
                    catch { }
                    IsDataLoading = false;
                    if (DecksCollection != null && DecksCollection.Count == 0)
                    {
                        IsNoDecks = true;
                    }
                    BackToDeck();
                }
            }
        }
Beispiel #2
0
 private void HandleDecksTypeMessage(DecksType decksType)
 {
     IsDeckSelected = false;
     IsMyDeck       = false;
     IsNoDecks      = false;
     _decksType     = decksType;
     DecksCollection.Clear();
     SearchMessageVisibility = false;
     InitializeDecksCollection();
     _statisticsService.InitializeFiles();
 }
Beispiel #3
0
 private void HandleReloadMessage(bool reload)
 {
     if (reload)
     {
         IsDeckSelected = false;
         DecksCollection.Clear();
         SearchMessageVisibility = false;
         IsNoDecks = false;
         InitializeDecksCollection();
     }
 }
Beispiel #4
0
        private async void HandleSearchMessage(string searchingContent)
        {
            IsNoDecks      = false;
            IsDeckSelected = false;
            if (await CheckInternetConnection())
            {
                List <Deck> searchList;
                DecksCollection.Clear();
                _favouriteDecks.Clear();

                SearchMessageVisibility = false;
                IsDataLoading           = true;
                try
                {
                    if (_accountService.IsUserLoggedIn())
                    {
                        searchList = await _restService.GetAllDecks(true, false, true, searchingContent);

                        IsUser = true;
                    }
                    else
                    {
                        searchList = await _restService.GetAllDecks(false, false, true, searchingContent);

                        IsUser = false;
                    }
                    if (searchList != null && searchList.Count > 0)
                    {
                        searchList.Sort((x, y) => DateTime.Compare(y.CreationDate, x.CreationDate));
                        searchList.ForEach(x => DecksCollection.Add(x));
                        if (IsUser)
                        {
                            _favouriteDecks = _favouriteService.GetFavouriteDecks();
                            CheckIfDeckIsFavourite();
                        }

                        IsDataLoading = false;
                    }
                }
                catch (Exception ex)
                {
                    Messenger.Default.Send <MessageToMessageBoxControl>(new MessageToMessageBoxControl(true, false, true, false, ex.Message));
                }
                finally
                {
                    IsDataLoading = false;
                    if (DecksCollection != null && DecksCollection.Count == 0)
                    {
                        SearchMessageVisibility = true;
                    }
                }
            }
        }
Beispiel #5
0
        private async void GoToLearning()
        {
            if (await CheckInternetConnection())
            {
                IsDeckSelected = false;
                NavigationService.NavigateTo("LearningView");
                Deck deck = DecksCollection.Where(x => x.ID == _selectedID).FirstOrDefault();
                _selectedID = String.Empty;

                Messenger.Default.Send <DataMessageToExam>(new DataMessageToExam(deck));
                Messenger.Default.Send <MessageToMenuControl>(new MessageToMenuControl(false, false, deck.Name));
            }
        }
Beispiel #6
0
        private async void GoToTest()
        {
            if (await CheckInternetConnection())
            {
                IsDeckSelected = false;
                NavigationService.NavigateTo("ExamView");
                Deck deck = DecksCollection.Where(x => x.ID == _selectedID).FirstOrDefault();
                _selectedID = String.Empty;
                Messenger.Default.Send <DataMessageToExam>(new DataMessageToExam(deck));
                Messenger.Default.Send <MessageToMenuControl>(new MessageToMenuControl(false, false, deck.Name));

                _statisticsService.IncrementTestsCountAnswers();
                _statisticsService.IncrementCountOfDecks(deck);
            }
        }
Beispiel #7
0
 private void CheckIfDeckIsFavourite()
 {
     if (_favouriteDecks != null)
     {
         foreach (Deck deck in _favouriteDecks)
         {
             Deck favouriteDeck = DecksCollection.Where(x => x.ID == deck.ID).FirstOrDefault();
             if (favouriteDeck != null)
             {
                 favouriteDeck.ViewModel.IsFavourite             = true;
                 favouriteDeck.ViewModel.AddToFavouriteDecksDate = deck.ViewModel.AddToFavouriteDecksDate;
             }
         }
     }
 }
Beispiel #8
0
        private void RemoveFromFavourite(string id)
        {
            if (IsUser)
            {
                Deck deck = DecksCollection.Where(x => x.ID == id).FirstOrDefault();
                if (deck.ViewModel == null)
                {
                    deck.ViewModel = new DeckViewModel();
                }

                deck.ViewModel.IsFavourite             = false;
                deck.ViewModel.AddToFavouriteDecksDate = default(DateTime);

                if (_favouriteDecks != null)
                {
                    Deck deckToRemove = _favouriteDecks.Where(x => x.ID == id).FirstOrDefault();
                    _favouriteDecks.Remove(deckToRemove);
                    _favouriteService.SaveFavouriteDecks(_favouriteDecks);
                }
            }
        }
Beispiel #9
0
        private async void TapTile(string id)
        {
            Messenger.Default.Send <MessageToMessageBoxControl>(new MessageToMessageBoxControl(false));
            if (await CheckInternetConnection())
            {
                _selectedID    = id;
                IsDeckSelected = true;
                IsMyDeck       = false;

                string name = DecksCollection.Where(x => x.ID == _selectedID).FirstOrDefault().Name;
                Messenger.Default.Send <MessageToMenuControl>(new MessageToMenuControl(false, false, name));

                if (_decksType == DecksType.MyDecks)
                {
                    IsMyDeck = true;
                }
                else
                {
                    try
                    {
                        Deck deck = await _restService.GetDeckById(_selectedID);

                        if (deck != null)
                        {
                            if (_accountService.IsUserLoggedIn())
                            {
                                if (_accountService.GetUserEmail() == deck.CreatorEmail)
                                {
                                    IsMyDeck = true;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Messenger.Default.Send <MessageToMessageBoxControl>(new MessageToMessageBoxControl(true, false, true, false, ex.Message));
                    }
                }
            }
        }
Beispiel #10
0
        private void AddToFavourite(string id)
        {
            if (IsUser)
            {
                Deck deck = DecksCollection.Where(x => x.ID == id).FirstOrDefault();
                if (deck.ViewModel == null)
                {
                    deck.ViewModel = new DeckViewModel();
                }

                deck.ViewModel.IsFavourite             = true;
                deck.ViewModel.AddToFavouriteDecksDate = DateTime.Now;

                if (_favouriteDecks == null)
                {
                    _favouriteDecks = new List <Deck>();
                }

                _favouriteDecks.Add(deck);
                _favouriteService.SaveFavouriteDecks(_favouriteDecks);
            }
        }
Beispiel #11
0
        private async void InitializeDecksCollection()
        {
            if (await CheckInternetConnection() && _accountService.IsUserLoggedIn())
            {
                IsUser = true;

                _favouriteDecks.Clear();
                _favouriteDecks = _favouriteService.GetFavouriteDecks();
                List <Deck> _deckLists = new List <Deck>();
                IsDataLoading = true;
                try
                {
                    if (_decksType == DecksType.PublicDecks)
                    {
                        Messenger.Default.Send <MessageToMenuControl>(new MessageToMenuControl(true, false));
                        _deckLists = await _restService.GetDecks();
                    }
                    else if (_decksType == DecksType.Favourite)
                    {
                        _deckLists = await _restService.GetDecks();

                        List <Deck> _deckList2 = await _restService.GetUserDecks();

                        if (_deckList2 != null)
                        {
                            _deckLists = _deckLists.Union(_deckList2).ToList();
                        }

                        if (_deckLists != null && _favouriteDecks != null)
                        {
                            _favouriteDecks.Sort((x, y) => DateTime.Compare(y.ViewModel.AddToFavouriteDecksDate, x.ViewModel.AddToFavouriteDecksDate));
                            foreach (Deck deck in _favouriteDecks)
                            {
                                Deck favouriteDeck = _deckLists.Where(x => x.ID == deck.ID).FirstOrDefault();
                                if (favouriteDeck != null)
                                {
                                    favouriteDeck.ViewModel.IsFavourite             = true;
                                    favouriteDeck.ViewModel.AddToFavouriteDecksDate = deck.ViewModel.AddToFavouriteDecksDate;
                                    DecksCollection.Add(favouriteDeck);
                                }
                            }
                        }
                    }
                    else
                    {
                        Messenger.Default.Send <MessageToMenuControl>(new MessageToMenuControl(false, false));
                        _deckLists = await _restService.GetUserDecks();
                    }

                    if (_deckLists != null && _decksType != DecksType.Favourite)
                    {
                        _deckLists.Sort((x, y) => string.Compare(x.Name, y.Name));
                        _deckLists.ForEach(x => DecksCollection.Add(x));
                        CheckIfDeckIsFavourite();
                    }
                }
                catch (Exception ex)
                {
                    Messenger.Default.Send <MessageToMessageBoxControl>(new MessageToMessageBoxControl(true, false, true, false, ex.Message));
                }
                finally
                {
                    if (DecksCollection != null && DecksCollection.Count == 0)
                    {
                        IsNoDecks = true;
                    }

                    IsDataLoading = false;
                }
            }
        }