コード例 #1
0
ファイル: SessionsService.cs プロジェクト: wmekal/Flashcards
 public ApiResponse <SessionState> ApplySessionCard(Topic topic, string category, string deck, ApplySessionCardCommand command)
 {
     using (var client = new FlashcardsHttpClient())
     {
         var url = $"/topics/{topic}/categories/{category}/decks/{deck}/sessions";
         return(client.Post <SessionState>(url, command));
     }
 }
コード例 #2
0
 public bool Delete(Topic topic, Guid id)
 => Handle(() =>
 {
     using (var client = new FlashcardsHttpClient())
     {
         return(client.Delete(RestUrl(topic, id)));
     }
 });
コード例 #3
0
 public bool Edit(Topic topic, Category category)
 => Handle(() =>
 {
     using (var client = new FlashcardsHttpClient())
     {
         return(client.Put(RestUrl(topic), category));
     }
 });
コード例 #4
0
 public bool Edit(Topic topic, string category, string deck, Card card)
 => Handle(() =>
 {
     using (var client = new FlashcardsHttpClient())
     {
         return(client.Put(RestUrl(topic, category, deck), card));
     }
 });
コード例 #5
0
ファイル: DecksService.cs プロジェクト: wmekal/Flashcards
 public bool Add(Topic topic, string category, Deck deck)
 => Handle(() =>
 {
     using (var client = new FlashcardsHttpClient())
     {
         return(client.Post(RestUrl(topic, category), deck));
     }
 });
コード例 #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);
                }
            }
        }