public ActionResult AssignUserRole(Models.UserRoleViewModel userInRole) { ViewBag.RoleName = GetRolesSelectList(); if (ModelState.IsValid && AssignRoles(userInRole.Username, userInRole.RoleName)) { return(View("SuccessfullCreation")); } return(View("AssignUserRole", userInRole)); }
public ActionResult RemoveUserFromRole(Models.UserRoleViewModel userInRole) { var rolesList = new List <string>(); foreach (var role in Roles.GetAllRoles()) { rolesList.Add(role); } ViewBag.RoleName = new SelectList(rolesList); if (ModelState.IsValid && RemoveUserFromRole(userInRole.Username, userInRole.RoleName)) { return(View("SuccessfullCreation")); } return(View("RemoveUserFromRole", userInRole)); }
public ActionResult Roles(string id) { AspNetUser user = db.AspNetUsers.Find(id); UserRoleViewModel userRole = new Models.UserRoleViewModel { UserName = user.UserName, Id = user.Id, AspNetRoles = user.AspNetRoles }; if (userRole.AspNetRoles.Count() != 0) { ViewBag.RoleId = new SelectList(Utilities.Utilities.GetRoles(), "Value", "Text", userRole.AspNetRoles.FirstOrDefault().Id); } else { ViewBag.RoleId = new SelectList(Utilities.Utilities.GetRoles(), "Value", "Text"); } return(View(userRole)); }