public async Task <int> Count(CooperativeAttitudeFilter filter) { IQueryable <CooperativeAttitudeDAO> CooperativeAttitudes = DataContext.CooperativeAttitude.AsNoTracking(); CooperativeAttitudes = DynamicFilter(CooperativeAttitudes, filter); return(await CooperativeAttitudes.CountAsync()); }
public async Task<List<CooperativeAttitude>> List(CooperativeAttitudeFilter CooperativeAttitudeFilter) { try { List<CooperativeAttitude> CooperativeAttitudes = await UOW.CooperativeAttitudeRepository.List(CooperativeAttitudeFilter); return CooperativeAttitudes; } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CooperativeAttitudeService)); } return null; }
public async Task<int> Count(CooperativeAttitudeFilter CooperativeAttitudeFilter) { try { int result = await UOW.CooperativeAttitudeRepository.Count(CooperativeAttitudeFilter); return result; } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CooperativeAttitudeService)); } return 0; }
public async Task <List <CooperativeAttitude> > List(CooperativeAttitudeFilter filter) { if (filter == null) { return(new List <CooperativeAttitude>()); } IQueryable <CooperativeAttitudeDAO> CooperativeAttitudeDAOs = DataContext.CooperativeAttitude.AsNoTracking(); CooperativeAttitudeDAOs = DynamicFilter(CooperativeAttitudeDAOs, filter); CooperativeAttitudeDAOs = DynamicOrder(CooperativeAttitudeDAOs, filter); List <CooperativeAttitude> CooperativeAttitudes = await DynamicSelect(CooperativeAttitudeDAOs, filter); return(CooperativeAttitudes); }
public async Task <bool> ValidateId(CooperativeAttitude CooperativeAttitude) { CooperativeAttitudeFilter CooperativeAttitudeFilter = new CooperativeAttitudeFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = CooperativeAttitude.Id }, Selects = CooperativeAttitudeSelect.Id }; int count = await UOW.CooperativeAttitudeRepository.Count(CooperativeAttitudeFilter); if (count == 0) { CooperativeAttitude.AddError(nameof(CooperativeAttitudeValidator), nameof(CooperativeAttitude.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <List <Store_CooperativeAttitudeDTO> > SingleListCooperativeAttitude([FromBody] Store_CooperativeAttitudeFilterDTO Store_CooperativeAttitudeFilterDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } CooperativeAttitudeFilter CooperativeAttitudeFilter = new CooperativeAttitudeFilter(); CooperativeAttitudeFilter.Skip = 0; CooperativeAttitudeFilter.Take = int.MaxValue; CooperativeAttitudeFilter.OrderBy = CooperativeAttitudeOrder.Id; CooperativeAttitudeFilter.OrderType = OrderType.ASC; CooperativeAttitudeFilter.Selects = CooperativeAttitudeSelect.ALL; CooperativeAttitudeFilter.Id = Store_CooperativeAttitudeFilterDTO.Id; CooperativeAttitudeFilter.Name = Store_CooperativeAttitudeFilterDTO.Name; List <CooperativeAttitude> CooperativeAttitudes = await CooperativeAttitudeService.List(CooperativeAttitudeFilter); List <Store_CooperativeAttitudeDTO> Store_CooperativeAttitudeDTOs = CooperativeAttitudes .Select(x => new Store_CooperativeAttitudeDTO(x)).ToList(); return(Store_CooperativeAttitudeDTOs); }
private IQueryable <CooperativeAttitudeDAO> DynamicOrder(IQueryable <CooperativeAttitudeDAO> query, CooperativeAttitudeFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case CooperativeAttitudeOrder.Id: query = query.OrderBy(q => q.Id); break; case CooperativeAttitudeOrder.Code: query = query.OrderBy(q => q.Code); break; case CooperativeAttitudeOrder.Name: query = query.OrderBy(q => q.Name); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case CooperativeAttitudeOrder.Id: query = query.OrderByDescending(q => q.Id); break; case CooperativeAttitudeOrder.Code: query = query.OrderByDescending(q => q.Code); break; case CooperativeAttitudeOrder.Name: query = query.OrderByDescending(q => q.Name); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }
private IQueryable <CooperativeAttitudeDAO> OrFilter(IQueryable <CooperativeAttitudeDAO> query, CooperativeAttitudeFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <CooperativeAttitudeDAO> initQuery = query.Where(q => false); foreach (CooperativeAttitudeFilter CooperativeAttitudeFilter in filter.OrFilter) { IQueryable <CooperativeAttitudeDAO> queryable = query; if (CooperativeAttitudeFilter.Id != null && CooperativeAttitudeFilter.Id.HasValue) { queryable = queryable.Where(q => q.Id, CooperativeAttitudeFilter.Id); } if (CooperativeAttitudeFilter.Code != null && CooperativeAttitudeFilter.Code.HasValue) { queryable = queryable.Where(q => q.Code, CooperativeAttitudeFilter.Code); } if (CooperativeAttitudeFilter.Name != null && CooperativeAttitudeFilter.Name.HasValue) { queryable = queryable.Where(q => q.Name, CooperativeAttitudeFilter.Name); } initQuery = initQuery.Union(queryable); } return(initQuery); }
private IQueryable <CooperativeAttitudeDAO> DynamicFilter(IQueryable <CooperativeAttitudeDAO> query, CooperativeAttitudeFilter 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 <CooperativeAttitude> > DynamicSelect(IQueryable <CooperativeAttitudeDAO> query, CooperativeAttitudeFilter filter) { List <CooperativeAttitude> CooperativeAttitudes = await query.Select(q => new CooperativeAttitude() { Id = filter.Selects.Contains(CooperativeAttitudeSelect.Id) ? q.Id : default(long), Code = filter.Selects.Contains(CooperativeAttitudeSelect.Code) ? q.Code : default(string), Name = filter.Selects.Contains(CooperativeAttitudeSelect.Name) ? q.Name : default(string), }).ToListAsync(); return(CooperativeAttitudes); }