private void BtnCategoriesDelete_Click(object sender, EventArgs e)
 {
     if (lbCategories.SelectedItem != null)
     {
         if (FlashcardsMessageBox.YesNo("Are you sure to delete category with all decks and cards?"))
         {
             _categoriesService.Delete(_topic, ((Category)lbCategories.SelectedItem).Id);
             RefreshCategories();
         }
     }
 }
 private void BtnDecksDelete_Click(object sender, EventArgs e)
 {
     if (lbDecks.SelectedItem != null)
     {
         if (FlashcardsMessageBox.YesNo("Are you sure to delete deck with all cards?"))
         {
             var category = (lbCategories.SelectedItem as Category)?.Name;
             _decksService.Delete(_topic, category, ((Deck)lbDecks.SelectedItem).Id);
             RefreshDecks(category);
         }
     }
 }
 private void BtnCardsDelete_Click(object sender, EventArgs e)
 {
     if (lbCards.SelectedItem != null)
     {
         if (FlashcardsMessageBox.YesNo("Are you sure to delete card?"))
         {
             var category = (lbCategories.SelectedItem as Category)?.Name;
             var deck     = (lbDecks.SelectedItem as Deck)?.Name;
             _cardsService.Delete(_topic, category, deck, ((Card)lbCards.SelectedItem).Id);
             RefreshCards(category, deck);
         }
     }
 }
Beispiel #4
0
        protected bool Handle <T>(Func <ApiResponse <T> > action)
        {
            var response = action();

            if (response.IsSuccess)
            {
                return(true);
            }
            else
            {
                FlashcardsMessageBox.Error(response.ErrorMessage);
                return(false);
            }
        }
Beispiel #5
0
 protected T Handle <T>(string url) where T : class, new()
 {
     using (var client = new FlashcardsHttpClient())
     {
         var response = client.Get <T>(url);
         if (response.IsSuccess)
         {
             return(response.Result);
         }
         else
         {
             FlashcardsMessageBox.Error(response.ErrorMessage);
             return(new T());
         }
     }
 }
Beispiel #6
0
        public bool Auth(string email, string password)
        {
            if (email.IsEmpty())
            {
                FlashcardsMessageBox.Error("Email can't be empty.");
                return(false);
            }
            else if (password.IsEmpty())
            {
                FlashcardsMessageBox.Error("Password can't be empty.");
                return(false);
            }

            using (var client = new FlashcardsHttpClient())
            {
                var body         = new { Email = email, Password = password };
                var authResponse = client.Post <JwtToken>(@"/auth", body);
                if (authResponse.IsSuccess)
                {
                    Session.Jwt = authResponse.Result;

                    client.LoadToken();
                    var userResponse = client.Get <User>($@"/users/{email}");
                    if (userResponse.IsSuccess)
                    {
                        Session.User          = userResponse.Result;
                        Session.User.Password = password;
                    }

                    return(true);
                }
                else
                {
                    FlashcardsMessageBox.Error(authResponse.ErrorMessage);
                    return(false);
                }
            }
        }
Beispiel #7
0
        private void ApplySessionState(ApplySessionCardCommand command)
        {
            var apiResult = _sessionsService.ApplySessionCard(_topic, _category, _deck, command);

            if (apiResult.IsSuccess)
            {
                _sessionState = apiResult.Result;
                if (_sessionState.IsFinished)
                {
                    lblProgress.Text = $"{_sessionState.ActualCount} / {_sessionState.TotalCount}";
                    pbProgress.Value = _sessionState.Percentage;
                    FlashcardsMessageBox.Info("The session is finished.");
                    Close();
                }
                else
                {
                    SetControls();
                }
            }
            else
            {
                FlashcardsMessageBox.Error(apiResult.ErrorMessage);
            }
        }