예제 #1
0
        private async Task InsertAppointment()
        {
            if (ValidateInputs())
            {
                List <Service> services = new List <Service>();

                foreach (Service service in LbServices.Items)
                {
                    services.Add(service);
                }

                AppointmentInsertVM appointmentInsertVM = new AppointmentInsertVM()
                {
                    Date            = DpDate.SelectedDate.Value,
                    Time            = TpTime.Value.Value.TimeOfDay,
                    RegisteredUser  = (RegisteredUser)CbCustomers.SelectedItem,
                    Services        = services,
                    HairSalonId     = worker.HairSalonId,
                    Worker          = worker,
                    MethodOfPayment = (MethodOfPayment)CbMethodsOfPayment.SelectedItem
                };

                bool appointmentIsNotAvailable = await appointmentApi.CheckAppointmentAvailability(new CheckAvailabilityVM()
                {
                    Date = appointmentInsertVM.Date, Time = appointmentInsertVM.Time, WorkerId = appointmentInsertVM.Worker.Id
                });

                if (appointmentIsNotAvailable)
                {
                    MessageBox.Show("Appointment is not available!");
                    return;
                }

                ls.LblLoading.Text = "Adding";
                ls.Show();
                bool success = await appointmentApi.InsertAppointment(appointmentInsertVM);

                ls.Close();

                if (success)
                {
                    Close();
                }
                else
                {
                    MessageBox.Show("Fail!");
                }
            }
            else
            {
                MessageBox.Show(
                    "All input fields are required!\n" +
                    "You must select atleast one service!");
            }
        }
예제 #2
0
        public async Task <ActionResult> Create(AppointmentInsertVM appointmentInsertVM)
        {
            appointmentApi = new AppointmentApiClient();

            bool appointmentIsNotAvailable = false;

            if (ModelState.IsValid)
            {
                appointmentIsNotAvailable = await appointmentApi.CheckAppointmentAvailability(new CheckAvailabilityVM()
                {
                    Date = appointmentInsertVM.Date, Time = appointmentInsertVM.Time, WorkerId = int.Parse(appointmentInsertVM.SelectedWorkerId)
                });
            }

            if (!appointmentIsNotAvailable)
            {
                if (ModelState.IsValid)
                {
                    RegisteredUser registeredUser = (RegisteredUser)Session["RegisteredUser"];
                    appointmentInsertVM.RegisteredUser = registeredUser;

                    await appointmentApi.InsertAppointmentByUser(appointmentInsertVM);

                    return(RedirectToAction("UserProfile", "Account"));
                }
            }
            else
            {
                ViewBag.Unavailable = "unavailable";
            }

            hairSalonApi = new HairSalonApiClient();

            HairSalon hairSalon = await hairSalonApi.GetHairSalon(appointmentInsertVM.HairSalonId.Value);

            List <SelectListItem> workers          = new List <SelectListItem>();
            List <SelectListItem> services         = new List <SelectListItem>();
            List <SelectListItem> methodsOfPayment = new List <SelectListItem>();

            foreach (var worker in hairSalon.Workers)
            {
                workers.Add(new SelectListItem()
                {
                    Value = worker.Id.ToString(), Text = worker.GetFullName()
                });
            }

            foreach (var hairSalonService in hairSalon.HairSalonServices)
            {
                services.Add(new SelectListItem()
                {
                    Value = hairSalonService.ServiceId.ToString(), Text = hairSalonService.Service.ToString()
                });
            }

            foreach (var hairSalonMethodsOfPayment in hairSalon.HairSalonMethodsOfPayment)
            {
                methodsOfPayment.Add(new SelectListItem()
                {
                    Value = hairSalonMethodsOfPayment.MethodOfPaymentId.ToString(), Text = hairSalonMethodsOfPayment.MethodOfPayment.ToString()
                });
            }

            AppointmentInsertVM newAppointmentInsertVM = new AppointmentInsertVM()
            {
                Date              = appointmentInsertVM.Date,
                Time              = appointmentInsertVM.Time,
                HairSalonId       = appointmentInsertVM.HairSalonId.Value,
                Workers           = new SelectList(workers, "Value", "Text"),
                AvailableServices = new SelectList(services, "Value", "Text"),
                MethodsOfPayment  = new SelectList(methodsOfPayment, "Value", "Text")
            };

            return(View(newAppointmentInsertVM));
        }