예제 #1
0
        private async Task UpdateUserAsync(Client user)
        {
            EditUserViewModel vm = new EditUserViewModel
            {
                Email       = user.Email,
                District    = user.District,
                StreetName  = user.StreetName,
                Province    = user.Province,
                HouseNumber = user.HouseNumber
            };

            string content = JsonConvert.SerializeObject(vm);

            apiRequestHelper.SetTokenHeader();
            string response = await apiRequestHelper.PutRequest(Constants.editClientUrl + "/" + user.Email, content);

            if (response != null)
            {
                DisplayAlert("Update message", "User updated successfully", "Okay");
                Navigation.PushAsync(new UserDetailPage());
            }
            else
            {
                DisplayAlert("Error", "Sorry, something went wrong. Please try again later.", "Okay");
            }
        }
        // Update the status of an appointment.
        private async Task UpdateAppointmentStatusAsync(Appointment appointment, bool accepted)
        {
            // Ask for a confirmation when the user wants to cancel the appointment.
            if (!accepted)
            {
                bool answer = await DisplayAlert("Warning", "Are you sure you want to cancel the appointment?", "yes", "no");

                if (!answer)
                {
                    return;
                }
            }

            // Create a model that will be sent to update through the API
            int statusId = accepted ? 2 : 3;
            AppointmentViewModel viewModel = new AppointmentViewModel
            {
                Id             = appointment.Id,
                Time           = appointment.Time,
                StatusId       = statusId,
                BenchId        = appointment.Bench.Id,
                ClientId       = appointment.Client.Id,
                HealthworkerId = appointment.Healthworker.Id,
            };

            // Do a PUT request.
            string content = JsonConvert.SerializeObject(viewModel);

            // Send token with Http request
            apiRequestHelper.SetTokenHeader();
            string response = await apiRequestHelper.PutRequest(Constants.appointmentsUrl + "/" + appointment.Id, content);

            if (response != null)
            {
                // Display a succesfull alert.
                String alertTitle   = accepted ? "Appointment accepted" : "Appointment canceled";
                String alertMessage = accepted ? "The appointment has been accepted." : "The appointment has been canceled.";
                DisplayAlert(alertTitle, alertMessage, "Okay");
                FetchAppointment();
            }
            else
            {
                // Display an error.
                DisplayAlert("Error", "Sorry, something went wrong. Please try again later.", "Okay");
            }
        }
예제 #3
0
        // Do a PUT request to update the clients healthworker
        private async Task choose_healthworker(object sender, EventArgs e)
        {
            AddHealthworkerToUserViewModel addHealthworkerModel = new AddHealthworkerToUserViewModel {
                HealthWorker_Id = healthworkers[currentHealthworker].Id
            };

            // Do a PUT request.
            string content  = JsonConvert.SerializeObject(addHealthworkerModel);
            string response = await apiRequestHelper.PutRequest(Constants.addHealthworkerToClientUrl + "/" + App.Current.Properties["email"], content);

            if (response != null)
            {
                DisplayAlert("Succesfull", healthworkers[currentHealthworker].Firstname + " is your new healthworker.", "Okay");
                App.Current.Properties["healthworker_id"] = healthworkers[currentHealthworker].Id;
                Navigation.PushAsync(new HealthworkerPage());
            }
            else
            {
                // Display an error.
                DisplayAlert("Error", "Sorry, something went wrong. Please try again later.", "Okay");
            }
        }