コード例 #1
0
        public async Task <ListingsResponse> GetFilteredListing([FromBody] ListingFilter filter)
        {
            var listings = string.IsNullOrEmpty(filter.Query) ?
                           _listingRepository.GetByFilter(_ => true) :
                           GetFullTextSearch(filter.Query);

            if (!string.IsNullOrEmpty(filter.City))
            {
                listings = listings.Where(x => x.City.Name == filter.City);
            }
            if (filter.Towns != null && filter.Towns.Any())
            {
                listings = listings.Where(x => filter.Towns.Contains(x.Town.Name));
            }
            if (filter.Streets != null && filter.Streets.Any())
            {
                listings = listings.Where(x => filter.Streets.Contains(x.Street.Name));
            }

            if (filter.RoomNumber != null && filter.RoomNumber.Any())
            {
                listings = listings.Where(x => filter.RoomNumber.Contains(x.RoomNumber));
            }

            if (!string.IsNullOrEmpty(filter.AdvertStatus))
            {
                listings = listings.Where(x => x.AdvertStatus == filter.AdvertStatus);
            }
            if (!string.IsNullOrEmpty(filter.FurnitureType))
            {
                listings = listings.Where(x => x.FurnitureStatus == filter.FurnitureType);
            }
            if (!string.IsNullOrEmpty(filter.AdvertOwnerType))
            {
                listings = listings.Where(x => x.AdvertOwnerType == filter.AdvertOwnerType);
            }

            var totalCount = listings.Count();

            listings = listings.Skip(filter.PageNumber * 20).Take(20);

            var filteredListing = await listings.ToListAsync();

            var listingRepresentation = filteredListing.Select(x => _listingMapper.MapListing(x))
                                        .GroupBy(x => x.ReSku).Select(x =>
                                                                      new
            {
                key     = x.Key,
                owners  = x.Select(y => new { ownerName = y.OwnerSite, Url = y.Url }).ToList(),
                Listing = x.First()
            }

                                                                      ).ToList <dynamic>();

            return(new ListingsResponse
            {
                TotalCount = totalCount,
                Listings = listingRepresentation
            });
        }
コード例 #2
0
ファイル: StoreService.cs プロジェクト: zykour/TheAfterParty
 public IEnumerable <Listing> GetListingsWithFilter(ListingFilter filter, out int TotalItems, List <Listing> listings = null)
 {
     return(listingRepository.GetListingsWithFilter(filter, out TotalItems, listings));
 }