public async Task <PagedResult <PropertyViewModel> > GetAllByTypeOfTransaction(GetViewPropertyPagingRequest 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()
                        select new { p, pc, ds, tt, tp, e, d, j, l };

            if (request.typeOfTransactionId.HasValue && request.typeOfTransactionId > 0)
            {
                query = query.Where(x => x.p.TypeOfTransactionId == request.typeOfTransactionId);
            }

            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);
        }
Exemple #2
0
        public async Task <IActionResult> GetAllPaging(GetViewPropertyPagingRequest request)
        {
            var properties = await _ownerPropertyService.GetAllByTypeOfTransaction(request);

            return(Ok(properties));
        }