public ActionResult Create([Bind(Include = "AppointmentId,ManagerId,email,ADate,TimeSlotID,Status")] Appointment appointment) { var userName = User.Identity.GetUserName(); if (ModelState.IsValid) { if (_buildingId == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (_appointmentService.CheckAppoinment(appointment) == false) { appointment.email = userName; appointment.DateBooked = DateTime.Now.Date; appointment.Status = "Pending"; appointment.BuildingAddress = appointment.getBuildingAddress(); db.Appointments.Add(appointment); db.SaveChanges(); return(RedirectToAction("ReservationDetails", new { id = appointment.AppointmentId })); } else { ModelState.AddModelError("", "Slot is currently un available for the date chosen"); ViewBag.ManagerId = new SelectList(db.Managers, "ManagerId", "FullName", appointment.ManagerId); ViewBag.TimeSlotID = new SelectList(db.timeslots, "TimeSlotID", "TimeS", appointment.TimeSlotID); return(View(appointment)); } } ViewBag.ManagerId = new SelectList(db.Managers, "ManagerId", "FullName", appointment.ManagerId); ViewBag.TimeSlotID = new SelectList(db.timeslots, "TimeSlotID", "TimeS", appointment.TimeSlotID); return(View(appointment)); }