public PropertiesViewModel Build(PropertiesQuery query, bool isUserSeller)
        {
            var properties = _context.Properties
                             .Where(p => p.IsListedForSale);

            if (!string.IsNullOrWhiteSpace(query.Search))
            {
                properties = properties.Where(x => x.StreetName.Contains(query.Search) ||
                                              x.Description.Contains(query.Search));
            }

            return(new PropertiesViewModel
            {
                IsSeller = isUserSeller,
                Properties = properties
                             .ToList()
                             .Select(MapViewModel)
                             .ToList(),
                Search = query.Search
            });
        }
        public PropertiesViewModel Build(PropertiesQuery query)
        {
            var properties = _context.Properties
                             .Where(p => p.IsListedForSale);

            if (!string.IsNullOrWhiteSpace(query.Search))
            {
                properties = properties.Where(x => x.StreetName.Contains(query.Search) ||
                                              x.Description.Contains(query.Search));
            }

            return(new PropertiesViewModel
            {
                Properties = properties
                             .Include(x => x.Offers)
                             .Include(x => x.Appointments)
                             .ToList()
                             .Select(MapViewModel)
                             .ToList(),
                Search = query.Search
            });
        }
Esempio n. 3
0
        public PropertiesViewModel Build(PropertiesQuery query, string currentUserId)
        {
            var properties = _context.Properties
                             .Where(p => p.IsListedForSale && p.SellerUserId != currentUserId);

            if (!string.IsNullOrWhiteSpace(query.Search))
            {
                properties = properties.Where(x => (x.StreetName.Contains(query.Search) ||
                                                    x.Description.Contains(query.Search)) && x.SellerUserId != currentUserId);
            }



            return(new PropertiesViewModel
            {
                Properties = properties
                             .ToList()
                             .Select(MapViewModel)
                             .ToList(),
                Search = query.Search
            });
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public PropertiesViewModel Build(PropertiesQuery query)
        {
            // Discussion point: implicit or explicit declaration?
            //var properties = _context.Properties
            IQueryable <Models.Property> properties = _context.Properties
                                                      .Where(p => p.IsListedForSale);

            if (!string.IsNullOrWhiteSpace(query.Search))
            {
                properties = properties.Where(x => x.StreetName.Contains(query.Search) ||
                                              x.Description.Contains(query.Search));
            }

            return(new PropertiesViewModel
            {
                Properties = properties
                                        //.ToList() redundant use of ToList
                             .Select(MapViewModel)
                             .ToList(), // TODO: undesirable use of ToList here - suppose there are a million properties...
                                        // needs refactoring to return an IEnumerable so views can load properties on demand
                Search = query.Search
            });
        }
Esempio n. 5
0
        public PropertiesViewModel Build(PropertiesQuery query)
        {
            //var properties = _context.Properties
            //    .Where(p => p.IsListedForSale);

            var properties = _context.CompletePropertiesDetails().Where(p => p.IsListedForSale);


            if (!string.IsNullOrWhiteSpace(query.Search))
            {
                properties = properties.Where(x => x.StreetName.Contains(query.Search) ||
                                              x.Description.Contains(query.Search));
            }

            return(new PropertiesViewModel
            {
                Properties = properties
                             .ToList()
                             .Select(d => MapViewModel(d, _userId))
                             .ToList(),
                Search = query.Search
            });
        }
        public PropertiesViewModel Build(PropertiesQuery query)
        {
            var properties = _context.Properties
                             .Where(p => p.IsListedForSale)
                             .Include(o => o.Offers)
                             .Include(v => v.Viewings);

            if (!string.IsNullOrWhiteSpace(query.Search))
            {
                properties = properties.Where(x => x.StreetName.Contains(query.Search) ||
                                              x.Description.Contains(query.Search));
            }

            return(new PropertiesViewModel
            {
                // Show properties ordered by accepted offers first.
                Properties = properties
                             .ToList()
                             .Select(p => MapViewModel(p, query.UserId))
                             .OrderByDescending(p => p.BuyerOfferAccepted != null)
                             .ToList(),
                SearchQuery = query
            });
        }