public static object CreateResultObject(this PaginatedList <CItemSet> paginatedList)
 {
     return(paginatedList.Select(x => new
     {
         Id = x.Id,
         Name = x.Name,
     }));
 }
 public PricesPageViewModel(PaginatedList <Price> paginatedList) :
     base(paginatedList.PageIndex, paginatedList.PageSize, paginatedList.TotalPages, paginatedList.TotalCount)
 {
     this.Items = paginatedList.Select(p => new PriceViewModel(p))
                  .OrderBy(p => p.Price)
                  .ThenBy(p => p.Supplier)
                  .ToList();
 }
 public PaginationResult(
     PaginatedList <TEntity> pageEntity, Func <TEntity, TViewModel> func)
 {
     Content         = pageEntity.Select(func);
     TotalPages      = pageEntity.TotalPages;
     TotalItems      = pageEntity.TotalItems;
     CurrentPage     = pageEntity.PageIndex;
     Size            = pageEntity.PageSize;
     HasNextpage     = pageEntity.HasNextPage;
     HasPreviousPage = pageEntity.HasPreviousPage;
 }
示例#4
0
        public Status <BoundBoxSearch> SearchLocation(float lat, float lng, float miles)
        {
            var bounds = Haversine.GetBoundingBox(lat, lng, miles);
            PaginatedList <BuildingPreview> results = null;

            using (var context = new RentlerContext())
            {
                var final = from b in context.Buildings
                            where b.IsActive &&
                            !b.IsDeleted &&
                            !b.IsRemovedByAdmin &&
                            b.Latitude >= bounds.MinLat &&
                            b.Latitude <= bounds.MaxLat &&
                            b.Longitude >= bounds.MinLng &&
                            b.Longitude <= bounds.MaxLng
                            orderby b.BuildingId
                            select new BuildingPreview()
                {
                    Address1              = b.Address1,
                    Address2              = b.Address2,
                    Bathrooms             = b.Bathrooms.Value,
                    Bedrooms              = b.Bedrooms.Value,
                    BuildingId            = b.BuildingId,
                    RibbonId              = b.RibbonId,
                    City                  = b.City,
                    IsFeatured            = false,
                    Price                 = b.Price,
                    PrimaryPhotoExtension = b.PrimaryPhotoExtension,
                    PrimaryPhotoId        = b.PrimaryPhotoId,
                    State                 = b.State,
                    Title                 = b.Title,
                    IsActive              = b.IsActive,
                    Latitude              = b.Latitude,
                    Longitude             = b.Longitude,
                    Zip = b.Zip
                };
                // get the results to show
                results = new PaginatedList <BuildingPreview>(final, 1, int.MaxValue);
            }

            results = new PaginatedList <BuildingPreview>(results
                                                          .Select(z => new KeyValuePair <double, BuildingPreview>(
                                                                      Haversine.GetDistance(lat, lng, z.Latitude, z.Longitude), z))
                                                          .OrderBy(z => z.Key).Select(s => s.Value).AsQueryable(), 1, int.MaxValue);

            return(Status.OK(new BoundBoxSearch
            {
                Results = results,
                Bounds = bounds,
                ResultsPerPage = int.MaxValue,
                Page = 1
            }));
        }
        public PaginatedList <UserWithRoles> GetUsers(int pageIndex, int pageSize)
        {
            PaginatedList <User>       users = _userRepository.Paginate <int>(pageIndex, pageSize, x => x.Id);
            IQueryable <UserWithRoles> userWithRolesCollection = users.Select(user => new UserWithRoles()
            {
                User  = user,
                Roles = GetUserRoles(user.Id)
            }).AsQueryable();

            return(new PaginatedList <UserWithRoles>(
                       userWithRolesCollection, users.PageIndex, users.PageSize, users.TotalCount));
        }
 public static object CreateResultObject(this PaginatedList <CCreatureTemplate> paginatedList)
 {
     return(paginatedList.Select(x => new
     {
         Id = x.Entry,
         Name = x.Name,
         SubName = x.SubName,
         MinLevel = x.MinLevel,
         MaxLevel = x.MaxLevel,
         CreatureType = x.CreatureType,
         Rank = x.Rank
     }));
 }
 internal static PaginatedDto <VtSystemDto> ToPaginatedListVtSystemDto(this PaginatedList <VT_SYSTEM> pls)
 {
     return(new PaginatedDto <VtSystemDto>
     {
         HasNextPage = pls.HasNextPage,
         HasPreviousPage = pls.HasPreviousPage,
         PageIndex = pls.PageIndex,
         PageSize = pls.PageSize,
         TotalCount = pls.TotalCount,
         TotalPageCount = pls.TotalPageCount,
         Items = pls.Select(x => x.ToVtSystemDto())
     });
 }
        public async Task <IActionResult> Get(
            [FromQuery] MiniSearchModel search = null,
            [FromQuery] int pageSize           = 21,
            [FromQuery] int pageIndex          = 1,
            [FromQuery] int creatorId          = 0)
        {
            //TODO: Move creator into MiniSearchModel?
            Creator creatorInfo = new Creator();

            if (creatorId > 0)
            {
                creatorInfo = await _context.Mini.AsNoTracking().TagWith("Minis API Search")
                              .Include(m => m.Creator)
                              .Select(m => m.Creator)
                              .FirstOrDefaultAsync(c => c.ID == creatorId);
            }

            PageInfo pagingInfo = new PageInfo(pageSize, pageIndex);

            MiniSearchRequest searchRequest = new MiniSearchRequest {
                PageInfo = pagingInfo, Creator = creatorInfo
            };

            _mapper.Map(search).Over(searchRequest);
            PaginatedList <Mini> searchResult = await _mediator.Send(searchRequest);

            _telemetry.TrackEvent("MiniSearchAPI", new Dictionary <string, string> {
                { "SearchString", searchRequest.SearchString },
                { "Tags", String.Join(",", searchRequest.Tags) },
                { "FreeOnly", searchRequest.FreeOnly.ToString() },
                { "HadResults", searchResult.Count > 0 ? "True" : "False" },
                { "PageIndex", searchRequest.PageInfo.PageIndex.ToString() },
                { "SortType", searchRequest.SortType }
            });
            return(Ok(
                       searchResult.Select(
                           m => new
            {
                ID = m.ID,
                Name = m.Name,
                Status = m.Status.ToString(),
                Creator = new { name = m.Creator.Name, id = m.Creator.ID },
                Thumbnail = m.Thumbnail.Replace("miniindex.blob.core.windows.net", _configuration["CDNURL"] + ".azureedge.net"),
                LinuxTime = m.ApprovedLinuxTime()
            }
                           )
                       ));
        }
 public ProductsPageViewModel(PaginatedList <Product> paginatedList) :
     base(paginatedList.PageIndex, paginatedList.PageSize, paginatedList.TotalPages, paginatedList.TotalCount)
 {
     this.Items = paginatedList.Select(p => new ProductViewModel(p)).ToList();
 }
示例#10
0
        public Status<BoundBoxSearch> SearchLocation(float lat, float lng, float miles)
        {
            var bounds = Haversine.GetBoundingBox(lat, lng, miles);
            PaginatedList<BuildingPreview> results = null;

            using (var context = new RentlerContext())
            {
                var final = from b in context.Buildings
                            where b.IsActive &&
                                    !b.IsDeleted &&
                                    !b.IsRemovedByAdmin &&
                                    b.Latitude >= bounds.MinLat &&
                                    b.Latitude <= bounds.MaxLat &&
                                    b.Longitude >= bounds.MinLng &&
                                    b.Longitude <= bounds.MaxLng
                            orderby b.BuildingId
                            select new BuildingPreview()
                            {
                                Address1 = b.Address1,
                                Address2 = b.Address2,
                                Bathrooms = b.Bathrooms.Value,
                                Bedrooms = b.Bedrooms.Value,
                                BuildingId = b.BuildingId,
                                RibbonId = b.RibbonId,
                                City = b.City,
                                IsFeatured = false,
                                Price = b.Price,
                                PrimaryPhotoExtension = b.PrimaryPhotoExtension,
                                PrimaryPhotoId = b.PrimaryPhotoId,
                                State = b.State,
                                Title = b.Title,
                                IsActive = b.IsActive,
                                Latitude = b.Latitude,
                                Longitude = b.Longitude,
                                Zip = b.Zip
                            };
                // get the results to show
                results = new PaginatedList<BuildingPreview>(final, 1, int.MaxValue);
            }

            results = new PaginatedList<BuildingPreview>(results
                .Select(z => new KeyValuePair<double, BuildingPreview>(
                    Haversine.GetDistance(lat, lng, z.Latitude, z.Longitude), z))
                .OrderBy(z => z.Key).Select(s => s.Value).AsQueryable(), 1, int.MaxValue);

            return Status.OK(new BoundBoxSearch
            {
                Results = results,
                Bounds = bounds,
                ResultsPerPage = int.MaxValue,
                Page = 1
            });
        }
示例#11
0
 public static PaginatedList <SchoolSummaryInfo> Create(PaginatedList <ShortSchoolSummary> schoolSummaries)
 {
     return(new PaginatedList <SchoolSummaryInfo>(schoolSummaries.Select(Create), schoolSummaries.PageIndex,
                                                  schoolSummaries.PageSize, schoolSummaries.TotalCount));
 }
示例#12
0
        public static object CreateResultObject(this PaginatedList <CItemTemplate> paginatedList, byte itemClass)
        {
            switch (itemClass)
            {
            case (byte)ItemEnums.ItemClasses.CONTAINER:
                return(paginatedList.Select(x => new
                {
                    Id = x.Entry,
                    Name = x.Name,
                    Class = x.Class,
                    SubClass = x.Subclass,
                    Quality = x.Quality,
                    ReqLevel = x.RequiredLevel,
                    ItemLevel = x.ItemLevel,
                    ContainerSlots = x.ContainerSlots
                }));

            case (byte)ItemEnums.ItemClasses.WEAPON:
                return(paginatedList.Select(x => new
                {
                    Id = x.Entry,
                    Name = x.Name,
                    Class = x.Class,
                    SubClass = x.Subclass,
                    Quality = x.Quality,
                    ReqLevel = x.RequiredLevel,
                    ItemLevel = x.ItemLevel,
                    Dps = x.CalculateItemDps(),
                    Speed = x.Delay / 1000.0F
                }));

            case (byte)ItemEnums.ItemClasses.ARMOR:
                return(paginatedList.Select(x => new
                {
                    Id = x.Entry,
                    Name = x.Name,
                    Class = x.Class,
                    SubClass = x.Subclass,
                    Quality = x.Quality,
                    ReqLevel = x.RequiredLevel,
                    ItemLevel = x.ItemLevel,
                    Armor = x.Armor,
                    Slot = x.InventoryType
                }));

            case (byte)ItemEnums.ItemClasses.CONSUMEABLE:
            case (byte)ItemEnums.ItemClasses.REAGENT:
            case (byte)ItemEnums.ItemClasses.PROJECTILE:
            case (byte)ItemEnums.ItemClasses.TRADE_GOODS:
            case (byte)ItemEnums.ItemClasses.GENERIC:
            case (byte)ItemEnums.ItemClasses.RECIPE:
            case (byte)ItemEnums.ItemClasses.MONEY:
            case (byte)ItemEnums.ItemClasses.QUIVER:
            case (byte)ItemEnums.ItemClasses.QUEST:
            case (byte)ItemEnums.ItemClasses.KEY:
            case (byte)ItemEnums.ItemClasses.PERMANENT:
            case (byte)ItemEnums.ItemClasses.MISC:
            case (byte)ItemEnums.ItemClasses.GLYPH:
            default:
                return(paginatedList.Select(x => new
                {
                    Id = x.Entry,
                    Name = x.Name,
                    Class = x.Class,
                    SubClass = x.Subclass,
                    Quality = x.Quality,
                    ReqLevel = x.RequiredLevel,
                    ItemLevel = x.ItemLevel
                }));
            }
        }
 internal static PaginatedDto <ComplaintsDto> ToPaginatedComplaintsDto(this PaginatedList <Complaints> cls)
 {
     return(new PaginatedDto <ComplaintsDto>
     {
         HasNextPage = cls.HasNextPage, HasPreviousPage = cls.HasPreviousPage, PageIndex = cls.PageIndex,
         PageSize = cls.PageSize, TotalCount = cls.TotalCount, TotalPageCount = cls.TotalPageCount, Items = cls.Select(x => x.ToComplaintsDto())
     });
 }
 internal static PaginatedDto <SysMsgDto> ToPaginatedMsgDto(this PaginatedList <SYS_MSGUSER> cls)
 {
     return(new PaginatedDto <SysMsgDto>
     {
         HasNextPage = cls.HasNextPage, HasPreviousPage = cls.HasPreviousPage, PageIndex = cls.PageIndex,
         PageSize = cls.PageSize, TotalCount = cls.TotalCount, TotalPageCount = cls.TotalPageCount, Items = cls.Select(x => x.ToSysMsgDto())
     });
 }
 internal static PaginatedDto <VtColDataDto> ToPaginatedRunningDataDto(this PaginatedList <VT_COLDATA> pls)
 {
     return(new PaginatedDto <VtColDataDto>
     {
         HasNextPage = pls.HasNextPage, HasPreviousPage = pls.HasPreviousPage, PageIndex = pls.PageIndex,
         PageSize = pls.PageSize, TotalCount = pls.TotalCount, TotalPageCount = pls.TotalPageCount, Items = pls.Select(x => x.ToVtColDataDto())
     });
 }
 internal static PaginatedDto <PowerDataDto> ToPaginatedPowerDataDto(this PaginatedList <PowerData> pls)
 {
     return(new PaginatedDto <PowerDataDto>
     {
         HasNextPage = pls.HasNextPage, HasPreviousPage = pls.HasPreviousPage, PageIndex = pls.PageIndex,
         PageSize = pls.PageSize, TotalCount = pls.TotalCount, TotalPageCount = pls.TotalPageCount, Items = pls.Select(x => x.ToPowerDataDto())
     });
 }
 internal static PaginatedDto <EnergyReportDataDto> ToPaginatedListEnergyDataDto(this PaginatedList <EnergyReportData> pl)
 {
     return(new PaginatedDto <EnergyReportDataDto>
     {
         HasNextPage = pl.HasNextPage, HasPreviousPage = pl.HasPreviousPage, PageIndex = pl.PageIndex,
         PageSize = pl.PageSize, TotalCount = pl.TotalCount, TotalPageCount = pl.TotalPageCount, Items = pl.Select(x => x.ToEnergyReportDataDto())
     });
 }
 internal static PaginatedDto <ReportEnergyDto> ToPaginatedListReportEnergyDto(this PaginatedList <Report_Energy> pl)
 {
     return(new PaginatedDto <ReportEnergyDto>
     {
         HasNextPage = pl.HasNextPage, HasPreviousPage = pl.HasPreviousPage, PageIndex = pl.PageIndex,
         PageSize = pl.PageSize, TotalCount = pl.TotalCount, TotalPageCount = pl.TotalPageCount, Items = pl.TotalCount > 0 ? pl.Select(x => x.ToReportEnergDto()).ToList() : new List <ReportEnergyDto>()
     });
 }
示例#19
0
        /// <summary>
        /// Searches the specified search.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <returns>
        /// A paginated list of search results.
        /// </returns>
        public Status <Search> Search(Search search)
        {
            // if it is null create a new one
            if (search == null)
            {
                search = new Search();
            }

            if (search.Page < 1)
            {
                search.Page = 1;
            }
            if (search.ResultsPerPage < 5)
            {
                search.ResultsPerPage = 30;
            }

            PaginatedList <BuildingPreview> results = null;

            // get the zip codes for the given location

            string[] codes = this.zipAdapter.GetZipCodesFromLocation(search.Location);

            var featured = featuredAdapter.GetFeatured(codes);

            search.ResultsPerPage = search.ResultsPerPage - featured.Result.Count;

            // find all the buildings
            using (var context = new RentlerContext())
            {
                var listings = from b in context.Buildings
                               where b.IsActive &&
                               b.IsDeleted == false &&
                               b.IsRemovedByAdmin == false
                               select b;

                // Location is defined
                if (codes.Length > 0)
                {
                    listings = from b in listings
                               where codes.Contains(b.Zip)
                               select b;
                }

                // Property Type is defined
                if (search.PropertyType != PropertyType.Undefined)
                {
                    listings = from b in listings
                               where b.PropertyTypeCode == search.PropertyTypeCode
                               select b;
                }

                // Minimum Price defined
                if (search.MinPrice.HasValue)
                {
                    listings = from b in listings
                               where b.Price >= search.MinPrice
                               select b;
                }

                // Maximum Price defined
                if (search.MaxPrice.HasValue)
                {
                    listings = from b in listings
                               where b.Price <= search.MaxPrice
                               select b;
                }

                // start of advanced

                // Bedrooms is defined
                if (search.Bedrooms.HasValue)
                {
                    listings = from b in listings
                               where b.Bedrooms >= search.Bedrooms
                               select b;
                }

                // Bathrooms is defined
                if (search.Bathrooms.HasValue)
                {
                    listings = from b in listings
                               where b.Bathrooms >= search.Bathrooms
                               select b;
                }

                // Minimum Square Footage is defined
                if (search.MinSquareFootage.HasValue)
                {
                    listings = from b in listings
                               where b.SquareFeet >= search.MinSquareFootage
                               select b;
                }

                // Maximum Square Footage is defined
                if (search.MaxSquareFootage.HasValue)
                {
                    listings = from b in listings
                               where b.SquareFeet <= search.MaxSquareFootage
                               select b;
                }

                // Year Built Minimum is defined
                if (search.YearBuiltMin.HasValue)
                {
                    listings = from b in listings
                               where b.YearBuilt >= search.YearBuiltMin
                               select b;
                }

                // Year Built Maximum is defined
                if (search.YearBuiltMax.HasValue)
                {
                    listings = from b in listings
                               where b.YearBuilt <= search.YearBuiltMax
                               select b;
                }

                // Amenities are defined
                if (search.Amenities != null && search.Amenities.Length > 0)
                {
                    listings                   = from b in listings
                                        let ba = b.BuildingAmenities.Select(x => x.AmenityId)
                                                 where search.Amenities.All(a => ba.Contains(a))
                                                 select b;
                }

                // Seller Type is defined
                if (search.SellerType != ContactInfoType.Undefined)
                {
                    listings = from b in listings
                               where b.ContactInfo.ContactInfoTypeCode == search.SellerTypeCode
                               select b;
                }

                // Terms
                if (search.Terms != null)
                {
                    // pet friendly
                    if (search.Terms.Contains("petfriendly"))
                    {
                        listings = from b in listings
                                   where b.ArePetsAllowed == true
                                   select b;
                    }

                    // smoking allowed
                    if (search.Terms.Contains("smokingallowed"))
                    {
                        listings = from b in listings
                                   where b.IsSmokingAllowed == true
                                   select b;
                    }
                }

                // Terms Lease Length
                if (search.LeaseLength != LeaseLength.Undefined)
                {
                    listings = from b in listings
                               where b.LeaseLengthCode == search.LeaseLengthCode
                               select b;
                }

                // photos only
                if (search.PhotosOnly)
                {
                    // if it has a primary photo then it has at least 1 photo
                    listings = from b in listings
                               where b.PrimaryPhotoId.HasValue
                               select b;
                }

                // keywords
                if (!string.IsNullOrWhiteSpace(search.Keywords))
                {
                    List <string> keywords = new List <string>();

                    // add words
                    keywords.AddRange(
                        search.Keywords.Split(
                            new char[0],
                            StringSplitOptions.RemoveEmptyEntries
                            )
                        );

                    // add the whole phrase by default if more
                    // than 1 word
                    if (keywords.Count > 1)
                    {
                        keywords.Add(search.Keywords);
                    }

                    // replace commas
                    for (int i = 0; i < keywords.Count; ++i)
                    {
                        keywords[i] = keywords[i].Replace(",", "");
                    }

                    // apply to Title, Description and Custom Amenities
                    listings                   = from b in listings
                                        let ca = b.CustomAmenities.Select(a => a.Name)
                                                 where keywords.Any(k => b.Title.Contains(k)) ||
                                                 keywords.Any(k => b.Description.Contains(k)) ||
                                                 keywords.Any(k => ca.Any(a => a.Contains(k)))
                                                 select b;
                }

                // end of advanced

                // apply default ordering
                switch (search.OrderBy)
                {
                case "NewOld":
                    //order by for priority listings, as well as date activated
                    listings = listings.OrderByDescending(l => l.HasPriority)
                               .ThenByDescending(l => l.DateActivatedUtc);
                    break;

                case "OldNew":
                    listings = listings.OrderBy(m => m.DateActivatedUtc);
                    break;

                case "PriceHighLow":
                    listings = listings.OrderByDescending(m => m.Price);
                    break;

                case "PriceLowHigh":
                    listings = listings.OrderBy(m => m.Price);
                    break;

                case "DateAvailable":
                    break;

                default:
                    listings = listings.OrderByDescending(l => l.HasPriority)
                               .ThenByDescending(l => l.DateActivatedUtc);
                    break;
                }

                // convert to building preview
                var final = from b in listings
                            select new BuildingPreview()
                {
                    Address1              = b.Address1,
                    Address2              = b.Address2,
                    Bathrooms             = b.Bathrooms.Value,
                    Bedrooms              = b.Bedrooms.Value,
                    BuildingId            = b.BuildingId,
                    RibbonId              = b.RibbonId,
                    City                  = b.City,
                    IsFeatured            = false,
                    Price                 = b.Price,
                    PrimaryPhotoExtension = b.PrimaryPhotoExtension,
                    PrimaryPhotoId        = b.PrimaryPhotoId,
                    State                 = b.State,
                    Title                 = b.Title,
                    IsActive              = b.IsActive,
                    Latitude              = b.Latitude,
                    Longitude             = b.Longitude,
                    HasPriority           = b.HasPriority,
                    DatePrioritized       = b.DatePrioritized,
                    Zip = b.Zip
                };

#if DEBUG
                Tracer.OutputQuery <BuildingPreview>(final);
#endif
                // get the results to show
                results = new PaginatedList <BuildingPreview>(
                    final,
                    search.Page,
                    search.ResultsPerPage
                    );

                //grab featured items if we have any results
                if (results.Count > 0)
                {
                    results.InsertRange(0, featured.Result);
                }
            }

            // increment search views for each listing
            IncrementSearchViews(results.Select(m => m.BuildingId).ToArray());

            search.Results = results;

            search.HasNextPage     = results.HasNextPage;
            search.HasPreviousPage = results.HasPreviousPage;

            return(Status.OK <Search>(search));
        }
示例#20
0
        public async Task OnGetAsync(int currentFilter, int searchTypeInt, int?pageIndex)
        {
            if (searchTypeInt != 0)
            {
                pageIndex = 1;
            }
            else
            {
                searchTypeInt = currentFilter;
            }

            CurrentFilter = searchTypeInt;

            List <SelectListItem> Types = new List <SelectListItem>();

            Types.Add(new SelectListItem()
            {
                Value = "1", Text = "Būsenos"
            });
            Types.Add(new SelectListItem()
            {
                Value = "2", Text = "Komentarai"
            });
            Types.Add(new SelectListItem()
            {
                Value = "3", Text = "Įsimintini"
            });

            ViewData["Types"] = new SelectList(Types, "Value", "Text", CurrentFilter.ToString());

            var user = await _userManager.GetUserAsync(User);

            IQueryable <Notification> notificationIQ = _context.Notifications
                                                       .Where(r => r.AppUserId == user.Id)
                                                       .OrderByDescending(r => r.CreatedDate);


            if (searchTypeInt != 0)
            {
                var realType = (NotiflicationType)searchTypeInt - 1;
                notificationIQ = notificationIQ.Where(s => s.Type == realType);
            }


            int pageSize = 20;

            Notification = await PaginatedList <Notification> .CreateAsync(
                notificationIQ.AsNoTracking(), pageIndex ?? 1, pageSize);

            ModelForNotificationIndexes = Notification
                                          .Select(r => new ModelForNotificationIndex()
            {
                Content     = r.Content,
                Link        = r.Link,
                IsRead      = r.IsRead,
                CreatedDate = r.CreatedDate,
                Type        = r.Type
            }).ToList();

            bool isUpdatable = false;

            foreach (var item in Notification.Where(r => r.IsRead == false))
            {
                isUpdatable = true;
                item.IsRead = true;
                _context.Entry(item).State = EntityState.Modified;
            }
            if (isUpdatable)
            {
                _context.SaveChanges();
            }
        }
示例#21
0
        /// <summary>
        /// Searches the specified search.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <returns>
        /// A paginated list of search results.
        /// </returns>
        public Status<Search> Search(Search search)
        {
            // if it is null create a new one
            if (search == null)
                search = new Search();

            if (search.Page < 1)
                search.Page = 1;
            if (search.ResultsPerPage < 5)
                search.ResultsPerPage = 30;

            PaginatedList<BuildingPreview> results = null;

            // get the zip codes for the given location

            string[] codes = this.zipAdapter.GetZipCodesFromLocation(search.Location);

            var featured = featuredAdapter.GetFeatured(codes);

            search.ResultsPerPage = search.ResultsPerPage - featured.Result.Count;

            // find all the buildings
            using (var context = new RentlerContext())
            {
                var listings = from b in context.Buildings
                               where b.IsActive &&
                               b.IsDeleted == false &&
                               b.IsRemovedByAdmin == false
                               select b;

                // Location is defined
                if (codes.Length > 0)
                {
                    listings = from b in listings
                               where codes.Contains(b.Zip)
                               select b;
                }

                // Property Type is defined
                if (search.PropertyType != PropertyType.Undefined)
                {
                    listings = from b in listings
                               where b.PropertyTypeCode == search.PropertyTypeCode
                               select b;
                }

                // Minimum Price defined
                if (search.MinPrice.HasValue)
                {
                    listings = from b in listings
                               where b.Price >= search.MinPrice
                               select b;
                }

                // Maximum Price defined
                if (search.MaxPrice.HasValue)
                {
                    listings = from b in listings
                               where b.Price <= search.MaxPrice
                               select b;
                }

                // start of advanced

                // Bedrooms is defined
                if (search.Bedrooms.HasValue)
                {
                    listings = from b in listings
                               where b.Bedrooms >= search.Bedrooms
                               select b;
                }

                // Bathrooms is defined
                if (search.Bathrooms.HasValue)
                {
                    listings = from b in listings
                               where b.Bathrooms >= search.Bathrooms
                               select b;
                }

                // Minimum Square Footage is defined
                if (search.MinSquareFootage.HasValue)
                {
                    listings = from b in listings
                               where b.SquareFeet >= search.MinSquareFootage
                               select b;
                }

                // Maximum Square Footage is defined
                if (search.MaxSquareFootage.HasValue)
                {
                    listings = from b in listings
                               where b.SquareFeet <= search.MaxSquareFootage
                               select b;
                }

                // Year Built Minimum is defined
                if (search.YearBuiltMin.HasValue)
                {
                    listings = from b in listings
                               where b.YearBuilt >= search.YearBuiltMin
                               select b;
                }

                // Year Built Maximum is defined
                if (search.YearBuiltMax.HasValue)
                {
                    listings = from b in listings
                               where b.YearBuilt <= search.YearBuiltMax
                               select b;
                }

                // Amenities are defined
                if (search.Amenities != null && search.Amenities.Length > 0)
                {
                    listings = from b in listings
                               let ba = b.BuildingAmenities.Select(x => x.AmenityId)
                               where search.Amenities.All(a => ba.Contains(a))
                               select b;
                }

                // Seller Type is defined
                if (search.SellerType != ContactInfoType.Undefined)
                {
                    listings = from b in listings
                               where b.ContactInfo.ContactInfoTypeCode == search.SellerTypeCode
                               select b;
                }

                // Terms
                if (search.Terms != null)
                {
                    // pet friendly
                    if (search.Terms.Contains("petfriendly"))
                    {
                        listings = from b in listings
                                   where b.ArePetsAllowed == true
                                   select b;
                    }

                    // smoking allowed
                    if (search.Terms.Contains("smokingallowed"))
                    {
                        listings = from b in listings
                                   where b.IsSmokingAllowed == true
                                   select b;
                    }
                }

                // Terms Lease Length
                if (search.LeaseLength != LeaseLength.Undefined)
                {
                    listings = from b in listings
                               where b.LeaseLengthCode == search.LeaseLengthCode
                               select b;
                }

                // photos only
                if (search.PhotosOnly)
                {
                    // if it has a primary photo then it has at least 1 photo
                    listings = from b in listings
                               where b.PrimaryPhotoId.HasValue
                               select b;
                }

                // keywords
                if (!string.IsNullOrWhiteSpace(search.Keywords))
                {
                    List<string> keywords = new List<string>();

                    // add words
                    keywords.AddRange(
                        search.Keywords.Split(
                            new char[0],
                            StringSplitOptions.RemoveEmptyEntries
                        )
                    );

                    // add the whole phrase by default if more
                    // than 1 word
                    if (keywords.Count > 1)
                        keywords.Add(search.Keywords);

                    // replace commas
                    for (int i = 0; i < keywords.Count; ++i)
                        keywords[i] = keywords[i].Replace(",", "");

                    // apply to Title, Description and Custom Amenities
                    listings = from b in listings
                               let ca = b.CustomAmenities.Select(a => a.Name)
                               where keywords.Any(k => b.Title.Contains(k)) ||
                               keywords.Any(k => b.Description.Contains(k)) ||
                               keywords.Any(k => ca.Any(a => a.Contains(k)))
                               select b;
                }

                // end of advanced

                // apply default ordering
                switch (search.OrderBy)
                {
                    case "NewOld":
                        //order by for priority listings, as well as date activated
                        listings = listings.OrderByDescending(l => l.HasPriority)
                                           .ThenByDescending(l => l.DateActivatedUtc);
                        break;
                    case "OldNew":
                        listings = listings.OrderBy(m => m.DateActivatedUtc);
                        break;
                    case "PriceHighLow":
                        listings = listings.OrderByDescending(m => m.Price);
                        break;
                    case "PriceLowHigh":
                        listings = listings.OrderBy(m => m.Price);
                        break;
                    case "DateAvailable":
                        break;
                    default:
                        listings = listings.OrderByDescending(l => l.HasPriority)
                                           .ThenByDescending(l => l.DateActivatedUtc);
                        break;
                }

                // convert to building preview
                var final = from b in listings
                            select new BuildingPreview()
                            {
                                Address1 = b.Address1,
                                Address2 = b.Address2,
                                Bathrooms = b.Bathrooms.Value,
                                Bedrooms = b.Bedrooms.Value,
                                BuildingId = b.BuildingId,
                                RibbonId = b.RibbonId,
                                City = b.City,
                                IsFeatured = false,
                                Price = b.Price,
                                PrimaryPhotoExtension = b.PrimaryPhotoExtension,
                                PrimaryPhotoId = b.PrimaryPhotoId,
                                State = b.State,
                                Title = b.Title,
                                IsActive = b.IsActive,
                                Latitude = b.Latitude,
                                Longitude = b.Longitude,
                                HasPriority = b.HasPriority,
                                DatePrioritized = b.DatePrioritized,
                                Zip = b.Zip
                            };

            #if DEBUG
                Tracer.OutputQuery<BuildingPreview>(final);
            #endif
                // get the results to show
                results = new PaginatedList<BuildingPreview>(
                    final,
                    search.Page,
                    search.ResultsPerPage
                );

                //grab featured items if we have any results
                if (results.Count > 0)
                    results.InsertRange(0, featured.Result);
            }

            // increment search views for each listing
            IncrementSearchViews(results.Select(m => m.BuildingId).ToArray());

            search.Results = results;

            search.HasNextPage = results.HasNextPage;
            search.HasPreviousPage = results.HasPreviousPage;

            return Status.OK<Search>(search);
        }
示例#22
0
 public static PaginatedList <LocalSchoolSummaryViewData> Create(PaginatedList <SchoolSummaryInfo> schools)
 {
     return(new PaginatedList <LocalSchoolSummaryViewData>(schools.Select(Create), schools.PageIndex, schools.PageSize, schools.TotalCount));
 }
 public PageEntityViewModel(
     PaginatedList <TEntity> pageEntity, Func <TEntity, TViewModel> func)
 {
     Entities = pageEntity.Select(func);
     Pager    = Pagination.FromPaginatedList(pageEntity);
 }