public RightsManagementViewModel Get([FromUri] RightsManagementRequest request) { if (request == null || !ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } UserMenuResponse response = menuRightsService.GetRoleMenuRights(request.RoleId); RightsManagementViewModel rightsManagementViewModel = new RightsManagementViewModel { Roles = response.Roles != null?response.Roles.Select(role => new UserRole { Id = role.Id, Name = role.Name }).ToList() : new List <UserRole>(), Rights = response.Menus.Select( m => new Models.MenuRight { MenuId = m.MenuId, MenuTitle = m.MenuTitle, IsParent = m.IsRootItem, IsSelected = response.MenuRights.Any( menu => menu.Menu.MenuId == m.MenuId), ParentId = m.ParentItem_MenuId }).ToList(), SelectedRoleId = string.IsNullOrEmpty(request.RoleId) && (response.Roles != null && response.Roles.Any()) ? response.Roles[0].Id : request.RoleId }; return(rightsManagementViewModel); }
public ActionResult RightsManagement() { UserMenuResponse userMenuRights = menuRightsService.GetRoleMenuRights(string.Empty); RightsManagementViewModel viewModel = new RightsManagementViewModel(); viewModel.Roles = userMenuRights.Roles.Where(role => role.Name != "SystemAdministrator").ToList(); viewModel.Rights = userMenuRights.Menus.Select( m => new MenuRightModel { MenuId = m.MenuId, MenuTitle = m.MenuTitle, IsParent = m.IsRootItem, IsSelected = userMenuRights.MenuRights.Any(menu => menu.Menu.MenuId == m.MenuId), //ParentId = m.ParentItem != null ? m.ParentItem.MenuId : (int?)null }).ToList(); return(View(viewModel)); }
//[SiteAuthorize(PermissionKey = "RightsManagement")] public ActionResult RightsManagement() { UserMenuResponse userMenuRights = menuRightsService.GetRoleMenuRights(string.Empty); RightsManagementViewModel viewModel = new RightsManagementViewModel(); var roles = Session["RoleName"].ToString().ToLower() == "superadmin" ? userMenuRights.Roles.ToList() : userMenuRights.Roles.Where(x => x.Name != "SuperAdmin").ToList(); viewModel.Roles = roles; viewModel.Rights = userMenuRights.Menus.Select( m => new Rights { MenuId = m.MenuId, MenuTitle = m.MenuTitle, IsParent = m.IsRootItem, IsSelected = userMenuRights.MenuRights.Any(menu => menu.Menu.MenuId == m.MenuId), ParentId = m.ParentItem != null ? m.ParentItem.MenuId : (int?)null }).ToList(); ViewBag.MessageVM = TempData["message"] as MessageViewModel; return(View(viewModel)); }