Beispiel #1
0
        public async Task <IActionResult> FavouritesList(PropertyListModel model, List <int> f = null, string viewName = "_List_Favourites")
        {
            IQueryable <PropertyListing> properties = _db.Properties
                                                      .Include(p => p.Agent)
                                                      .Include(p => p.Metadata)
                                                      .Include(p => p.Media)
                                                      .Where(p => p.Status == model.PublishStatus);

            if (model.Search.IsSet())
            {
                properties = properties.Where(n =>
                                              n.Title.Contains(model.Search) ||
                                              n.Address1.Contains(model.Search) ||
                                              n.Address2.Contains(model.Search) ||
                                              n.City.Contains(model.Search) ||
                                              n.County.Contains(model.Search) ||
                                              n.Postcode.Contains(model.Search) ||
                                              n.ShortDescription.Contains(model.Search) ||
                                              n.Lease.Contains(model.Search) ||
                                              n.Location.Contains(model.Search) ||
                                              n.Planning.Contains(model.Search) ||
                                              n.Reference.Contains(model.Search)
                                              );
            }

            properties = properties.Where(p => f.Contains(p.Id));

            model.AvailableTypes = await _db.Properties.Select(p => p.ListingType).Distinct().ToListAsync();

            model.AvailableStatuses = await _db.Properties.Select(p => p.LeaseStatus).Distinct().ToListAsync();

            model.AvailablePlanningTypes = await _db.Properties.Select(p => p.Planning).Distinct().ToListAsync();

            model.PlanningTypes = Engine.Settings.Property.GetPlanningTypes();

            await model.ReloadAsync(properties);

            return(View(viewName, model));
        }
Beispiel #2
0
        public async Task <PropertyListModel> GetPropertiesAsync(PropertyListModel model)
        {
            IQueryable <PropertyListing> properties = _db.Properties
                                                      .Include(p => p.Agent)
                                                      .Include(p => p.Metadata);

            if (model.LoadImages)
            {
                properties = properties
                             .Include(p => p.Media)
                             .Include(p => p.FloorPlans);
            }

            if (model.PublishStatus.HasValue)
            {
                properties = properties.Where(p => p.Status == model.PublishStatus);
            }

            if (model.Type != null)
            {
                model.Type.RemoveAll(t => !t.IsSet());
                if (model.Type.Count > 0)
                {
                    properties = properties.Where(n => model.Type.Any(t => n.ListingType == t));
                }
            }

            if (model.Status != null)
            {
                model.Status.RemoveAll(t => !t.IsSet());
                if (model.Status.Count > 0)
                {
                    properties = properties.Where(n => model.Status.Any(t => n.LeaseStatus == t));
                }
            }

            if (model.Agent.IsSet())
            {
                properties = properties.Where(n => n.Agent.UserName == model.Agent);
            }

            if (model.Location.IsSet())
            {
                properties = properties.Where(n => n.Address2 == model.Location);
            }

            if (model.PlanningType.IsSet())
            {
                properties = properties.Where(n => n.Planning == model.PlanningType);
            }

            if (model.MinBedrooms.HasValue)
            {
                properties = properties.Where(n => n.Bedrooms >= model.MinBedrooms.Value);
            }

            if (model.MaxBedrooms.HasValue)
            {
                properties = properties.Where(n => n.Bedrooms <= model.MaxBedrooms.Value);
            }

            if (model.Bedrooms.HasValue)
            {
                properties = properties.Where(n => n.Bedrooms == model.Bedrooms.Value);
            }

            if (model.MinRent.HasValue)
            {
                properties = properties.Where(n => n.Rent >= model.MinRent.Value);
            }

            if (model.MaxRent.HasValue)
            {
                properties = properties.Where(n => n.Rent <= model.MaxRent.Value);
            }

            if (model.MinPremium.HasValue)
            {
                properties = properties.Where(n => n.Premium >= model.MinPremium.Value);
            }

            if (model.MaxPremium.HasValue)
            {
                properties = properties.Where(n => n.Premium <= model.MaxPremium.Value);
            }

            if (model.MinPrice.HasValue)
            {
                properties = properties.Where(n => n.AskingPrice >= model.MinPrice.Value);
            }

            if (model.MaxPrice.HasValue)
            {
                properties = properties.Where(n => n.AskingPrice <= model.MaxPrice.Value);
            }

            if (model.Search.IsSet())
            {
                properties = properties.Where(n =>
                                              n.Title.Contains(model.Search) ||
                                              n.Address1.Contains(model.Search) ||
                                              n.Address2.Contains(model.Search) ||
                                              n.City.Contains(model.Search) ||
                                              n.County.Contains(model.Search) ||
                                              n.Postcode.Contains(model.Search) ||
                                              n.ShortDescription.Contains(model.Search) ||
                                              n.Lease.Contains(model.Search) ||
                                              n.Location.Contains(model.Search) ||
                                              n.Planning.Contains(model.Search) ||
                                              n.Reference.Contains(model.Search)
                                              );
            }

            if (model.Order.IsSet())
            {
                switch (model.Order)
                {
                case "name":
                case "title":
                    properties = properties.OrderBy(n => n.Title);
                    break;

                case "date":
                    properties = properties.OrderBy(n => n.PublishDate);
                    break;

                case "views":
                    properties = properties.OrderBy(n => n.Views);
                    break;

                case "name+desc":
                case "title+desc":
                    properties = properties.OrderByDescending(n => n.Title);
                    break;

                case "date+desc":
                    properties = properties.OrderByDescending(n => n.PublishDate);
                    break;

                case "views+desc":
                    properties = properties.OrderByDescending(n => n.Views);
                    break;

                case "rent":
                    properties = properties.OrderBy(n => n.Rent);
                    break;

                case "planning":
                    properties = properties.OrderBy(n => n.Planning);
                    break;

                case "type":
                    properties = properties.OrderBy(n => n.ListingType);
                    break;

                case "premium":
                    properties = properties.OrderBy(n => n.Premium);
                    break;

                case "rent+desc":
                    properties = properties.OrderByDescending(n => n.Rent);
                    break;

                case "planning+desc":
                    properties = properties.OrderByDescending(n => n.Planning);
                    break;

                case "type+desc":
                    properties = properties.OrderByDescending(n => n.ListingType);
                    break;

                case "premium+desc":
                    properties = properties.OrderByDescending(n => n.Premium);
                    break;

                default:
                    properties = properties.OrderByDescending(n => n.PublishDate).ThenBy(n => n.Id);
                    break;
                }
            }

            model.AvailableTypes = await _db.Properties.Select(p => p.ListingType).Distinct().ToListAsync();

            model.AvailableStatuses = await _db.Properties.Select(p => p.LeaseStatus).Distinct().ToListAsync();

            model.AvailablePlanningTypes = await _db.Properties.Select(p => p.Planning).Distinct().ToListAsync();

            model.PlanningTypes = Engine.Settings.Property.GetPlanningTypes();

            await model.ReloadAsync(properties);

            if (model.List != null)
            {
                model.Locations   = model.List.Select(p => new MapMarker(p, p.Title, p.QuickInfo, p.Id.ToString(), p.Url, p.FeaturedImage.Url)).ToList();
                model.CentrePoint = GeoCalculations.GetCentralGeoCoordinate(model.Locations.Select(p => new GeoCoordinate(p.Latitude, p.Longitude)));
            }
            return(model);
        }