Esempio n. 1
0
        async Task AddRating()
        {
            if (Grade <= 0 || Grade > 10)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "You have to add rating in range 1 - 10!", "OK");

                return;
            }

            if (string.IsNullOrEmpty(Comment))
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Comment field is required", "OK");

                return;
            }

            try
            {
                bool answer = await Application.Current.MainPage.DisplayAlert("Alert", "Would you like to add rating?", "Yes", "No");

                if (answer)
                {
                    RatingInsertRequest request = new RatingInsertRequest
                    {
                        UserID        = Appointment.UserID,
                        DentistID     = Appointment.DentistID,
                        DentistRating = Grade,
                        Comment       = Comment,
                        RatingDate    = RatingDate
                    };
                    await _ratingService.Insert <Rating>(request);

                    await Application.Current.MainPage.DisplayAlert("Success", "You have sucessfully added rating for a dentist!", "OK");

                    var appointment = await _appointmentService.GetById <Appointment>(Appointment.AppointmentID);

                    AppointmentInsertRequest update_request = new AppointmentInsertRequest
                    {
                        UserID       = Appointment.UserID,
                        DentistID    = Appointment.DentistID,
                        TreatmentID  = Appointment.TreatmentID,
                        StartDate    = Appointment.StartDate,
                        EndDate      = Appointment.EndDate,
                        RatingStatus = true
                    };
                    await _appointmentService.Update <Appointment>(Appointment.AppointmentID, update_request);

                    Application.Current.MainPage = new MainPage();
                }
            }
            catch (Exception)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Something went wrong", "OK");
            }
        }
Esempio n. 2
0
        async Task AddPayment()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(CreditCardNumber))
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Credit card number field is required !", "OK");

                    return;
                }
                var client = await _userService.GetById <User>(DentistTreatmentAppointment.UserID);

                var dentist = await _dentistService.GetById <Dentist>(DentistTreatmentAppointment.DentistID);

                var treatment = await _treatmentService.GetById <Treatment>(DentistTreatmentAppointment.TreatmentID);

                AppointmentInsertRequest request = new AppointmentInsertRequest
                {
                    UserID       = client.UserID,
                    DentistID    = dentist.DentistID,
                    TreatmentID  = treatment.TreatmentID,
                    StartDate    = DentistTreatmentAppointment.StartDate,
                    EndDate      = DentistTreatmentAppointment.StartDate.AddHours(DentistTreatmentAppointment.TimeRequired),
                    RatingStatus = false,
                };
                var result = await _appointmentService.Insert <Appointment>(request);

                if (result == null)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Appointment already booked! Please book another appointment", "OK");

                    return;
                }
                else
                {
                    await _paymentService.Insert <Payment>(new PaymentInsertRequest
                    {
                        UserID      = client.UserID,
                        TreatmentID = treatment.TreatmentID,
                        Amount      = treatment.Price,
                        Date        = Date
                    });

                    await Application.Current.MainPage.DisplayAlert("Success", "You have successfully booked an appointment!", "OK");

                    Application.Current.MainPage = new MainPage();
                }
            }
            catch (Exception)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Somethning went wrong", "OK");
            }
        }
        async Task BookAnAppointment()
        {
            try
            {
                if (Time.Hours < 8 || Time.Hours > 16)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Business hours is 8:00 AM - 17:00 PM", "OK");

                    return;
                }

                var list = await _userService.GetAll <List <User> >(new UserSearchRequest { Username = APIService.Username });

                var client = list[0];

                var appointments = await _appointmentService.GetAll <List <Appointment> >(new AppointmentSearchRequest { UserID = client.UserID });

                foreach (var appointment in appointments)
                {
                    if (appointment.StartDate.Date == StartDate.Date)
                    {
                        await Application.Current.MainPage.DisplayAlert("Error", "You can book only one appointment per day !", "OK");

                        return;
                    }
                }

                var hours   = Time.Hours;
                var minutes = Time.Minutes;

                FullStartDate = StartDate.Date.Add(new TimeSpan(hours, minutes, 0));

                AppointmentInsertRequest request = new AppointmentInsertRequest
                {
                    UserID       = client.UserID,
                    DentistID    = DentistTreatment.DentistID,
                    TreatmentID  = DentistTreatment.TreatmentID,
                    StartDate    = FullStartDate,
                    EndDate      = FullStartDate.AddHours(DentistTreatment.TimeRequired),
                    RatingStatus = false
                };

                bool answer = await Application.Current.MainPage.DisplayAlert("Alert", "Would you like to add payment?", "Yes", "No");

                if (answer)
                {
                    await Application.Current.MainPage.Navigation.PushModalAsync(new PaymentPage(new DentistTreatmentAppointmentDTO {
                        UserID = client.UserID,
                        DentistID = DentistTreatment.DentistID,
                        TreatmentID = DentistTreatment.TreatmentID,
                        StartDate = FullStartDate,
                        EndDate = EndDate,
                        TimeRequired = DentistTreatment.TimeRequired
                    }));
                }
                else
                {
                    var result = await _appointmentService.Insert <Appointment>(request);

                    if (result == null)
                    {
                        await Application.Current.MainPage.DisplayAlert("Error", "Appointment already booked! Please book another appointment", "OK");

                        return;
                    }
                    else
                    {
                        await Application.Current.MainPage.DisplayAlert("Success", "You have successfully booked an appointment!", "OK");

                        Application.Current.MainPage = new MainPage();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }