public ActionResult Create(CreatePhysicianModel physicianInfo) { if (ModelState.IsValid) { if (!WebSecurity.UserExists(physicianInfo.UserName)) { db.AttendingPhysicians.Add(new AttendingPhysician { UserName = physicianInfo.UserName, Email = physicianInfo.Email, Name = physicianInfo.Name, Phone = physicianInfo.Phone, SSN = physicianInfo.SSN, Department = db.Departments.Find(physicianInfo.DepartmentID) }); db.SaveChanges(); WebSecurity.CreateAccount(physicianInfo.UserName, physicianInfo.Password); Roles.AddUsersToRoles(new[] { physicianInfo.UserName }, new[] { "AttendingPhysician" }); return RedirectToAction("Index"); } else { ModelState.AddModelError("", string.Format("Login name \"{0}\" already exists.", physicianInfo.UserName)); } } return View(physicianInfo); }
// // GET: /Physician/Create public ActionResult Create() { var physicianInfo = new CreatePhysicianModel(); physicianInfo.Departments = new SelectList( db.Departments, "DepartmentID", "DepartmentName", db.InsuranceCompanies.First()); return View(physicianInfo); }