public async Task <int> Count(ConsultingServiceFilter filter) { IQueryable <ConsultingServiceDAO> ConsultingServices = DataContext.ConsultingService.AsNoTracking(); ConsultingServices = DynamicFilter(ConsultingServices, filter); return(await ConsultingServices.CountAsync()); }
public async Task <List <ConsultingService> > List(ConsultingServiceFilter ConsultingServiceFilter) { try { List <ConsultingService> ConsultingServices = await UOW.ConsultingServiceRepository.List(ConsultingServiceFilter); return(ConsultingServices); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(ConsultingServiceService)); } return(null); }
public async Task <int> Count(ConsultingServiceFilter ConsultingServiceFilter) { try { int result = await UOW.ConsultingServiceRepository.Count(ConsultingServiceFilter); return(result); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(ConsultingServiceService)); } return(0); }
public async Task <List <ConsultingService> > List(ConsultingServiceFilter filter) { if (filter == null) { return(new List <ConsultingService>()); } IQueryable <ConsultingServiceDAO> ConsultingServiceDAOs = DataContext.ConsultingService.AsNoTracking(); ConsultingServiceDAOs = DynamicFilter(ConsultingServiceDAOs, filter); ConsultingServiceDAOs = DynamicOrder(ConsultingServiceDAOs, filter); List <ConsultingService> ConsultingServices = await DynamicSelect(ConsultingServiceDAOs, filter); return(ConsultingServices); }
public async Task <bool> ValidateId(ConsultingService ConsultingService) { ConsultingServiceFilter ConsultingServiceFilter = new ConsultingServiceFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = ConsultingService.Id }, Selects = ConsultingServiceSelect.Id }; int count = await UOW.ConsultingServiceRepository.Count(ConsultingServiceFilter); if (count == 0) { ConsultingService.AddError(nameof(ConsultingServiceValidator), nameof(ConsultingService.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <List <Store_ConsultingServiceDTO> > SingleListConsultingService([FromBody] Store_ConsultingServiceFilterDTO Store_ConsultingServiceFilterDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } ConsultingServiceFilter ConsultingServiceFilter = new ConsultingServiceFilter(); ConsultingServiceFilter.Skip = 0; ConsultingServiceFilter.Take = int.MaxValue; ConsultingServiceFilter.OrderBy = ConsultingServiceOrder.Id; ConsultingServiceFilter.OrderType = OrderType.ASC; ConsultingServiceFilter.Selects = ConsultingServiceSelect.ALL; ConsultingServiceFilter.Id = Store_ConsultingServiceFilterDTO.Id; ConsultingServiceFilter.Name = Store_ConsultingServiceFilterDTO.Name; List <ConsultingService> ConsultingServices = await ConsultingServiceService.List(ConsultingServiceFilter); List <Store_ConsultingServiceDTO> Store_ConsultingServiceDTOs = ConsultingServices .Select(x => new Store_ConsultingServiceDTO(x)).ToList(); return(Store_ConsultingServiceDTOs); }
private IQueryable <ConsultingServiceDAO> DynamicOrder(IQueryable <ConsultingServiceDAO> query, ConsultingServiceFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case ConsultingServiceOrder.Id: query = query.OrderBy(q => q.Id); break; case ConsultingServiceOrder.Code: query = query.OrderBy(q => q.Code); break; case ConsultingServiceOrder.Name: query = query.OrderBy(q => q.Name); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case ConsultingServiceOrder.Id: query = query.OrderByDescending(q => q.Id); break; case ConsultingServiceOrder.Code: query = query.OrderByDescending(q => q.Code); break; case ConsultingServiceOrder.Name: query = query.OrderByDescending(q => q.Name); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }
private IQueryable <ConsultingServiceDAO> OrFilter(IQueryable <ConsultingServiceDAO> query, ConsultingServiceFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <ConsultingServiceDAO> initQuery = query.Where(q => false); foreach (ConsultingServiceFilter ConsultingServiceFilter in filter.OrFilter) { IQueryable <ConsultingServiceDAO> queryable = query; if (ConsultingServiceFilter.Id != null && ConsultingServiceFilter.Id.HasValue) { queryable = queryable.Where(q => q.Id, ConsultingServiceFilter.Id); } if (ConsultingServiceFilter.Code != null && ConsultingServiceFilter.Code.HasValue) { queryable = queryable.Where(q => q.Code, ConsultingServiceFilter.Code); } if (ConsultingServiceFilter.Name != null && ConsultingServiceFilter.Name.HasValue) { queryable = queryable.Where(q => q.Name, ConsultingServiceFilter.Name); } initQuery = initQuery.Union(queryable); } return(initQuery); }
private IQueryable <ConsultingServiceDAO> DynamicFilter(IQueryable <ConsultingServiceDAO> query, ConsultingServiceFilter 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 <ConsultingService> > DynamicSelect(IQueryable <ConsultingServiceDAO> query, ConsultingServiceFilter filter) { List <ConsultingService> ConsultingServices = await query.Select(q => new ConsultingService() { Id = filter.Selects.Contains(ConsultingServiceSelect.Id) ? q.Id : default(long), Code = filter.Selects.Contains(ConsultingServiceSelect.Code) ? q.Code : default(string), Name = filter.Selects.Contains(ConsultingServiceSelect.Name) ? q.Name : default(string), }).ToListAsync(); return(ConsultingServices); }