Exemple #1
0
        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 Login(object sender, EventArgs e)
        {
            var email = txtEmail.Text;

            if (string.IsNullOrWhiteSpace(email))
            {
                await DisplayAlert("Error", "The email address field is required.", "Ok");

                return;
            }

            txtEmail.IsEnabled   = false;
            btnLogin.IsVisible   = false;
            prgLoading.IsVisible = true;

            try
            {
                var response = await _authClient.Login(email);

                var tokenClient = new TokenClient();
                tokenClient.SetAuth(email, response.Token, response.ExpiresAt);

                // send to home page
                Navigation.InsertPageBefore(new RootPage(), this);
                await Navigation.PopAsync();
            }
            catch (ApiException)
            {
                txtEmail.IsEnabled   = true;
                btnLogin.IsVisible   = true;
                prgLoading.IsVisible = false;

                ToastService.DisplayError("Sorry, you cannot access this app at this time.");
            }
        }
Exemple #3
0
        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 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;
            }
        }
Exemple #5
0
        protected async void OpenScanner(object sender, EventArgs e)
        {
            var scanner = DependencyService.Get <IQrScanService>();
            var result  = await scanner.ScanAsync();

            if (string.IsNullOrWhiteSpace(result))
            {
                ToastService.DisplayInfo("Scan unsuccessful.");
                return;
            }

            // verify it is an object id
            if (!ObjectId.TryParse(result, out _))
            {
                ToastService.DisplayError("Invalid scan result. Try again!");
                return;
            }

            var popup = new AttendanceRegistration(result);
            await Navigation.ShowPopupAsync(popup);
        }
Exemple #6
0
        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.");
            }
        }