public ActionResult Create(PatientViewModel patientDetail) { var alreadyExists = db.PatientDetails.Where(p => p.FullName == patientDetail.PatientDetails.FullName && p.ContactNo == patientDetail.PatientDetails.ContactNo); if (alreadyExists.Count() > 0) { ModelState.AddModelError("", "Patient with same name and contact no already exists in the system"); } if (ModelState.IsValid) { try { var currentUserId = User.Identity.GetUserId(); long customerId = 1; long branchId = 1; if (currentUserId != null) { var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())); customerId = manager.FindById(currentUserId).HMSEmpID; branchId = manager.FindById(currentUserId).BranchID; patientDetail.PatientDetails.CreatedBy = Convert.ToInt32(customerId); } DateTime today = DateTime.Today; //int age = today.Year - patientDetail.PatientDetails.Age; patientDetail.PatientDetails.DOB = today.AddYears(- (patientDetail.PatientDetails.Age)); //if (patientDetail.PatientDetails.DOB.Date > today.AddYears(-age)) age--; //patientDetail.PatientDetails.Age = age; patientDetail.PatientDetails.CreatedOn = DateTime.Now; patientDetail.PatientDetails.DateOfRegistration = DateTime.Now; db.PatientDetails.Add(patientDetail.PatientDetails); db.SaveChanges(); patientDetail.Appointment.CreatedDate = DateTime.Now; patientDetail.Appointment.CreatedBy = Convert.ToInt32(customerId); //patientDetail.Appointment.BranchDetails_ID = Convert.ToInt32(branchId); patientDetail.PatientDetails.Appointments.Add(patientDetail.Appointment); db.SaveChanges(); return RedirectToAction("Index", "Appointments"); } catch (Exception ex) { throw ex; } } ViewBag.Specialization = new SelectList(db.Specializations.ToList(), "ID", "Name", patientDetail.Appointment.Specialization_ID); ViewBag.Doctors = new SelectList(db.Doctors.Include("EmployeeDetail").ToList(), "ID", "EmployeeDetail.FirstName", patientDetail.Appointment.Doctor_ID); ViewBag.City = new SelectList(db.Cities.ToList(), "ID", "Name", patientDetail.PatientDetails.City_ID); ViewBag.ShiftType = new SelectList(db.ShiftTypes, "ID", "Name", patientDetail.Appointment.ShiftType_ID); ViewBag.PatientType = new SelectList(db.PatientTypes, "ID", "Type", patientDetail.Appointment.PatientType_ID); ViewBag.Branch = new SelectList(db.BranchDetails, "ID", "Name", patientDetail.Appointment.BranchDetails_ID); return View(patientDetail); }
// GET: Patient/Create public ActionResult Create() { PatientViewModel model = new PatientViewModel(); Appointment appointment = new Appointment(); appointment.AppointmentDate = DateTime.Now; model.Appointment = appointment; ViewBag.Specialization = new SelectList(db.Specializations.ToList(), "ID", "Name"); List<DoctorName> doctornamelist = UtilityManager.GetName(); ViewBag.Doctors = new SelectList(doctornamelist, "ID", "Name"); //ViewBag.Doctors = new SelectList(db.Doctors.Include("EmployeeDetail").ToList(), "ID", "EmployeeDetail.LastName"); ViewBag.City = new SelectList(db.Cities.ToList(), "ID", "Name"); ViewBag.ShiftType = new SelectList(db.ShiftTypes, "ID", "Name"); ViewBag.PatientType = new SelectList(db.PatientTypes, "ID", "Type"); ViewBag.Branch = new SelectList(db.BranchDetails, "ID", "Name"); return View(model); }