public ActionResult EditManager(string Id) { AppUser user = UserManager.FindById(Id); ManagerUserMode mode = new ManagerUserMode { UserId = user.Id, Email = user.Email, Phone = user.PhoneNumber, UserName = user.PayRollUser }; return(View(mode)); }
public async Task <ActionResult> Edit(ManagerUserMode viewModel) { AppUser user = UserManager.FindById(viewModel.UserId); user.PayRollUser = viewModel.UserName; user.PhoneNumber = viewModel.Phone; var result = await UserManager.UpdateAsync(user); if (!result.Succeeded) { // Add all errors to the page so they can be used to display what went wrong AddErrors(result); return(View(viewModel)); } return(RedirectToAction("Mlist")); }
public async Task <ActionResult> Add(ManagerUserMode viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } AppUser Admin = LoginUser; AppUser user = UserManager.FindByEmail(viewModel.Email); if (user != null) { ModelState.AddModelError("", "The email has been registered!"); return(View(viewModel)); } user = new AppUser { UserName = viewModel.Email, Email = viewModel.Email, PayRollUser = viewModel.UserName, PhoneNumber = viewModel.Phone, TimeZone = Admin.TimeZone, CompanyId = Admin.CompanyId }; var result = await UserManager.CreateAsync(user, "Pay123456"); if (result.Succeeded) { if (!UserManager.IsInRole(user.Id, "Manager")) { UserManager.AddToRole(user.Id, "Manager"); } string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("UserConfirm", "Account", new { userId = user.Id, code = code, Nt = TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) }, protocol: Request.Url.Scheme); string EmailBody = "Thank you for creating an PayRoll account. You need to confirm your account and setting your password, you'll have access to PayRoll system."; string EmailLink = "Please confirm your account complete regist by clicking.<a href=\"" + callbackUrl + "\">Click it! »</a>"; string strbody = ReplaceText(EmailBody, EmailLink); await UserManager.SendEmailAsync(user.Id, "Confirm Your Account (" + user.PayRollUser + ")", strbody); } return(RedirectToAction("Mlist")); }