public async Task <int> Count(CustomerLeadSourceFilter filter) { IQueryable <CustomerLeadSourceDAO> CustomerLeadSources = DataContext.CustomerLeadSource.AsNoTracking(); CustomerLeadSources = DynamicFilter(CustomerLeadSources, filter); return(await CustomerLeadSources.CountAsync()); }
public async Task <ActionResult <List <CustomerLeadReport_CustomerLeadSourceDTO> > > FilterListCustomerLeadSource([FromBody] CustomerLeadReport_CustomerLeadSourceFilterDTO CustomerLeadReport_CustomerLeadSourceFilterDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } CustomerLeadSourceFilter CustomerLeadSourceFilter = new CustomerLeadSourceFilter(); CustomerLeadSourceFilter.Skip = 0; CustomerLeadSourceFilter.Take = 20; CustomerLeadSourceFilter.OrderBy = CustomerLeadSourceOrder.Id; CustomerLeadSourceFilter.OrderType = OrderType.ASC; CustomerLeadSourceFilter.Selects = CustomerLeadSourceSelect.ALL; CustomerLeadSourceFilter.Id = CustomerLeadReport_CustomerLeadSourceFilterDTO.Id; CustomerLeadSourceFilter.Code = CustomerLeadReport_CustomerLeadSourceFilterDTO.Code; CustomerLeadSourceFilter.Name = CustomerLeadReport_CustomerLeadSourceFilterDTO.Name; List <CustomerLeadSource> CustomerLeadSources = await CustomerLeadSourceService.List(CustomerLeadSourceFilter); List <CustomerLeadReport_CustomerLeadSourceDTO> CustomerLeadReport_CustomerLeadSourceDTOs = CustomerLeadSources .Select(x => new CustomerLeadReport_CustomerLeadSourceDTO(x)).ToList(); return(CustomerLeadReport_CustomerLeadSourceDTOs); }
public async Task <List <CustomerLeadSource> > List(CustomerLeadSourceFilter CustomerLeadSourceFilter) { try { List <CustomerLeadSource> CustomerLeadSources = await UOW.CustomerLeadSourceRepository.List(CustomerLeadSourceFilter); return(CustomerLeadSources); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CustomerLeadSourceService)); } return(null); }
public async Task <int> Count(CustomerLeadSourceFilter CustomerLeadSourceFilter) { try { int result = await UOW.CustomerLeadSourceRepository.Count(CustomerLeadSourceFilter); return(result); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CustomerLeadSourceService)); } return(0); }
public async Task <List <CustomerLeadSource> > List(CustomerLeadSourceFilter filter) { if (filter == null) { return(new List <CustomerLeadSource>()); } IQueryable <CustomerLeadSourceDAO> CustomerLeadSourceDAOs = DataContext.CustomerLeadSource.AsNoTracking(); CustomerLeadSourceDAOs = DynamicFilter(CustomerLeadSourceDAOs, filter); CustomerLeadSourceDAOs = DynamicOrder(CustomerLeadSourceDAOs, filter); List <CustomerLeadSource> CustomerLeadSources = await DynamicSelect(CustomerLeadSourceDAOs, filter); return(CustomerLeadSources); }
public async Task <bool> ValidateId(CustomerLeadSource CustomerLeadSource) { CustomerLeadSourceFilter CustomerLeadSourceFilter = new CustomerLeadSourceFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = CustomerLeadSource.Id }, Selects = CustomerLeadSourceSelect.Id }; int count = await UOW.CustomerLeadSourceRepository.Count(CustomerLeadSourceFilter); if (count == 0) { CustomerLeadSource.AddError(nameof(CustomerLeadSourceValidator), nameof(CustomerLeadSource.Id), ErrorCode.IdNotExisted); } return(count == 1); }
private IQueryable <CustomerLeadSourceDAO> DynamicOrder(IQueryable <CustomerLeadSourceDAO> query, CustomerLeadSourceFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case CustomerLeadSourceOrder.Id: query = query.OrderBy(q => q.Id); break; case CustomerLeadSourceOrder.Code: query = query.OrderBy(q => q.Code); break; case CustomerLeadSourceOrder.Name: query = query.OrderBy(q => q.Name); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case CustomerLeadSourceOrder.Id: query = query.OrderByDescending(q => q.Id); break; case CustomerLeadSourceOrder.Code: query = query.OrderByDescending(q => q.Code); break; case CustomerLeadSourceOrder.Name: query = query.OrderByDescending(q => q.Name); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }
private IQueryable <CustomerLeadSourceDAO> OrFilter(IQueryable <CustomerLeadSourceDAO> query, CustomerLeadSourceFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <CustomerLeadSourceDAO> initQuery = query.Where(q => false); foreach (CustomerLeadSourceFilter CustomerLeadSourceFilter in filter.OrFilter) { IQueryable <CustomerLeadSourceDAO> queryable = query; if (CustomerLeadSourceFilter.Id != null && CustomerLeadSourceFilter.Id.HasValue) { queryable = queryable.Where(q => q.Id, CustomerLeadSourceFilter.Id); } if (CustomerLeadSourceFilter.Code != null && CustomerLeadSourceFilter.Code.HasValue) { queryable = queryable.Where(q => q.Code, CustomerLeadSourceFilter.Code); } if (CustomerLeadSourceFilter.Name != null && CustomerLeadSourceFilter.Name.HasValue) { queryable = queryable.Where(q => q.Name, CustomerLeadSourceFilter.Name); } initQuery = initQuery.Union(queryable); } return(initQuery); }
private IQueryable <CustomerLeadSourceDAO> DynamicFilter(IQueryable <CustomerLeadSourceDAO> query, CustomerLeadSourceFilter filter) { if (filter == null) { return(query.Where(q => false)); } if (filter.Id != null && filter.Id.HasValue) { query = query.Where(q => q.Id, filter.Id); } if (filter.Code != null && filter.Code.HasValue) { query = query.Where(q => q.Code, filter.Code); } if (filter.Name != null && filter.Name.HasValue) { query = query.Where(q => q.Name, filter.Name); } query = OrFilter(query, filter); return(query); }
private async Task <List <CustomerLeadSource> > DynamicSelect(IQueryable <CustomerLeadSourceDAO> query, CustomerLeadSourceFilter filter) { List <CustomerLeadSource> CustomerLeadSources = await query.Select(q => new CustomerLeadSource() { Id = filter.Selects.Contains(CustomerLeadSourceSelect.Id) ? q.Id : default(long), Code = filter.Selects.Contains(CustomerLeadSourceSelect.Code) ? q.Code : default(string), Name = filter.Selects.Contains(CustomerLeadSourceSelect.Name) ? q.Name : default(string), }).ToListAsync(); return(CustomerLeadSources); }