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));
        }
Exemple #2
0
        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();
 }
Exemple #4
0
 public static void Initialize()
 {
     Database.SetInitializer(new MigrateDatabaseToLatestVersion <MyMedicalGuideDbContext, Configuration>());
     MyMedicalGuideDbContext.Create().Database.Initialize(true);
 }
 public UsersService()
 {
     this.context = new MyMedicalGuideDbContext();
 }