public ActionResult DeleteUser(string id) { var user = UserManager.FindById(id.ToString()); var result = UserManager.Delete(user); var db = new METRO_LIVEEntities(); var itemsToRemove = db.Users.RemoveRange(db.Users.Where(x => x.Email == user.Email)); db.Users.RemoveRange(itemsToRemove); db.SaveChanges(); if (result.Succeeded) { return View("DeleteStatus"); } else { return View("Error"); } }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); var u = new User(); u.UserName = model.UserName; u.Email = model.Email; var db = new DAL.METRO_LIVEEntities(); db.Users.Add(u); db.SaveChanges(); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); ViewBag.Message = "Check your email and confirm your account, you must be confirmed " + "before you can log in."; return View("Info"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }
public async Task<ActionResult> AddUser(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var u = new User(); u.UserName = model.UserName; u.Email = model.Email; var db = new DAL.METRO_LIVEEntities(); db.Users.Add(u); db.SaveChanges(); string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var cResult = await UserManager.ConfirmEmailAsync(user.Id, code); return View("UserInfoOk"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }