private async void Register(object sender, RoutedEventArgs e) { HttpResponseMessage res = null; try { // Build register request progressRing.IsActive = true; // Get negative checkboxes PagesUtilities.GetAllCheckBoxesTags(RegisterNegativeEffectsGrid, out List <int> intList); GlobalContext.RegisterContext.IntNegativePreferences = intList; // Send request with register information res = await HttpManager.Manager.Post(Constants.MakeUrl("register"), GlobalContext.RegisterContext); if (res != null) { // Request succeeded var content = res.GetContent(); switch (res.StatusCode) { // Register succeeded case HttpStatusCode.Created: case HttpStatusCode.OK: Status.Text = "Register Successful!"; PagesUtilities.SleepSeconds(1); Frame.Navigate(typeof(DashboardPage), res); break; // Register failed case HttpStatusCode.BadRequest: Status.Text = "Register failed!\n" + content["message"]; break; default: Status.Text = "Error!\n" + content["message"]; break; } } else { Status.Text = "Register failed!\nPost operation failed"; } } catch (Exception exc) { AppDebug.Exception(exc, "Register"); } finally { progressRing.IsActive = false; } }
private async void PostLogin(object sender, RoutedEventArgs e) { AppDebug.Line("PostLogin"); HttpResponseMessage res = null; progressRing.IsActive = true; try { // Create login request var req = new LoginRequest(Username.Text, Password.Password); res = await Task.Run(async() => await HttpManager.Manager.Post(Constants.MakeUrl("login"), req)); if (res != null) { // Request succeeded var content = res.GetContent(); switch (res.StatusCode) { // Login successfull case HttpStatusCode.OK: AppDebug.Line("Login success!"); PagesUtilities.SleepSeconds(1); progressRing.IsActive = false; Frame.Navigate(typeof(DashboardPage), res); break; // Login failed case HttpStatusCode.BadRequest: Status.Text = "Login failed!\n" + content["message"]; break; default: Status.Text = "Error!\n" + content["message"]; break; } } else { Status.Text = "Login failed!\nPost operation failed"; } } catch (Exception exc) { Status.Text = "Exception during login"; AppDebug.Exception(exc, "PostLogin"); } finally { progressRing.IsActive = false; } }