public ActionResult Create(ApplicationUserCreateModel userModel) { if (this.ModelState.IsValid) { var applicationUser = new ApplicationUser { Email = userModel.Email, UserName = userModel.UserName, PasswordHash = userModel.Password, CreatedOn = DateTime.Now }; var userManager = this.HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var userCreateResult = userManager.Create(applicationUser, applicationUser.PasswordHash); if (!userCreateResult.Succeeded) { return(this.Content(string.Join("; ", userCreateResult.Errors))); } this.Data.SaveChanges(); return(this.RedirectToAction("Index")); } return(this.View(userModel)); }
public ActionResult Create(ApplicationUserCreateModel userModel) { if (this.ModelState.IsValid) { ApplicationUser applicationUser = new ApplicationUser { Email = userModel.Email, UserName = userModel.UserName, PasswordHash = userModel.Password, CreatedOn = DateTime.Now }; var userManager = this.HttpContext .GetOwinContext() .GetUserManager<ApplicationUserManager>(); var userCreateResult = userManager.Create(applicationUser, applicationUser.PasswordHash); if (!userCreateResult.Succeeded) { return this.Content(string.Join("; ", userCreateResult.Errors)); } this.Data.SaveChanges(); return this.RedirectToAction("Index"); } return this.View(userModel); }
public async Task <IdentityResult> CreateUserAsync(ApplicationUserCreateModel model) { var newAcount = _mapper.Map <ApplicationUser>(model.ApplicationUser); var result = await _userManager.CreateAsync(newAcount, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(newAcount, model.UserRole); } return(result); }
public async Task <bool> CreateAsync(ApplicationUserCreateModel model) { model.UserRole = UserRoles.Student; return(await _genericRepository.CreateEntityAsync(model)); }