/// <summary> /// Get permissions for roles other than those specially treated in this class /// </summary> /// <param name="category"></param> /// <param name="role"></param> /// <returns></returns> private PermissionSet GetOtherPermissions(Category category, MembershipRole role) { // Get all permissions var permissionList = _permissionRepository.GetAll(); // Get the known permissions for this role and category var categoryRow = _categoryPermissionForRoleRepository.GetCategoryRow(role, category); var categoryRowPermissions = categoryRow.ToDictionary(catRow => catRow.Permission); // Load up the results with the permisions for this role / cartegory. A null entry for a permissions results in a new // record with a false value var permissions = new List <CategoryPermissionForRole>(); foreach (var permission in permissionList) { permissions.Add(categoryRowPermissions.ContainsKey(permission) ? categoryRowPermissions[permission] : new CategoryPermissionForRole { Category = category, MembershipRole = role, IsTicked = false, Permission = permission }); } var permissionSet = new PermissionSet(permissions); return(permissionSet); }
/// <summary> /// Get permissions for roles other than those specially treated in this class /// </summary> /// <param name="category"></param> /// <param name="role"></param> /// <returns></returns> private PermissionSet GetOtherPermissions(Category category, MembershipRole role) { // Get all permissions var permissionList = _permissionRepository.GetAll().ToList(); var categoryPermissions = new List <CategoryPermissionForRole>(); if (category != null) { // Get the known permissions for this role and category var categoryRow = _categoryPermissionForRoleRepository.GetCategoryRow(role, category); var categoryRowPermissions = categoryRow.ToDictionary(catRow => catRow.Permission); // Load up the results with the permisions for this role / cartegory. A null entry for a permissions results in a new // record with a false value foreach (var permission in permissionList.Where(x => !x.IsGlobal)) { categoryPermissions.Add(categoryRowPermissions.ContainsKey(permission) ? categoryRowPermissions[permission] : new CategoryPermissionForRole { Category = category, MembershipRole = role, IsTicked = false, Permission = permission }); } } // Sort the global permissions out - As it's a guest we set everything to false var globalPermissions = new List <GlobalPermissionForRole>(); // Get the known global permissions for this role var globalRow = _globalPermissionForRoleRepository.GetAll(role); var globalRowPermissions = globalRow.ToDictionary(row => row.Permission); // Load up the results with the permisions for this role. A null entry for a permissions results in a new // record with a false value foreach (var permission in permissionList.Where(x => x.IsGlobal)) { globalPermissions.Add(globalRowPermissions.ContainsKey(permission) ? globalRowPermissions[permission] : new GlobalPermissionForRole { MembershipRole = role, IsTicked = false, Permission = permission }); } return(new PermissionSet(categoryPermissions, globalPermissions)); }
/// <summary> /// Returns a row with the permission and CPFR /// </summary> /// <param name="role"></param> /// <param name="cat"></param> /// <returns></returns> public Dictionary <Permission, CategoryPermissionForRole> GetCategoryRow(MembershipRole role, Category cat) { var catRowList = _categoryPermissionForRoleService.GetCategoryRow(role, cat); return(catRowList.ToDictionary(catRow => catRow.Permission)); }