private IQueryable <ICForestPlot> GetFilterForestPlotsQuery(FilterForestPlotDetailDto filter) { return(_unitOfWork.GetRepository <ICForestPlot>() .GetAll() .Include(x => x.GESubCompartment) .Include(x => x.GECompartment) .Include(x => x.GEStateProvince) .Include(x => x.GEDistrict) .Include(x => x.GECommunes) .Include(x => x.ICTreeSpec) .Include(x => x.GECompartment) .Include(x => x.GESubCompartment) .Include(x => x.ICForestCert) .Include(x => x.APActor) .ThenInclude(x => x.APActorType) .Include(x => x.GEDisICLandUseCerttrict) .SearchByFields( filter.SearchTerm, x => x.APActor.APActorName) .Where(x => x.FK_GECommuneID == filter.CommuneID && x.FK_ICTreeSpecID == filter.TreeSpecID) .WhereIf(filter.OldFrom.HasValue, x => (x.ICForestPlotPlantingYear.GetValueOrDefault() == 0 ? 0 : (Clock.Now.Year - x.ICForestPlotPlantingYear.GetValueOrDefault())) >= filter.OldFrom) .WhereIf(filter.OldTo.HasValue, x => (x.ICForestPlotPlantingYear.GetValueOrDefault() == 0 ? 0 : (Clock.Now.Year - x.ICForestPlotPlantingYear.GetValueOrDefault())) <= filter.OldTo) .WhereIf(!filter.Reliability.IsNullOrEmpty(), x => x.ICForestPlotReliability == filter.Reliability) .WhereIf(filter.ForestCertID.HasValue, x => x.FK_ICForestCertID == filter.ForestCertID)); }
public async Task <int[]> ForestPlotPlantingYears(FilterForestPlotDetailDto filter) { return(await _unitOfWork.GetRepository <ICForestPlot>() .GetAll() .Where(x => x.FK_GECommuneID == filter.CommuneID && x.FK_ICTreeSpecID == filter.TreeSpecID) .Select(x => x.ICForestPlotPlantingYear.GetValueOrDefault() == 0 ? 0 : (Clock.Now.Year - x.ICForestPlotPlantingYear.GetValueOrDefault())) .Distinct() .OrderBy(x => x) .ToArrayAsync()); }
public async Task <IPagedResultDto <ForestPlotDetailDto> > FilterForestPlotDetailsAsync(PagingAndSortingRequestDto pagingAndSortingRequestDto, FilterForestPlotDetailDto filter) { var plot = await _unitOfWork.GetRepository <ICPlot>() .GetAll() .Include(x => x.ICTreeSpecGroup) .Include(x => x.ICTreeSpec) .Include(x => x.GECommune) .ThenInclude(x => x.GEDistrict) .ThenInclude(x => x.GEStateProvince) .FirstOrDefaultAsync(x => x.FK_GECommuneID == filter.CommuneID && x.FK_ICTreeSpecID == filter.TreeSpecID); var query = GetFilterForestPlotsQuery(filter); return(await query.OrderBy(x => x.Id) .ApplySorting(pagingAndSortingRequestDto) .GetPagedResultAsync(pagingAndSortingRequestDto.Page, pagingAndSortingRequestDto.PageSize, x => x.ToForestPlotDetailDto(), plot.ToForestPlotDto())); }