Ejemplo n.º 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!");
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> InsertAppointment(AppointmentInsertVM appointmentInsertVM)
        {
            StringContent content = GetStringContent(appointmentInsertVM);
            HttpClient    request = new HttpClient();

            HttpResponseMessage response = await request.PostAsync($"{ API_URL }/InsertAppointment", content);

            if (response.IsSuccessStatusCode)
            {
                bool result = await response.Content.ReadAsAsync <bool>();

                return(result);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public bool InsertAppointment(AppointmentInsertVM appointmentInsertVM)
        {
            HairSalon       hairSalon       = unitOfWork.HairSalons.Get(appointmentInsertVM.HairSalonId);
            RegisteredUser  registeredUser  = unitOfWork.RegisteredUsers.Get(appointmentInsertVM.RegisteredUser.Id);
            Worker          worker          = unitOfWork.Workers.Get(appointmentInsertVM.Worker.Id);
            MethodOfPayment methodOfPayment = unitOfWork.MethodsOfPayment.Get(appointmentInsertVM.MethodOfPayment.Id);

            string   newTime    = appointmentInsertVM.Time.ToString("hh':'mm");
            TimeSpan newierTime = TimeSpan.Parse(newTime);

            Appointment appointment = new Appointment()
            {
                Date            = appointmentInsertVM.Date,
                Time            = newierTime,
                IsCompleted     = false,
                HairSalon       = hairSalon,
                RegisteredUser  = registeredUser,
                Worker          = worker,
                MethodOfPayment = methodOfPayment
            };

            decimal sum = 0;

            foreach (Service service in appointmentInsertVM.Services)
            {
                sum += service.Price;
            }
            appointment.TotalPrice = sum;

            unitOfWork.Appointments.Add(appointment);
            unitOfWork.Complete();

            Appointment appointmentForService = unitOfWork.Appointments.GetAppointment(appointment.Date, appointment.Time);

            foreach (Service service in appointmentInsertVM.Services)
            {
                Service serviceForAppointment = unitOfWork.Services.Get(service.Id);
                unitOfWork.AppointmentServices.Add(new AppointmentServices()
                {
                    Appointment = appointmentForService, Service = serviceForAppointment
                });
            }

            int success = unitOfWork.Complete();

            return(success > 0);
        }
Ejemplo n.º 4
0
        public bool InsertAppointmentByUser(AppointmentInsertVM appointmentInsertVM)
        {
            HairSalon       hairSalon       = unitOfWork.HairSalons.Get(appointmentInsertVM.HairSalonId);
            RegisteredUser  registeredUser  = unitOfWork.RegisteredUsers.Get(appointmentInsertVM.RegisteredUser.Id);
            Worker          worker          = unitOfWork.Workers.Get(int.Parse(appointmentInsertVM.SelectedWorkerId));
            MethodOfPayment methodOfPayment = unitOfWork.MethodsOfPayment.Get(int.Parse(appointmentInsertVM.SelectedMethodOfPaymentId));

            Appointment appointment = new Appointment()
            {
                Date            = appointmentInsertVM.Date,
                Time            = appointmentInsertVM.Time,
                IsCompleted     = false,
                HairSalon       = hairSalon,
                RegisteredUser  = registeredUser,
                Worker          = worker,
                MethodOfPayment = methodOfPayment
            };

            decimal sum = 0;

            foreach (int serviceId in appointmentInsertVM.SelectedServices)
            {
                Service serviceForAppointment = unitOfWork.Services.Get(serviceId);
                sum += serviceForAppointment.Price;
            }
            appointment.TotalPrice = sum;

            unitOfWork.Appointments.Add(appointment);
            unitOfWork.Complete();

            Appointment appointmentForService = unitOfWork.Appointments.GetAppointment(appointment.Id);

            foreach (int serviceId in appointmentInsertVM.SelectedServices)
            {
                Service serviceForAppointment = unitOfWork.Services.Get(serviceId);
                unitOfWork.AppointmentServices.Add(new AppointmentServices()
                {
                    AppointmentId = appointmentForService.Id, ServiceId = serviceForAppointment.Id
                });
            }

            int success = unitOfWork.Complete();

            return(success > 0);
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Create(int hairSalonId)
        {
            hairSalonApi = new HairSalonApiClient();

            HairSalon hairSalon = await hairSalonApi.GetHairSalon(hairSalonId);

            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 appointmentInsertVM = new AppointmentInsertVM()
            {
                HairSalonId       = hairSalonId,
                Workers           = new SelectList(workers, "Value", "Text"),
                AvailableServices = new SelectList(services, "Value", "Text"),
                MethodsOfPayment  = new SelectList(methodsOfPayment, "Value", "Text")
            };

            return(View(appointmentInsertVM));
        }
Ejemplo n.º 6
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));
        }