public bool UpdateAppointment(int id, AppointmentUpdateVM appointmentUpdateVM) { Appointment appointment = unitOfWork.Appointments.Get(id); appointment.IsCompleted = appointmentUpdateVM.IsCompleted; int success = unitOfWork.Complete(); return(success > 0); }
public async Task <ActionResult> Edit(int id) { appointmentApi = new AppointmentApiClient(); hairSalonApi = new HairSalonApiClient(); Appointment appointment = await appointmentApi.GetAppointment(id); HairSalon hairSalon = await hairSalonApi.GetHairSalon(appointment.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() }); } AppointmentUpdateVM appointmentUpdateVM = new AppointmentUpdateVM() { Date = appointment.Date, Time = appointment.Time, Workers = new SelectList(workers, "Value", "Text"), SelectedWorker = new SelectListItem() { Value = appointment.Worker.Id.ToString(), Text = appointment.Worker.GetFullName() }, AvailableServices = new SelectList(services, "Value", "Text"), MethodsOfPayment = new SelectList(methodsOfPayment, "Value", "Text"), HairSalonId = hairSalon.Id }; return(View(appointmentUpdateVM)); }
public async Task <ActionResult> Cancel(int id) { appointmentApi = new AppointmentApiClient(); AppointmentUpdateVM appointmentUpdateVM = new AppointmentUpdateVM() { IsCompleted = true }; await appointmentApi.UpdateAppointment(id, appointmentUpdateVM); return(RedirectToAction("Details", "Appointment", new { id })); }
public async Task <bool> UpdateAppointmentByUser(AppointmentUpdateVM appointmentUpdateVM) { StringContent content = GetStringContent(appointmentUpdateVM); HttpClient request = new HttpClient(); HttpResponseMessage response = await request.PutAsync($"{ API_URL }/UpdateAppointmentByUser", content); if (response.IsSuccessStatusCode) { bool result = await response.Content.ReadAsAsync <bool>(); return(result); } return(false); }
public bool UpdateAppointmentByUser(AppointmentUpdateVM appointmentUpdateVM) { HairSalon hairSalon = unitOfWork.HairSalons.Get(appointmentUpdateVM.HairSalonId); RegisteredUser registeredUser = unitOfWork.RegisteredUsers.Get(appointmentUpdateVM.RegisteredUser.Id); Worker worker = unitOfWork.Workers.Get(int.Parse(appointmentUpdateVM.SelectedWorkerId)); MethodOfPayment methodOfPayment = unitOfWork.MethodsOfPayment.Get(int.Parse(appointmentUpdateVM.SelectedMethodOfPaymentId)); Appointment appointment = unitOfWork.Appointments.Get(appointmentUpdateVM.Id); appointment.Date = appointmentUpdateVM.Date; appointment.Time = appointmentUpdateVM.Time; appointment.IsCompleted = false; appointment.HairSalonId = hairSalon.Id; appointment.RegisteredUserId = registeredUser.Id; appointment.WorkerId = worker.Id; appointment.MethodOfPayment = methodOfPayment; decimal sum = 0; foreach (int serviceId in appointmentUpdateVM.SelectedServices) { Service serviceForAppointment = unitOfWork.Services.Get(serviceId); sum += serviceForAppointment.Price; } appointment.TotalPrice = sum; unitOfWork.Complete(); unitOfWork.AppointmentServices.RemoveAppointmentServices(appointment.Id); Appointment appointmentForService = unitOfWork.Appointments.GetAppointment(appointment.Id); foreach (int serviceId in appointmentUpdateVM.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); }
private async Task CompleteAppointment() { AppointmentUpdateVM appointmentUpdateVM = new AppointmentUpdateVM() { IsCompleted = true }; bool success = await appointmentApi.UpdateAppointment(appointment.Id, appointmentUpdateVM); if (success) { MessageBox.Show($"Sucessfully completed appointment!"); } else { MessageBox.Show("Fail"); } }
public async Task <ActionResult> Edit(AppointmentUpdateVM appointmentUpdateVM) { appointmentApi = new AppointmentApiClient(); bool appointmentIsNotAvailable = false; if (ModelState.IsValid) { appointmentIsNotAvailable = await appointmentApi.CheckAppointmentAvailability(new CheckAvailabilityVM() { Date = appointmentUpdateVM.Date, Time = appointmentUpdateVM.Time, WorkerId = int.Parse(appointmentUpdateVM.SelectedWorkerId) }); } if (!appointmentIsNotAvailable) { if (ModelState.IsValid) { RegisteredUser registeredUser = (RegisteredUser)Session["RegisteredUser"]; appointmentUpdateVM.RegisteredUser = registeredUser; await appointmentApi.UpdateAppointmentByUser(appointmentUpdateVM); return(RedirectToAction("Details", "Appointment", new { appointmentUpdateVM.Id })); } } else { ViewBag.Unavailable = "unavailable"; } hairSalonApi = new HairSalonApiClient(); HairSalon hairSalon = await hairSalonApi.GetHairSalon(appointmentUpdateVM.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() }); } AppointmentUpdateVM newAppointmentUpdateVM = new AppointmentUpdateVM() { Date = appointmentUpdateVM.Date, Time = appointmentUpdateVM.Time, HairSalonId = hairSalon.Id, Workers = new SelectList(workers, "Value", "Text"), AvailableServices = new SelectList(services, "Value", "Text"), MethodsOfPayment = new SelectList(methodsOfPayment, "Value", "Text") }; return(View(newAppointmentUpdateVM)); }