public QueryResults QueryDatabase <T>(int count = 20, int page = 0, string text = "") where T : KeyedObject { IKeyedObjectRepository <T> repository = this.ServiceProvider.GetService <IKeyedObjectRepository <T> >(); IQueryable <T> results = repository.OrderByDescending(i => i._Id).Skip(page * count).Take(count); int totalCount = 0; if (!string.IsNullOrWhiteSpace(text)) { results = results.Where(ExpressionBuilder.AnyPropertyContains <T>(text)); //totalCount = repository.Where(ExpressionBuilder.AnyPropertyContains<T>(text)).Count(); } else { repository.Count(); } ISecurityProvider <T> securityProvider = this.ServiceProvider.GetService <ISecurityProvider <T> >(); List <T> ResultsList = results.ToList(); if (securityProvider != null && !this.UserSession.LoggedInUser.HasRole(RoleNames.SYS_ADMIN)) { ResultsList = ResultsList.Where(r => securityProvider.CheckAccess(r)).ToList(); } return(new QueryResults() { Results = ResultsList, TotalCount = totalCount }); }
/// <summary> /// Checks the entity for specified permissions against the current session user if the provider is not null /// </summary> /// <param name="provider">The provider to use try and use for this check</param> /// <param name="entity">The entity to check</param> /// <param name="permissionTypes">The specific permissions to check for</param> /// <returns>True if the access type requested is allowed</returns> public static bool TryCheckAccess <T>(this ISecurityProvider <T> provider, T entity, PermissionTypes permissionTypes = PermissionTypes.Read) { if (provider is null) { return(true); } return(provider.CheckAccess(entity, permissionTypes)); }