protected bool Handle <T>(Func <ApiResponse <T> > action) { var response = action(); if (response.IsSuccess) { return(true); } else { FlashcardsMessageBox.Error(response.ErrorMessage); return(false); } }
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()); } } }
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); } } }
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); } }