public async Task <PagedResult <PropertyViewModel> > Find(GetFindPropertyPagingRequest request) { var query = from p in _context.Properties join w in _context.Wards on p.WardId equals w.Id join tt in _context.TypeOfTransactions on p.TypeOfTransactionId equals tt.Id join tp in _context.TypeOfProperties on p.TypeOfPropertyId equals tp.Id join e in _context.EvaluationStatuses on p.EvaluationStatusId equals e.Id join d in _context.Directions on p.HouseDirectionId equals d.Id join l in _context.LegalPapers on p.LegalPapersId equals l.Id join ds in _context.Districts on w.DistrictId equals ds.Id join pc in _context.Provinces on ds.ProvinceId equals pc.Id join i in _context.PropertyImages on p.Id equals i.PropertyId into joined from j in (from i in joined where i.IsDefault == true select i).DefaultIfEmpty() where p.Status == Status.Approved select new { p, w, tt, d, tp, e, ds, pc, j, l }; if (request.typeOfTransactionId > 0) { query = query.Where(x => x.p.TypeOfTransactionId == request.typeOfTransactionId); } if (request.typeOfPropertyId.HasValue && request.typeOfPropertyId > 0) { query = query.Where(x => x.p.TypeOfPropertyId == request.typeOfPropertyId); } if (request.price.HasValue && request.price > 0) { query = query.Where(x => x.p.Price <= request.price); } if (request.area.HasValue && request.area > 0) { query = query.Where(x => x.p.Area <= request.area); } if (request.houseDirectionId.HasValue && request.houseDirectionId > 0) { query = query.Where(x => x.p.HouseDirectionId == request.houseDirectionId); } if (request.numberOfBedrooms.HasValue && request.numberOfBedrooms > 0) { query = query.Where(x => x.p.NumberOfBedrooms <= request.numberOfBedrooms); } if (request.evaluationStatusId.HasValue && request.evaluationStatusId > 0) { query = query.Where(x => x.p.EvaluationStatusId == request.evaluationStatusId); } if (request.provinceId.HasValue && request.provinceId > 0) { query = query.Where(x => x.pc.Id == request.provinceId); } if (request.districtId.HasValue && request.districtId > 0) { query = query.Where(x => x.ds.Id == request.districtId); } if (request.wardId.HasValue && request.wardId > 0) { query = query.Where(x => x.p.WardId == request.wardId); } int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new PropertyViewModel() { Id = x.p.Id, Title = x.p.Title, ProvinceName = x.pc.Name, DistrictName = x.ds.Name, LinkName = x.j.LinkName, LegalPaperName = x.l.TypeOfLegalPapers, Area = x.p.Area, AreaFrom = x.p.AreaFrom, AreaTo = x.p.AreaTo, Length = x.p.Length, Width = x.p.Width, Facade = x.p.Facade, Price = x.p.Price, PriceFrom = x.p.PriceFrom, PriceTo = x.p.PriceTo, Description = x.p.Description, NumberOfStoreys = x.p.NumberOfStoreys, NumberOfBedrooms = x.p.NumberOfBedrooms, NumberOfWCs = x.p.NumberOfWCs, DirectionName = x.d.DirectionName, TypeOfPropertyName = x.tp.TypeOfPropertyName, EvaluationStatusName = x.e.EvaluationStatusName, Lat = x.p.Lat, Lng = x.p.Lng, ContactName = x.p.ContactName, EmailContact = x.p.EmailContact, ContactPhone = x.p.ContactPhone }).ToListAsync(); var pagedResult = new PagedResult <PropertyViewModel>() { TotalRecords = totalRow, Items = data }; return(pagedResult); }
public async Task <IActionResult> Find(GetFindPropertyPagingRequest request) { var properties = await _ownerPropertyService.Find(request); return(Ok(properties)); }