public ActionResult Edit(Guid?id) { if (id == null) { GetAlert(Danger, "ID cannot be null!"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var user = TheUserManager.GetUserById(id); if (user == null) { GetAlert(Danger, "User cannot be found!"); return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var model = new UserVm.Edit() { UserId = user.UserId, UserName = user.Name, UserEnabled = user.Enabled, UserLocked = user.Locked }; var userRoles = TheUserManager.GetRolesForUser(id); var roles = TheRoleManager.GetAllRoles(); var roleDetail = roles.Select(rd => new CheckBoxListItem() { Id = rd.RoleId, Display = rd.Name, IsChecked = userRoles.Any(ur => ur.RoleId == rd.RoleId) }).ToList(); model.Roles = roleDetail; return(View("Edit", model)); }
public ActionResult Create() { var model = new UserVm.Create(); var roles = TheRoleManager.GetAllRoles(); var roleDetail = roles.Select(rd => new CheckBoxListItem() { Id = rd.RoleId, Display = rd.Name, IsChecked = false }).ToList(); model.Roles = roleDetail; return(View("Create", model)); }
public ActionResult Index(string term, int?page) { var model = TheRoleManager.GetAllRoles().Select(x => new RoleVm.Index() { RoleId = x.RoleId, RoleName = x.Name, RoleDescription = x.Description, RoleUserCount = x.UserRoles.Count, RoleLocked = x.Locked, RoleEnabled = x.Enabled }); if (!string.IsNullOrEmpty(term)) { model = model.Where(s => s.RoleName.Contains(term) || s.RoleDescription.Contains(term)); } var pageNo = page ?? 1; var pagedData = model.ToPagedList(pageNo, AppConfig.PageSize); ViewBag.Data = pagedData; return(View("Index", pagedData)); }