public async Task <IActionResult> DeleteUser(string id) { if (id == null) { return(RedirectToAction("Error")); } CleaningUser user = await userManager.FindByIdAsync(id); await userManager.DeleteAsync(user); return(RedirectToAction("ViewUser", "Account")); }
public async Task <IActionResult> Register(RegisterModel model) { if (ModelState.IsValid) { var polly = CompanyRepository.GetCompany(); var user = await userManager.FindByNameAsync(model.Email); if (user == null) { user = new CleaningUser { Id = Guid.NewGuid().ToString(), Fullname = model.Fullname, UserName = model.Email, Email = model.Email, PhoneNumber = model.PhoneNumber, Created = DateTime.Now }; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await userManager.AddToRoleAsync(user, "Admin"); var token = await userManager.GenerateEmailConfirmationTokenAsync(user); var confirmationEmail = Url.Action("ConfirmEmailAddress", "Local", new { token = token, email = user.Email }, Request.Scheme); string confirm = "Please confirm your account by clicking this link: <a href=\"" + confirmationEmail + "\">link</a>"; EmailService.Send(user.Email, user.Fullname, "Confirmation message", confirm); // System.IO.File.WriteAllText("confirmation.txt", confirmationEmail); ModelState.Clear(); HttpContext.Session.SetString("Success", "A link has been sent to your Email account for confirmation"); return(RedirectToAction("Register")); } } else { //user exist ViewBag.AccountExist = "A link has been sent to your Email account for confirmation"; string confirm = "you attempted to register an email address that already exist on the system if you would like to login:<a href= \"" + Url.Action("Login", "Account") + "\">click here</a>"; EmailService.Send(user.Email, user.Fullname, "Account Exist", confirm); } } return(View()); }
public async Task <IActionResult> RegisterStaff(RegisterStaffModel model, List <IFormFile> UserImage) { if (ModelState.IsValid) { var polly = await userManager.FindByEmailAsync(model.Email); if (polly == null) { IFormFile f = UserImage.FirstOrDefault(); if (f.Length > 0) { if (IsImage(f)) { byte[] imageData = null; using (var binary = new MemoryStream()) { await f.CopyToAsync(binary); imageData = binary.ToArray(); } var user = new CleaningUser { Id = Guid.NewGuid().ToString(), Fullname = model.Fullname, Email = model.Email, PhoneNumber = model.PhoneNumber, UserName = model.Email, Created = DateTime.Now }; var k = new UserImageRecord { Staff = user, Upload = imageData }; var result = await userManager.CreateAsync(user, model.Password); UserImageImp.AddUserImage(k); if (result.Succeeded) { await userManager.AddToRoleAsync(user, model.UserRoles); HttpContext.Session.SetString("Success", "Registration in Progress,check your email to complete the registration"); var token = await userManager.GenerateEmailConfirmationTokenAsync(user); string confirmationEmail = Url.Action("ConfirmEmailAddress", "Local", new { token, email = user.Email }, Request.Scheme); string confirm = "Please confirm your account by clicking this link: <a href=\"" + confirmationEmail + "\">link</a>"; EmailService.Send(user.Email, user.Fullname, "Confirmation message", confirm); ModelState.Clear(); return(RedirectToAction("RegisterStaff")); } } else { ViewBag.NotRightFormat = "you have not uploaded an image"; } } else { ViewBag.noImage = "you have not uploaded an image"; } } else { ViewBag.Exist = "Registration in Progress,check your email to complete the registration"; string confirm = "you attempted to register an email address that already exist on the system if you would like to login:<a href= \"" + Url.Action("Login", "Account") + "\">click here</a>"; EmailService.Send(polly.Email, polly.Fullname, "Account Exist", confirm); } } ViewBag.role = GetUserRole(); return(View()); }