public static DictionaryItemDto ToDictionaryItemDto(this GEDistrict value) { return(value == null ? null : new DictionaryItemDto { Key = value.Id.ToString(), Code = value.GEDistrictCode, Text = value.GEDistrictName }); }
public async Task <IPagedResultDto <ShortContactDto> > FilterForestContactsAsync(PagingAndSortingRequestDto pagingAndSortingRequestDto, FilterContactsDto filter) { GECommune commune = null; if (filter.ContactCommuneId > 0) { commune = await _unitOfWork.GetRepository <GECommune>() .GetAll() .Include(x => x.GEDistrict) .FirstOrDefaultAsync(x => x.Id == filter.ContactCommuneId); } GEDistrict district = null; if (filter.ContactDistrictId > 0) { district = await _unitOfWork.GetRepository <GEDistrict>() .GetAll() .Include(x => x.GEStateProvince) .FirstOrDefaultAsync(x => x.Id == filter.ContactDistrictId); } return(await _unitOfWork.GetRepository <ARContact>() .GetAllIncluding(x => x.ARContactReviews) .SearchByFields(filter.SearchTerm, x => x.ARContactName, x => x.ARContactAcronymName, x => x.ARContactContributor, x => x.ARContactUserContact) .WhereIf(filter.ContactStateProvinceId > 0, x => x.ARContactForestCommuneGroups.Any(y => y.FK_GEStateProvinceID == filter.ContactStateProvinceId)) .WhereIf(district != null, x => x.ARContactForestCommuneGroups.Any(y => y.FK_GEDistrictID == filter.ContactDistrictId || (y.FK_GEDistrictID == null && y.FK_GEStateProvinceID == district.FK_GEStateProvinceID))) .WhereIf(commune != null, x => x.ARContactForestCommuneGroups.Any(y => y.FK_GECommuneID == filter.ContactCommuneId || (y.FK_GECommuneID == null && y.FK_GEDistrictID == commune.FK_GEDistrictID) || (y.FK_GECommuneID == null && y.FK_GEDistrictID == null && y.FK_GEStateProvinceID == commune.GEDistrict.FK_GEStateProvinceID))) .OrderByDescending(x => x.ARContactReviews.Max(y => y.ARContactReviewDate)) //.WhereIf(locationFilter.Rating.HasValue, x => x.ARContactReviewRating == locationFilter.Rating) .ApplySorting(pagingAndSortingRequestDto) .GetPagedResultAsync( pagingAndSortingRequestDto.Page, pagingAndSortingRequestDto.PageSize, x => x.ToShortContactDto())); }