public ActionResult Index(ComponentPresentation presentation, string Location = "", decimal Latitude = 0, decimal Longitude = 0, string Distance = null, bool clear = false, string Address = "", string NoJS = "", string WithinVal = null) { if (clear) { if (this.Logger.IsDebugEnabled) { this.Logger.Debug("Clearing session"); } base.RouteData.Values["Level1BrandActivated"] = false; base.RouteData.Values["BrandComponent"] = new Field(); base.RouteData.Values["BrandFilter"] = string.Empty; base.RouteData.Values["BrandFacet"] = string.Empty; base.RouteData.Values["BrandFacetValue"] = string.Empty; base.RouteData.Values["BrandValueForSearch"] = string.Empty; base.Session.ClearLevel1BrandFilter(); } bool flag = false; bool flag2 = false; if ((Latitude != 0M) && (Longitude != 0M)) { flag = true; } else if (string.IsNullOrEmpty(Location)) { flag2 = true; } string filterByBrandname = ""; if (!string.IsNullOrEmpty(base.Session.GetLevel1BrandFilter())) { filterByBrandname = base.RouteData.Values.GetLevel1BrandSearchValue(); } if (Distance == null) { Distance = WebConfiguration.Current.StoreLocatorDefaultValue; } StoreLocatorResults results = new StoreLocatorResults { DistanceItems = this.storelocatorrepository.GetDistanceItems(Distance), Distance = Convert.ToInt16(Distance) }; if (!string.IsNullOrEmpty(WebConfiguration.Current.StoreLocatorWithinVals)) { if (WithinVal != null) { results.WithinItems = this.storelocatorrepository.GetWithinItems(WithinVal); } else { results.WithinItems = this.storelocatorrepository.GetWithinItems(null); } } else { results.WithinItems = new List<SelectListItem>(); } GoogleMapsMarker marker = null; List<GoogleMapsMarker> markerForPostcode = new List<GoogleMapsMarker>(); if (!string.IsNullOrEmpty(Address)) { base.Session["SelectedAddress"] = Address; } else if ((string.IsNullOrEmpty(Address) && !string.IsNullOrEmpty(Location)) && (Location == (base.Session["SelectedAddress"] as string))) { Address = Location; } if ((flag && (NoJS != "true")) || (!string.IsNullOrEmpty(Address) && (NoJS == "true"))) { marker = new GoogleMapsMarker("current", Latitude, Longitude); if (!string.IsNullOrEmpty(Address)) { marker = this.setAddressOnMarker(Address, ',', marker); } results.Latitude = Latitude; results.Longitude = Longitude; } else if (string.IsNullOrEmpty(Location)) { results.Latitude = Convert.ToDecimal(WebConfiguration.Current.StoreLocatorLatitude, CultureInfo.InvariantCulture); results.Longitude = Convert.ToDecimal(WebConfiguration.Current.StoreLocatorLongitude, CultureInfo.InvariantCulture); } else { results.Location = Location; string culture = WebConfiguration.Current.Culture; string bias = ""; if (string.IsNullOrEmpty(WithinVal)) { bias = culture.Substring(culture.Length - 2); } else { bias = WithinVal; } markerForPostcode = this.storelocatorrepository.GetMarkerForPostcode(Location, bias); int result = 5; int.TryParse(WebConfiguration.Current.StoreLocatorMaxDisambigResults, out result); switch (markerForPostcode.Count) { case 0: results.Error = Helper.GetResource("StoreLocatorPostcodeNotFound"); break; case 1: if (markerForPostcode[0].type == "country") { results.Error = Helper.GetResource("StoreLocatorPostcodeNotFound"); break; } marker = markerForPostcode[0]; results.Latitude = marker.lat; Latitude = marker.lat; results.Longitude = marker.lng; Longitude = marker.lng; break; default: results.Options = markerForPostcode.GetRange(0, (markerForPostcode.Count >= result) ? result : markerForPostcode.Count); results.Latitude = Convert.ToDecimal(WebConfiguration.Current.StoreLocatorLatitude, CultureInfo.InvariantCulture); results.Longitude = Convert.ToDecimal(WebConfiguration.Current.StoreLocatorLongitude, CultureInfo.InvariantCulture); break; } } if (marker != null) { List<StoreLocatorRetailer> list2 = this.storelocatorrepository.GetStoreLocatorRetailers(marker, Convert.ToInt16(Distance), filterByBrandname); if (list2.Count > 0) { JavaScriptSerializer serializer = new JavaScriptSerializer(); results.Retailers = list2; results.RetailersJSON = serializer.Serialize(list2); results.StaticMapAddress = this.storelocatorrepository.GetStaticMap(marker, list2); } else { results.Error = Helper.GetResource("StoreLocatorNoRetailers"); } results.Location = this.getAddressFromLocation(marker); results.Latitude = marker.lat; results.Longitude = marker.lng; } this.SetComponentTypes(results); if (base.RouteData.Values.IsLevel1BrandFilterActivated()) { results.Brand = base.RouteData.Values.GetLevel1BrandComponent(); ((dynamic) base.ViewBag).StoreLocator = true; } return base.View(results); }
private void SetComponentTypes(StoreLocatorResults results) { results.ExtComponentSection = new ExtComponentSearchSection(); results.ExtComponentSection.ComponentTypes = FacetedContentHelper.GetComponentSchemaTypes("StoreLocator"); }