public ActionResult Doctors_Create([DataSourceRequest]DataSourceRequest request, DoctorGridViewModel doctor) { if (this.ModelState.IsValid) { //TODO:Create service for users var context = new MyMedicalGuideDbContext(); var userManager = new UserManager<User>(new UserStore<User>(context)); var userDoctor = new User() { Email = doctor.Email, FirstName = doctor.FirstName, LastName = doctor.LastName, PhoneNumber = doctor.PhoneNumber, UserName = doctor.Username }; var hospitalId = this.TempData["hospitalId"]; userManager.Create(userDoctor, doctor.Password); var DoctorDb = new MyMedicalGuide.Data.Models.Doctor() { User = userDoctor, HospitalId = (int)hospitalId, DepartmentId = doctor.DepartmentId, CreatedOn = DateTime.Now }; context.Doctors.Add(DoctorDb); userManager.AddToRole(userDoctor.Id, "Doctor"); } return this.Json(new[] { doctor }.ToDataSourceResult(request, this.ModelState)); }
public ActionResult Doctors_Create([DataSourceRequest] DataSourceRequest request, DoctorGridViewModel doctor) { if (this.ModelState.IsValid) { //TODO:Create service for users var context = new MyMedicalGuideDbContext(); var userManager = new UserManager <User>(new UserStore <User>(context)); var userDoctor = new User() { Email = doctor.Email, FirstName = doctor.FirstName, LastName = doctor.LastName, PhoneNumber = doctor.PhoneNumber, UserName = doctor.Username }; var hospitalId = this.TempData["hospitalId"]; userManager.Create(userDoctor, doctor.Password); var DoctorDb = new MyMedicalGuide.Data.Models.Doctor() { User = userDoctor, HospitalId = (int)hospitalId, DepartmentId = doctor.DepartmentId, CreatedOn = DateTime.Now }; context.Doctors.Add(DoctorDb); userManager.AddToRole(userDoctor.Id, "Doctor"); } return(this.Json(new[] { doctor }.ToDataSourceResult(request, this.ModelState))); }
public UsersService() { this.context = new MyMedicalGuideDbContext(); }
public static void Initialize() { Database.SetInitializer(new MigrateDatabaseToLatestVersion <MyMedicalGuideDbContext, Configuration>()); MyMedicalGuideDbContext.Create().Database.Initialize(true); }