public async Task <int> Count(CompanyFileGroupingFilter filter) { IQueryable <CompanyFileGroupingDAO> CompanyFileGroupings = DataContext.CompanyFileGrouping.AsNoTracking(); CompanyFileGroupings = DynamicFilter(CompanyFileGroupings, filter); return(await CompanyFileGroupings.CountAsync()); }
public async Task <List <CompanyFileGrouping> > List(CompanyFileGroupingFilter filter) { if (filter == null) { return(new List <CompanyFileGrouping>()); } IQueryable <CompanyFileGroupingDAO> CompanyFileGroupingDAOs = DataContext.CompanyFileGrouping.AsNoTracking(); CompanyFileGroupingDAOs = DynamicFilter(CompanyFileGroupingDAOs, filter); CompanyFileGroupingDAOs = DynamicOrder(CompanyFileGroupingDAOs, filter); List <CompanyFileGrouping> CompanyFileGroupings = await DynamicSelect(CompanyFileGroupingDAOs, filter); return(CompanyFileGroupings); }
private IQueryable <CompanyFileGroupingDAO> OrFilter(IQueryable <CompanyFileGroupingDAO> query, CompanyFileGroupingFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <CompanyFileGroupingDAO> initQuery = query.Where(q => false); foreach (CompanyFileGroupingFilter CompanyFileGroupingFilter in filter.OrFilter) { IQueryable <CompanyFileGroupingDAO> queryable = query; if (CompanyFileGroupingFilter.Id != null && CompanyFileGroupingFilter.Id.HasValue) { queryable = queryable.Where(q => q.Id, CompanyFileGroupingFilter.Id); } if (CompanyFileGroupingFilter.Title != null && CompanyFileGroupingFilter.Title.HasValue) { queryable = queryable.Where(q => q.Title, CompanyFileGroupingFilter.Title); } if (CompanyFileGroupingFilter.Description != null && CompanyFileGroupingFilter.Description.HasValue) { queryable = queryable.Where(q => q.Description, CompanyFileGroupingFilter.Description); } if (CompanyFileGroupingFilter.CompanyId != null && CompanyFileGroupingFilter.CompanyId.HasValue) { queryable = queryable.Where(q => q.CompanyId, CompanyFileGroupingFilter.CompanyId); } if (CompanyFileGroupingFilter.CreatorId != null && CompanyFileGroupingFilter.CreatorId.HasValue) { queryable = queryable.Where(q => q.CreatorId, CompanyFileGroupingFilter.CreatorId); } if (CompanyFileGroupingFilter.FileTypeId != null && CompanyFileGroupingFilter.FileTypeId.HasValue) { queryable = queryable.Where(q => q.FileTypeId, CompanyFileGroupingFilter.FileTypeId); } initQuery = initQuery.Union(queryable); } return(initQuery); }
private IQueryable <CompanyFileGroupingDAO> DynamicFilter(IQueryable <CompanyFileGroupingDAO> query, CompanyFileGroupingFilter filter) { if (filter == null) { return(query.Where(q => false)); } query = query.Where(q => !q.DeletedAt.HasValue); if (filter.CreatedAt != null && filter.CreatedAt.HasValue) { query = query.Where(q => q.CreatedAt, filter.CreatedAt); } if (filter.UpdatedAt != null && filter.UpdatedAt.HasValue) { query = query.Where(q => q.UpdatedAt, filter.UpdatedAt); } if (filter.Id != null && filter.Id.HasValue) { query = query.Where(q => q.Id, filter.Id); } if (filter.Title != null && filter.Title.HasValue) { query = query.Where(q => q.Title, filter.Title); } if (filter.Description != null && filter.Description.HasValue) { query = query.Where(q => q.Description, filter.Description); } if (filter.CompanyId != null && filter.CompanyId.HasValue) { query = query.Where(q => q.CompanyId, filter.CompanyId); } if (filter.CreatorId != null && filter.CreatorId.HasValue) { query = query.Where(q => q.CreatorId, filter.CreatorId); } if (filter.FileTypeId != null && filter.FileTypeId.HasValue) { query = query.Where(q => q.FileTypeId, filter.FileTypeId); } query = OrFilter(query, filter); return(query); }
private async Task <List <CompanyFileGrouping> > DynamicSelect(IQueryable <CompanyFileGroupingDAO> query, CompanyFileGroupingFilter filter) { List <CompanyFileGrouping> CompanyFileGroupings = await query.Select(q => new CompanyFileGrouping() { Id = filter.Selects.Contains(CompanyFileGroupingSelect.Id) ? q.Id : default(long), Title = filter.Selects.Contains(CompanyFileGroupingSelect.Title) ? q.Title : default(string), Description = filter.Selects.Contains(CompanyFileGroupingSelect.Description) ? q.Description : default(string), CompanyId = filter.Selects.Contains(CompanyFileGroupingSelect.Company) ? q.CompanyId : default(long), CreatorId = filter.Selects.Contains(CompanyFileGroupingSelect.Creator) ? q.CreatorId : default(long), FileTypeId = filter.Selects.Contains(CompanyFileGroupingSelect.FileType) ? q.FileTypeId : default(long), Company = filter.Selects.Contains(CompanyFileGroupingSelect.Company) && q.Company != null ? new Company { Id = q.Company.Id, Name = q.Company.Name, Phone = q.Company.Phone, FAX = q.Company.FAX, PhoneOther = q.Company.PhoneOther, Email = q.Company.Email, EmailOther = q.Company.EmailOther, ZIPCode = q.Company.ZIPCode, Revenue = q.Company.Revenue, Website = q.Company.Website, Address = q.Company.Address, NationId = q.Company.NationId, ProvinceId = q.Company.ProvinceId, DistrictId = q.Company.DistrictId, NumberOfEmployee = q.Company.NumberOfEmployee, RefuseReciveEmail = q.Company.RefuseReciveEmail, RefuseReciveSMS = q.Company.RefuseReciveSMS, CustomerLeadId = q.Company.CustomerLeadId, ParentId = q.Company.ParentId, Path = q.Company.Path, Level = q.Company.Level, ProfessionId = q.Company.ProfessionId, AppUserId = q.Company.AppUserId, CreatorId = q.Company.CreatorId, CurrencyId = q.Company.CurrencyId, CompanyStatusId = q.Company.CompanyStatusId, Description = q.Company.Description, RowId = q.Company.RowId, } : null, Creator = filter.Selects.Contains(CompanyFileGroupingSelect.Creator) && q.Creator != null ? new AppUser { Id = q.Creator.Id, Username = q.Creator.Username, DisplayName = q.Creator.DisplayName, Address = q.Creator.Address, Email = q.Creator.Email, Phone = q.Creator.Phone, SexId = q.Creator.SexId, Birthday = q.Creator.Birthday, Avatar = q.Creator.Avatar, Department = q.Creator.Department, OrganizationId = q.Creator.OrganizationId, Longitude = q.Creator.Longitude, Latitude = q.Creator.Latitude, StatusId = q.Creator.StatusId, RowId = q.Creator.RowId, Used = q.Creator.Used, } : null, FileType = filter.Selects.Contains(CompanyFileGroupingSelect.FileType) && q.FileType != null ? new FileType { Id = q.FileType.Id, Code = q.FileType.Code, Name = q.FileType.Name, } : null, }).ToListAsync(); return(CompanyFileGroupings); }
private IQueryable <CompanyFileGroupingDAO> DynamicOrder(IQueryable <CompanyFileGroupingDAO> query, CompanyFileGroupingFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case CompanyFileGroupingOrder.Id: query = query.OrderBy(q => q.Id); break; case CompanyFileGroupingOrder.Title: query = query.OrderBy(q => q.Title); break; case CompanyFileGroupingOrder.Description: query = query.OrderBy(q => q.Description); break; case CompanyFileGroupingOrder.Company: query = query.OrderBy(q => q.CompanyId); break; case CompanyFileGroupingOrder.Creator: query = query.OrderBy(q => q.CreatorId); break; case CompanyFileGroupingOrder.FileType: query = query.OrderBy(q => q.FileTypeId); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case CompanyFileGroupingOrder.Id: query = query.OrderByDescending(q => q.Id); break; case CompanyFileGroupingOrder.Title: query = query.OrderByDescending(q => q.Title); break; case CompanyFileGroupingOrder.Description: query = query.OrderByDescending(q => q.Description); break; case CompanyFileGroupingOrder.Company: query = query.OrderByDescending(q => q.CompanyId); break; case CompanyFileGroupingOrder.Creator: query = query.OrderByDescending(q => q.CreatorId); break; case CompanyFileGroupingOrder.FileType: query = query.OrderByDescending(q => q.FileTypeId); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }