コード例 #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 Add(Topic topic, string category, string deck, Card card)
 => Handle(() =>
 {
     using (var client = new FlashcardsHttpClient())
     {
         return(client.Post(RestUrl(topic, category, deck), card));
     }
 });
コード例 #3
0
 public bool Add(Topic topic, Category category)
 => Handle(() =>
 {
     using (var client = new FlashcardsHttpClient())
     {
         return(client.Post(RestUrl(topic), category));
     }
 });
コード例 #4
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);
                }
            }
        }