public ActionResult RequestAppointment(int petId) { var viewModel = new RequestAppointmentViewModel(); viewModel.petId = petId; return(View(viewModel)); }
public RequestAppointmentViewModel Build(int id, string userId) { var property = _context.Properties.Find(id); var retModel = new RequestAppointmentViewModel { PropertyId = property.Id, PropertyType = property.PropertyType, StreetName = property.StreetName }; return(retModel); }
public async Task <object> RequestAppointment(RequestAppointmentViewModel viewModel) { bool isTaken = false; var appointmentsOnTheSameDate = await _repository.GetAppointmentsByDate(viewModel.Date); if (appointmentsOnTheSameDate.Count < 6) { foreach (var appointment in appointmentsOnTheSameDate) { if (appointment.StartTime.Equals(viewModel.Hour)) { isTaken = true; break; } } if (isTaken) { var availableHours = viewModel.Hours; foreach (var appointment in appointmentsOnTheSameDate) { var remove = availableHours.Where(o => o.Value.Equals(appointment.StartTime)).FirstOrDefault(); availableHours.Remove(remove); } return(viewModel); } else { var newAppointment = new AppointmentModel { ServiceID = viewModel.ServiceId, PetID = viewModel.petId, StartTime = viewModel.Hour, Date = viewModel.Date, }; var success = await _repository.BookAppointment(newAppointment); if (success) { return("Date Booked"); } else { return("Error"); } } } else { return("Date Not Available"); } }
public async Task <ActionResult> RequestAppointment(RequestAppointmentViewModel viewModel) { if (ModelState.IsValid && viewModel.ServiceId > 0) { var outCome = await UserService.RequestAppointment(viewModel); if (outCome.GetType() == typeof(string)) { var code = outCome as string; switch (code) { case "Date Booked": TempData["successBooked"] = "success"; return(RedirectToAction("Managment")); case "Date Not Available": ViewBag.DateNotAvailable = "No appointments available for this date"; return(View(viewModel)); case "Error": ViewBag.Failed = "An error has ocurred pleas "; return(View(viewModel)); } } else if (outCome.GetType() == typeof(RequestAppointmentViewModel)) { var updatedViewModel = outCome as RequestAppointmentViewModel; ViewBag.HourTaken = "The Hour has been already taken"; return(View(updatedViewModel)); } } if (viewModel.ServiceId <= 0) { ViewBag.PickService = "Selection is needed"; } return(View(viewModel)); }