protected async void DeleteRecord(object sender, EventArgs e) { var shouldDelete = await DisplayAlert("Confirm Delete", "Are you sure you want to permanently delete this newcomer?", "Yes", "No"); if (shouldDelete) { if (((SwipeItemView)sender).BindingContext is NewcomerViewModel newcomer) { await _newcomerClient.DeleteNewcomer(newcomer.Id); // refresh view collectionDateEntries.ItemsSource = _dateRecords.Where(x => x.Id != newcomer.Id); // notify user ToastService.DisplaySuccess("Entry successfully removed."); } else { ToastService.DisplayError("An error occurred when deleting the entry."); } } else { ToastService.DisplayInfo("Operation cancelled."); } }
protected async void UpdateRecord(object sender, EventArgs e) { var vm = BindingContext as NewcomerViewModel; var newcomer = _mapper.Map <NewcomerUpdateBindingModel>(vm); // validate inputs var validationResult = await _newcomerValidator.ValidateAsync(newcomer); if (!validationResult.IsValid) { var errors = validationResult.Errors .Aggregate(string.Empty, (x, y) => x + " - " + y.ErrorMessage + Environment.NewLine); var result = await DisplayAlert("Warning", $"There were some issues with the entry: {Environment.NewLine}{Environment.NewLine}{errors} {Environment.NewLine}Do you want to proceed?", "Yes", "No"); if (!result) { return; } } // mutate controls btnUpdate.IsVisible = false; prgSaving.IsVisible = true; try { newcomer.BirthDay = $"{cmbMonths.SelectedItem} {cmbDays.SelectedItem}"; var response = await _newcomerClient.Update(vm.Id, newcomer); // alert the user ToastService.DisplaySuccess("Newcomer successfully updated."); // set the display values SetNewcomerDisplayValues(response); } catch (ApiException ex) { await DisplayAlert("Error", ex.Content, "Okay"); } catch (HttpRequestException) { await DisplayAlert("Error", "An error occurred.", "Okay"); } // mutate controls btnUpdate.IsVisible = true; prgSaving.IsVisible = false; await scrollView.ScrollToAsync(0, 0, true); HideEditControls(); }
protected async void Record(object sender, EventArgs e) { var newcomer = BindingContext as NewcomerBindingModel; // validate inputs var validationResult = await _newcomerValidator.ValidateAsync(newcomer); if (!validationResult.IsValid) { var errors = validationResult.Errors .Aggregate(string.Empty, (x, y) => x + " - " + y.ErrorMessage + Environment.NewLine); var result = await DisplayAlert("Warning", $"There were some issues with the entry: {Environment.NewLine}{Environment.NewLine}{errors} {Environment.NewLine}Do you want to proceed?", "Yes", "No"); if (!result) { return; } } // disable the button btnSave.IsVisible = false; prgSaving.IsVisible = true; try { newcomer.BirthDay = $"{cmbMonths.SelectedItem} {cmbDays.SelectedItem}"; await _newcomerClient.Register(newcomer); // alert the user ToastService.DisplaySuccess("Newcomer successfully recorded."); // set the controls await ResetControlsAsync(); } catch (ApiException ex) { ToastService.DisplayError(ex.Content); } catch (HttpRequestException) { ToastService.DisplayError("An error occurred."); } finally { // enable buttons prgSaving.IsVisible = false; btnSave.IsVisible = true; } }
protected async void UpdateAttendee(object sender, EventArgs e) { var vm = BindingContext as AttendeeViewModel; var attendee = _mapper.Map <AttendeeUpdateBindingModel>(vm); // validate inputs var validationResult = await _attendanceValidator.ValidateAsync(attendee); if (!validationResult.IsValid) { var errors = validationResult.Errors .Aggregate(string.Empty, (x, y) => x + " - " + y.ErrorMessage + Environment.NewLine); var result = await DisplayAlert("Warning", $"There were some issues with the entry: {Environment.NewLine}{Environment.NewLine}{errors} {Environment.NewLine}Do you want to proceed?", "Yes", "No"); if (!result) { return; } } btnUpdate.IsVisible = false; prgSaving.IsVisible = true; try { var response = await _attendanceClient.Update(vm.Id, attendee); // alert the user ToastService.DisplaySuccess("Attendee details updated successfully."); // set the display values SetAttendeeDisplayValue(response); } catch (ApiException ex) { await DisplayAlert("Error", ex.Content, "Okay"); } catch (HttpRequestException) { await DisplayAlert("Error", "An error occurred.", "Okay"); } btnUpdate.IsVisible = true; prgSaving.IsVisible = false; await scrollView.ScrollToAsync(0, 0, true); HideEditControls(); }
protected async void RegisterAttendance(object sender, EventArgs e) { stkButtons.IsVisible = false; prgSubmit.IsVisible = true; try { var attendee = new AttendeeV2BindingModel { SeatAssigned = txtSeatNumber.Text, SeatType = cmbSeatType.SelectedItem.ToString(), PersonId = _personId }; await _attendanceClient.Register(attendee); // alert the user ToastService.DisplaySuccess("Attendee successfully registered."); Dismiss(null); } catch (ApiException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.DisplayError(error?.Message); } catch (ApiException ex) when(ex.StatusCode == HttpStatusCode.Conflict) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.DisplayError(error?.Message); Dismiss(null); } catch (ApiException ex) { ToastService.DisplayError(ex.Content ?? "An error occured."); } catch (HttpRequestException) { ToastService.DisplayError("An error occurred."); } finally { prgSubmit.IsVisible = false; stkButtons.IsVisible = true; } }
protected async void GenerateDateReport(object sender, EventArgs e) { var email = await DisplayPromptAsync("Report", "What email address should the report be sent to?", "Send", "Cancel", "e.g [email protected] (optional)", keyboard : Keyboard.Email); if (email == null) { ToastService.DisplayInfo("Operation cancelled."); return; } if (((SwipeItemView)sender).BindingContext is DateSummaryViewModel summary) { await _attendanceClient.SendAttendanceReport(summary.Date, email); ToastService.DisplaySuccess("Report successfully generated and sent."); } else { ToastService.DisplayError("An error occurred when sending the report."); } }