public async Task <PagedResultOutput <EditorDocument> > GetAll(GetAllDocumentsInput input) { var tagNames = input?.TagFilter ?? new List <string>(); var filteredUsers = await _userService.GetUsersByUserName(input?.UserName); var filteredUserIds = filteredUsers.Select(u => u.Id).ToList(); var query = Repository .Include(d => d.Tags) .Where(r => r.DocumentAccess == EditorDocumentAllowedAccess.Public) .WhereIf(!string.IsNullOrEmpty(input?.Filter), r => r.Title.Contains(input.Filter) || r.Description.Contains(input.Filter)) .WhereIf(tagNames.Any(), d => d.Tags.Any(t => tagNames.Contains(t.TagName))) .WhereIf(input?.StartDate != null, d => d.LastUpdateTime != null ? d.LastUpdateTime >= input.StartDate : d.CreationTime >= input.StartDate) .WhereIf(input?.EndDate != null, d => d.LastUpdateTime != null ? d.LastUpdateTime <= input.EndDate : d.CreationTime <= input.EndDate) .WhereIf(!string.IsNullOrEmpty(input?.UserName), u => filteredUserIds.Contains(u.UserId)); // TODO Rate Filter var totalCount = await query.CountAsync(); query = input == null || input.Order == "asc" ? query.OrderBy(document => document.Title) : query.OrderByDescending(document => document.Title); var items = await query .Skip(input?.SkipCount ?? 0) .Take(input?.PageSize ?? 20) .ToListAsync(); return(new PagedResultOutput <EditorDocument>(items, totalCount)); }
public async Task <PagedResultDto <GetDocumentForViewDto> > GetDocuments(GetAllDocumentsInput input) { var filteredDocuments = _documentRepository.GetAll() .Include(e => e.SysRefFk) .Include(e => e.ProductFk) .Include(e => e.ServiceFk) .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Url.Contains(input.Filter) || e.Name.Contains(input.Filter) || e.Description.Contains(input.Filter)) .WhereIf(!string.IsNullOrWhiteSpace(input.UrlFilter), e => e.Url == input.UrlFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.NameFilter), e => e.Name == input.NameFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.DescriptionFilter), e => e.Description == input.DescriptionFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.ProductNameFilter), e => e.ProductFk != null && e.ProductFk.Name == input.ProductNameFilter) .WhereIf(!string.IsNullOrWhiteSpace(input.ServiceNameFilter), e => e.ServiceFk != null && e.ServiceFk.Name == input.ServiceNameFilter) .WhereIf(input.ProductIdFilter != 0, e => e.ProductFk != null && e.ProductId == input.ProductIdFilter) .WhereIf(input.ServiceIdFilter != 0, e => e.ServiceFk != null && e.ServiceId == input.ServiceIdFilter); var pagedAndFilteredDocuments = filteredDocuments .OrderBy(input.Sorting ?? "Name asc") .PageBy(input); var documents = from o in pagedAndFilteredDocuments join o1 in _lookup_sysRefRepository.GetAll() on o.SysRefId equals o1.Id into j1 from s1 in j1.DefaultIfEmpty() join o2 in _lookup_productRepository.GetAll() on o.ProductId equals o2.Id into j2 from s2 in j2.DefaultIfEmpty() join o3 in _lookup_serviceRepository.GetAll() on o.ServiceId equals o3.Id into j3 from s3 in j3.DefaultIfEmpty() select new GetDocumentForViewDto() { Document = new DocumentDto { Url = o.Url, Name = o.Name, Description = o.Description, Id = o.Id, ImageBase64String = Convert.ToBase64String(o.Bytes) }, SysRefTenantId = s1 == null ? "" : s1.TenantId.ToString(), ProductName = s2 == null ? "" : s2.Name.ToString(), ServiceName = s3 == null ? "" : s3.Name.ToString() }; var totalCount = await filteredDocuments.CountAsync(); return(new PagedResultDto <GetDocumentForViewDto>( totalCount, await documents.ToListAsync() )); }