public ActionResult Create(UserProfile model, string Password, string IsAdmin) { if (ModelState.IsValid) { WebSecurity.CreateUserAndAccount(model.UserName, Password, new { Email = model.Email }); if (!string.IsNullOrEmpty(IsAdmin)) Roles.AddUserToRole(model.UserName, "Admin"); return RedirectToAction("Index"); } return View(model); }
public ActionResult Edit(UserProfile model, string IsAdmin) { if (ModelState.IsValid) { var u = db.UserProfiles.Find(model.UserId); u.UserName = model.UserName; u.Email = model.Email; db.SaveChanges(); if (!string.IsNullOrEmpty(IsAdmin)) { if(!Roles.IsUserInRole(u.UserName, "Admin")) Roles.AddUserToRole(u.UserName, "Admin"); } else Roles.RemoveUserFromRole(u.UserName, "Admin"); return RedirectToAction("Index"); } return View(model); }