public static IList<Catalog> LimitToAdministeredBy(this IList<Catalog> catalogs, User user) { if (user.IsSuperAdmin()) { return catalogs; } else { var adminCatalogIds = user.UserCatalogRoles.Where(x => x.RoleId <= (int)Roles.Admin).Select(x => x.CatalogId); return catalogs.Where(c => adminCatalogIds.Contains(c.CatalogId)).ToList(); } // return catalogs.Where(c => c.UserCatalogRoles.Any(x => x.UserId == user.UserId && x.RoleId <= (int)Roles.Admin)).ToList(); }
// ************************************** // IsAvailableTo // ************************************** public static bool IsAvailableTo(this Content content, User user) { if (content == null) { return false; } if (user.IsSuperAdmin()) { return true; } else if (user.UserCatalogRoles != null && user.UserCatalogRoles.AsParallel().Any(x => x.CatalogId == content.CatalogId)) { return true; } else { return false; } }