public Login() { InitializeComponent(); DataContext = this; loginAPIHelper = new LoginAPIHelper(); LoginCommand = new RelayCommand(async delegate { await Task.Run(() => DoLogin()); }, CLogin); }
private async Task DoLogin() { List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("UserName", UserName), new KeyValuePair <string, string>("Password", Password) }; if (FieldValidation.ValidateFields(values)) { CanLogin = false; try { LoginAPIHelper loginAPIHelper = new LoginAPIHelper(); var result = await loginAPIHelper.Authenticate(UserName, Password).ConfigureAwait(false); if (result.GetType() == typeof(LoginErrorResponse)) { LoginErrorResponse response = result as LoginErrorResponse; MessageBox.Show(response.Error_Description, response.Error, MessageBoxButton.OK, MessageBoxImage.Error); } else if (result.GetType() == typeof(AuthenticatedUser)) { AuthenticatedUser authenticatedUser = result as AuthenticatedUser; LoggedInUser loggedInUser = await loginAPIHelper.GetLoggedInUser(authenticatedUser.Access_Token).ConfigureAwait(false); loggedInUser.Token = authenticatedUser.Access_Token; Application.Current.Properties["LoggedInUser"] = loggedInUser; Application.Current.Dispatcher.Invoke((Action) delegate { ProjectSelection projectSelection = new ProjectSelection(); projectSelection.Show(); this.Close(); }); } else { MessageBox.Show("OOPS! Unexpected error occured", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } CanLogin = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); CanLogin = true; } } }
public static LoginResponse SignIn(LoginRequest userInfo) { var LoginInfo = LoginAPIHelper.Post <LoginResponse>("", userInfo); return(LoginInfo); }