public async Task <ActionResult <List <KpiGeneralEmployeeReport_KpiYearDTO> > > FilterListKpiYear([FromBody] KpiGeneralEmployeeReport_KpiYearFilterDTO KpiGeneralEmployeeReport_KpiYearFilterDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } KpiYearFilter KpiYearFilter = new KpiYearFilter(); KpiYearFilter.Skip = 0; KpiYearFilter.Take = 20; KpiYearFilter.OrderBy = KpiYearOrder.Id; KpiYearFilter.OrderType = OrderType.ASC; KpiYearFilter.Selects = KpiYearSelect.ALL; KpiYearFilter.Id = KpiGeneralEmployeeReport_KpiYearFilterDTO.Id; KpiYearFilter.Code = KpiGeneralEmployeeReport_KpiYearFilterDTO.Code; KpiYearFilter.Name = KpiGeneralEmployeeReport_KpiYearFilterDTO.Name; List <KpiYear> KpiYears = await KpiYearService.List(KpiYearFilter); List <KpiGeneralEmployeeReport_KpiYearDTO> KpiGeneralEmployeeReport_KpiYearDTOs = KpiYears .Select(x => new KpiGeneralEmployeeReport_KpiYearDTO(x)).ToList(); return(KpiGeneralEmployeeReport_KpiYearDTOs); }
private IQueryable <KpiYearDAO> OrFilter(IQueryable <KpiYearDAO> query, KpiYearFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <KpiYearDAO> initQuery = query.Where(q => false); foreach (KpiYearFilter KpiYearFilter in filter.OrFilter) { IQueryable <KpiYearDAO> queryable = query; if (KpiYearFilter.Id != null && KpiYearFilter.Id.HasValue) { queryable = queryable.Where(q => q.Id, KpiYearFilter.Id); } if (KpiYearFilter.Code != null && KpiYearFilter.Code.HasValue) { queryable = queryable.Where(q => q.Code, KpiYearFilter.Code); } if (KpiYearFilter.Name != null && KpiYearFilter.Name.HasValue) { queryable = queryable.Where(q => q.Name, KpiYearFilter.Name); } initQuery = initQuery.Union(queryable); } return(initQuery); }
public async Task <int> Count(KpiYearFilter filter) { IQueryable <KpiYearDAO> KpiYears = DataContext.KpiYear.AsNoTracking(); KpiYears = DynamicFilter(KpiYears, filter); return(await KpiYears.CountAsync()); }
public async Task <List <KpiYear> > List(KpiYearFilter filter) { if (filter == null) { return(new List <KpiYear>()); } IQueryable <KpiYearDAO> KpiYearDAOs = DataContext.KpiYear.AsNoTracking(); KpiYearDAOs = DynamicFilter(KpiYearDAOs, filter); KpiYearDAOs = DynamicOrder(KpiYearDAOs, filter); List <KpiYear> KpiYears = await DynamicSelect(KpiYearDAOs, filter); return(KpiYears); }
public async Task <List <KpiYear> > List(KpiYearFilter KpiYearFilter) { try { List <KpiYear> KpiYears = await UOW.KpiYearRepository.List(KpiYearFilter); return(KpiYears); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(KpiYearService)); } return(null); }
public async Task <int> Count(KpiYearFilter KpiYearFilter) { try { int result = await UOW.KpiYearRepository.Count(KpiYearFilter); return(result); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(KpiYearService)); } return(0); }
private async Task <bool> ValidateKpiYear(KpiItem KpiItem) { KpiYearFilter KpiYearFilter = new KpiYearFilter { Id = new IdFilter { Equal = KpiItem.KpiYearId } }; int count = await UOW.KpiYearRepository.Count(KpiYearFilter); if (count == 0) { KpiItem.AddError(nameof(KpiItemValidator), nameof(KpiItem.KpiYear), ErrorCode.KpiYearIdNotExisted); } return(KpiItem.IsValidated); }
public async Task <bool> ValidateId(KpiYear KpiYear) { KpiYearFilter KpiYearFilter = new KpiYearFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = KpiYear.Id }, Selects = KpiYearSelect.Id }; int count = await UOW.KpiYearRepository.Count(KpiYearFilter); if (count == 0) { KpiYear.AddError(nameof(KpiYearValidator), nameof(KpiYear.Id), ErrorCode.IdNotExisted); } return(count == 1); }
private IQueryable <KpiYearDAO> DynamicOrder(IQueryable <KpiYearDAO> query, KpiYearFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case KpiYearOrder.Id: query = query.OrderBy(q => q.Id); break; case KpiYearOrder.Code: query = query.OrderBy(q => q.Code); break; case KpiYearOrder.Name: query = query.OrderBy(q => q.Name); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case KpiYearOrder.Id: query = query.OrderByDescending(q => q.Id); break; case KpiYearOrder.Code: query = query.OrderByDescending(q => q.Code); break; case KpiYearOrder.Name: query = query.OrderByDescending(q => q.Name); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }
private IQueryable <KpiYearDAO> DynamicFilter(IQueryable <KpiYearDAO> query, KpiYearFilter 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 <bool> ValidateKpiYear(KpiGeneral KpiGeneral) { KpiYearFilter KpiYearFilter = new KpiYearFilter { Id = new IdFilter { Equal = KpiGeneral.KpiYearId } }; int count = await UOW.KpiYearRepository.Count(KpiYearFilter); if (count == 0) { KpiGeneral.AddError(nameof(KpiGeneralValidator), nameof(KpiGeneral.KpiYear), ErrorCode.KpiYearIdNotExisted); } if (KpiGeneral.KpiYearId < StaticParams.DateTimeNow.Year) { KpiGeneral.AddError(nameof(KpiGeneralValidator), nameof(KpiGeneral.KpiYear), ErrorCode.KpiYearIdIsInThePast); } return(KpiGeneral.IsValidated); }
private async Task <List <KpiYear> > DynamicSelect(IQueryable <KpiYearDAO> query, KpiYearFilter filter) { List <KpiYear> KpiYears = await query.Select(q => new KpiYear() { Id = filter.Selects.Contains(KpiYearSelect.Id) ? q.Id : default(long), Code = filter.Selects.Contains(KpiYearSelect.Code) ? q.Code : default(string), Name = filter.Selects.Contains(KpiYearSelect.Name) ? q.Name : default(string), }).ToListAsync(); return(KpiYears); }