public async Task <IActionResult> Edit(string id, ApplicationStoreUser applicationStoreUser) { if (id != applicationStoreUser.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var user = await _context.ApplicationStoreUsers.FirstOrDefaultAsync(i => i.Id == applicationStoreUser.Id); user.FirstName = applicationStoreUser.FirstName; user.LastName = applicationStoreUser.LastName; user.PhoneNumber = applicationStoreUser.PhoneNumber; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApplicationStoreUserExists(applicationStoreUser.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(applicationStoreUser)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { //var user = new IdentityUser { UserName = Input.Email, Email = Input.Email }; var applicationStoreUser = new ApplicationStoreUser { UserName = Input.Email, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName, PhoneNumber = Input.PhoneNumber, MemberType = Input.MemberType }; // changed by developer var result = await _userManager.CreateAsync(applicationStoreUser, Input.Password); if (result.Succeeded) { // Added by developer---------------------------------------- if (Input.MemberType == MemberTypeEnum.SuperAdmin) { await _userManager.AddToRoleAsync(applicationStoreUser, StaticInfo.SuperAdminUser); } else if (Input.MemberType == MemberTypeEnum.Admin) { await _userManager.AddToRoleAsync(applicationStoreUser, StaticInfo.AdminUser); } else if (Input.MemberType == MemberTypeEnum.Member) { await _userManager.AddToRoleAsync(applicationStoreUser, StaticInfo.MemberUser); } //----------------------------------------------------------- //_logger.LogInformation("User created a new account with password."); if (!User.IsInRole(StaticInfo.SuperAdminUser)) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(applicationStoreUser); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = applicationStoreUser.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(applicationStoreUser, isPersistent : false); return(LocalRedirect(returnUrl)); } else { return(RedirectToAction("Index", "AdminUsers", new { area = "Admin" })); // Added by developer } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }