public async Task <IActionResult> Register(RegisterVM model) { if (ModelState.IsValid) { var user = new WCitizen { UserName = model.Username }; user.WDollars = 50; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("Index", "Home")); } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } return(View(model)); }
public async Task <IActionResult> RemoveFromAdmin(string id) { WCitizen user = await userManager.FindByIdAsync(id); var result = await userManager.RemoveFromRoleAsync(user, "Admin"); if (result.Succeeded) { } return(RedirectToAction("ManagePeople")); }
public async Task <IActionResult> AddToAdmin(string id) { IdentityRole adminRole = await roleManager.FindByNameAsync("Admin"); if (adminRole == null) { TempData["message"] = "Admin role does not exist."; } else { WCitizen user = await userManager.FindByIdAsync(id); await userManager.AddToRoleAsync(user, adminRole.Name); } return(RedirectToAction("ManagePeople")); }
public async Task <IActionResult> DeleteWCitizen(string id) { IdentityResult result = null; WCitizen user = await userManager.FindByIdAsync(id); if (user != null) { if (0 == (from r in repo.WShop where r.Owner.Name == user.Name select r).Count <WShop>()) { result = await userManager.DeleteAsync(user); } else { result = IdentityResult.Failed(new IdentityError() { Description = "User's WShops must be deleted first" }); } if (!result.Succeeded) { string errorMessage = ""; foreach (IdentityError error in result.Errors) { errorMessage += errorMessage != "" ? " | " : ""; errorMessage += error.Description; //errorMessage += error.Description + " | "; } TempData["message"] = errorMessage; } else { TempData["message"] = ""; // No errors, clear the message } } return(RedirectToAction("ManagePeople")); }