//Searchs for properties in DB
        private SearchResultsViewModel SearchForExactAddressLocation(SearchCompare array)
        {
            var property = db.Properties.Where(c => (c.streetaddress == array.streetaddress)
                && ((c.route == array.route) || (c.route == array.route_long))).Select(x => new SearchResultsViewModel
                {
                    formatted_address = x.formatted_address,
                    propertyID = x.propertyID,
                    numofReviews = x.Reviews.Count(),
                    averagerating = (double?)(x.Reviews.Select(b => b.rating).Average()) ?? 0.0
                }).FirstOrDefault();

            return property;
        }
        private SearchCompare MapProperties(IEnumerable<GoogleAddress> g)
        {
            var results = new SearchCompare();

            foreach (var item in g.First().Components)
            {
                if (item.Types.First() == GoogleAddressType.StreetNumber) { results.streetaddress = item.ShortName; }
                if (item.Types.First() == GoogleAddressType.Route) { results.route = item.ShortName; results.route_long = item.LongName; }
                if (item.Types.First() == GoogleAddressType.Locality) { results.city = item.ShortName; results.city_long = item.LongName; }
                if (item.Types.First() == GoogleAddressType.AdministrativeAreaLevel1) { results.state = item.ShortName; }
                if (item.Types.First() == GoogleAddressType.Country) { results.country = item.ShortName; }
                if (item.Types.First() == GoogleAddressType.PostalCode) { results.zip = item.ShortName; }
            }
            results.formatted_address = g.First().FormattedAddress;
            results.latitude = (decimal)g.First().Coordinates.Latitude;
            results.longitude = (decimal)g.First().Coordinates.Longitude;
            results.type = g.First().Type;

            return results;
        }
        private List<SearchResultsViewModel> SearchAllRelatedProperties(SearchCompare array, int id)
        {
            var coord = new GeoCoordinate { Latitude = (double?)array.latitude ?? 0, Longitude = (double?)array.longitude ?? 0 };
            var property = db.Properties.Select(x => new SearchResultsViewModel
                {
                    propertyID = x.propertyID,
                    formatted_address = x.formatted_address,
                    numofReviews = x.Reviews.Count(),
                    averagerating = (double?)(x.Reviews.Select(b => b.rating).Average()) ?? 0.0,
                    latitude = x.latitude,
                    longitude = x.longitude,
                    geocoord = new GeoCoordinate { Latitude = (double?)x.latitude ?? 0, Longitude = (double?)x.longitude ?? 0 },
                    type = "exact"
                })
                .Where(x => x.propertyID != id)
                .AsEnumerable()
                .OrderBy(x => x.geocoord.GetDistanceTo(coord))
                .Take(500).ToList();

            /*
            var property = db.Database.SqlQuery<Property>("SearchReviews_StreetAddress_Related @lat, @lon, @propertyid",
            new SqlParameter("@lat", array.latitude),
            new SqlParameter("@lon", array.longitude),
            new SqlParameter("@propertyid", array.propertyID)).
               .ToList();
             * */

            return property;
        }
        //Prepares the exact address property object for view
        //If the address exists in DB, configure its lat/lng
        //If it doesnt, configure it for the view and give its needed data for the view.
        private SearchResultsViewModel ConfigureExactAddressForView(SearchCompare geocodedAddress)
        {
            Geography locationData;
            var exactproperty = SearchForExactAddressLocation(geocodedAddress);
            if (exactproperty != null)
            {
                exactproperty.type = "exact";

                if (exactproperty.latitude == 0m)
                {
                    locationData = GetLatLng(exactproperty.formatted_address);
                    if (locationData != null)
                    {
                        exactproperty.latitude = locationData.latitude;
                        exactproperty.longitude = locationData.longitude;
                    }
                }
                return exactproperty;
            }
            else
            {
                SearchResultsViewModel V1 = new SearchResultsViewModel();
                V1.propertyID = 0;
                V1.formatted_address = geocodedAddress.formatted_address;
                V1.latitude = geocodedAddress.latitude;
                V1.longitude = geocodedAddress.longitude;
                V1.type = "exact-new";

                return V1;
            }
        }