public async Task <int> Count(TownFilter townFilter) { IQueryable <TownDAO> townDAOs = context.Town; townDAOs = DynamicFilter(townDAOs, townFilter); return(await townDAOs.CountAsync()); }
public async Task <List <TownDTO> > ListTown([FromBody] TownFilterDTO townFilterDTO) { TownFilter townFilter = new TownFilter { Code = new StringFilter { StartWith = townFilterDTO.Code }, Name = new StringFilter { StartWith = townFilterDTO.Name }, DistrictId = townFilterDTO.DistrictId, Skip = townFilterDTO.Skip, Take = int.MaxValue, OrderBy = TownOrder.Name, OrderType = OrderType.ASC }; var listTown = await TownService.List(townFilter); if (listTown == null) { return(null); } return(listTown.Select(t => new TownDTO { Id = t.Id, Code = t.Code, Name = t.Name, DistrictId = t.DistrictId }).ToList()); }
public async Task <List <Town> > List(TownFilter townFilter) { if (townFilter == null) { return(new List <Town>()); } IQueryable <TownDAO> townDAOs = context.Town; townDAOs = DynamicFilter(townDAOs, townFilter); townDAOs = DynamicOrder(townDAOs, townFilter); var towns = await DynamicSelect(townDAOs); return(towns); }
private IQueryable <TownDAO> DynamicOrder(IQueryable <TownDAO> query, TownFilter townFilter) { switch (townFilter.OrderType) { case OrderType.ASC: switch (townFilter.OrderBy) { case TownOrder.Code: query = query.OrderBy(q => q.Code); break; case TownOrder.Name: query = query.OrderBy(q => q.Name); break; default: query = query.OrderBy(q => q.Id); break; } break; case OrderType.DESC: switch (townFilter.OrderBy) { case TownOrder.Code: query = query.OrderByDescending(q => q.Code); break; case TownOrder.Name: query = query.OrderByDescending(q => q.Name); break; default: query = query.OrderByDescending(q => q.Id); break; } break; default: query = query.OrderBy(q => q.Id); break; } query = query.Skip(townFilter.Skip).Take(townFilter.Take); return(query); }
private IQueryable <TownDAO> DynamicFilter(IQueryable <TownDAO> query, TownFilter townFilter) { if (townFilter == null) { return(query.Where(q => 1 == 0)); } query = query.Where(q => q.DistrictId == townFilter.DistrictId); if (townFilter.Id != null) { query = query.Where(q => q.Id, townFilter.Id); } if (townFilter.Name != null) { query = query.Where(q => q.Name, townFilter.Name); } if (townFilter.Code != null) { query = query.Where(q => q.Code, townFilter.Code); } return(query); }
public async Task <List <Town> > List(TownFilter townFilter) { return(await UOW.TownRepository.List(townFilter)); }