public ActionResult ChangeRole(UserEditModel model)
 {
     var user = Membership.GetUser(model.UserName);
     string[] roles = Roles.GetRolesForUser(user.UserName);
     string newRole = "User";
     if (roles[0] == "User") newRole = "Admin";
     Roles.RemoveUserFromRoles(model.UserName, roles);
     Roles.AddUserToRole(model.UserName, newRole);
     return RedirectToAction("ChangeRoleSuccess");
 }
 public ActionResult ChangeRole(string Name, string ViewType)
 {
     var user = Membership.GetUser(Name);
     if (User.IsInRole("Admin") && User.Identity.Name != user.UserName)
     {
         var model = new UserEditModel();
         model.UserName = Name;
         model.ViewType = ViewType;
         return View(model);
     }
     return RedirectToAction("../Home/Index");
 }
 public ActionResult Delete(UserEditModel model)
 {
     if (ModelState.IsValid)
         {
             if (User.IsInRole("Admin"))
             {
                 MembershipUser currentUser = Membership.GetUser(model.UserName, true /* userIsOnline */);
                 bool deleteResult = Membership.DeleteUser(model.UserName);
                 string statusString = "OK";
                 if (!deleteResult) statusString = "Fail";
                 RouteValueDictionary routeValues = new RouteValueDictionary();
                 routeValues.Add("Status", statusString);
                 return RedirectToAction("DeleteSuccess", routeValues);
             }
         }
     return View(model);
 }
 // GET: /User/Delete/5
 public ActionResult Delete(string Name, string ViewType)
 {
     var model = new UserEditModel();
     model.UserName = Name;
     model.ViewType = ViewType;
     return View(model);
 }
 public ActionResult ResetPassword(UserEditModel model)
 {
     if (ModelState.IsValid)
         {
             if (User.IsInRole("Admin") || model.UserName == User.Identity.Name)
             {
                 MembershipUser currentUser = Membership.GetUser(model.UserName, true /* userIsOnline */);
                 string NewPass = currentUser.ResetPassword();
                 RouteValueDictionary routeValues = new RouteValueDictionary();
                 routeValues.Add("NewPassword", NewPass);
                 routeValues.Add("ViewType", model.ViewType);
                 routeValues.Add("UserName", model.UserName);
                 return RedirectToAction("ResetPasswordSuccess", routeValues);
             }
         }
     return View();
 }
 public ActionResult Edit(UserEditModel model)
 {
     if (User.IsInRole("Admin") || db.Users.Find(model.UserDetails.UserId).Name == User.Identity.Name )
     {
         if (ModelState.IsValid)
         {
             db.Entry(model.UserDetails).State = EntityState.Modified;
             db.SaveChanges();
             if (model.ViewType == "All")
             {
                 return RedirectToAction("Index");
             }
             else
             {
                 RouteValueDictionary routeValues = new RouteValueDictionary();
                 routeValues.Add("Name", model.UserName);
                 routeValues.Add("ViewType", model.ViewType);
                 return RedirectToAction("../User/Details",routeValues);
             }
         }
         return View(model);
     }
        return RedirectToAction("../Home/Index");
 }
 public ActionResult Edit(string Name, string ViewType )
 {
     var user = Membership.GetUser(Name);
     if ( User.IsInRole("Admin") || User.Identity.Name == user.UserName )
     {
         var userModel = db.Users.Find(user.ProviderUserKey);
         var userDetailsModel = db.UserDetails.Find(userModel.UserId);
         if (userDetailsModel != null)
         {
             ViewBag.Message = Name;
             var model = new UserEditModel();
             model.ViewType = ViewType;
             model.UserName = Name;
             model.UserDetails = userDetailsModel;
             return View(model);
         }
     }
     return RedirectToAction("../Home/Index");
 }