// GET: Appointment/ScheduleAppointment public ActionResult ScheduleAppointment() { DateTime Date = DateTime.Now; var db = new ApplicationDbContext(); var userId = User.Identity.GetUserId(); var user = UserManager.FindById(userId); var physicianId = user.PhysicianID; if (physicianId == null) { return(RedirectToAction("Index", "Manage", new { Message = ManageController.ManageMessageId.RequirePhysician })); } var apts = db.Appointments.Where(u => u.PhysicianID == physicianId).OrderBy(u => u.TimeDate).ToList(); Dictionary <string, bool> TimeDates = new Dictionary <string, bool>(); foreach (var item in apts) { TimeDates[item.TimeDate.ToString()] = true; } var model = new ScheduleAppointmentViewModel { PhysicianAppointments = apts, Date = Date, TimeDates = TimeDates }; return(View(model)); }
public ActionResult ScheduleAppointment(ScheduleAppointmentViewModel model) { string reason = Request.Form["reas"]; string date = Request.Form["value"]; if (reason == null || date == null) { return(View(model)); } DateTime TimeDate = Convert.ToDateTime(date); var db = new ApplicationDbContext(); var userId = User.Identity.GetUserId(); var user = UserManager.FindById(userId); var physicianId = user.PhysicianID; db.Appointments.Add(new Appointments { PatientID = userId, PhysicianID = physicianId, Reason = reason, TimeDate = TimeDate }); db.SaveChanges(); return(RedirectToAction("Index", new { Message = AppointmentMessageId.ScheduleAppointmentSuccess })); }