public static void AddLocationSettingsGroup(DataProxyBase dataProxy, BaseView view)
        {
            var group = view.GetOrCreateSettingGroup("Location Settings");

            group.AddSetting(new Setting("LocationSettingsHelp", "", SettingFieldType.Html, "<div class='col-xs-12 bg-info'><div class='col-xs-12'>Note: These settings are ignored if location settings are present in the page's query string.</div></div>"));
            group.AddSetting(new Setting("LocationContext", "Limit Results to Location", SettingFieldType.Dropdown) { Options = GetLocationContextOptions(dataProxy), Value = 0 });
            group.AddSetting(new Setting("LocationDescendants", "Include Child Locations", SettingFieldType.Boolean, true));
        }
 public static DescendantOption ResolveLocationDescendantOption(BaseView viewSettings, IDictionary<string, string> parameters)
 {
     if (parameters.ContainsKey("LocationDescendants") && !string.IsNullOrEmpty(parameters["LocationDescendants"]))
         return (bool.Parse(parameters["LocationDescendants"])) ? DescendantOption.IncludeDescendants : DescendantOption.NoDescendants;
     else
     {
         var locationDescendantsSetting = viewSettings.GetSettingValue("LocationDescendants", "true");
         return (bool.Parse(locationDescendantsSetting)) ? DescendantOption.IncludeDescendants : DescendantOption.NoDescendants;
     }
 }
        public static LocationContext ResolveLocationContext(DataProxyBase dataProxy, BaseView viewSettings, IDictionary<string, string> parameters)
        {
            int? locationId = null;
            string locationSiteUrl = null;

            // First look for location context in request parameters
            if (parameters != null && parameters.ContainsKey("LocationContext") && !string.IsNullOrEmpty(parameters["LocationContext"]))
                locationId = int.Parse(parameters["LocationContext"]);
            else
            {
                if (viewSettings != null)
                {
                    // Next look at module instance setting
                    var locationContextSetting = viewSettings.GetSettingValue("LocationContext", null);

                    if (!string.IsNullOrEmpty(locationContextSetting))
                        locationId = int.Parse(locationContextSetting);
                }
            }

            // Get full context using locationId or request URL
            //if (viewSettings != null && parameters != null)
            //{
            //	locationId = dataProxy.LocationContext.Id;
            //	locationSiteUrl = dataProxy.LocationContext.SiteUrl;
            //}
            //else
            //{
                var request = new ResolveOrgUnitContextRequest() { ItemUrl = ServiceContext.RequestReferrerUrl, OrgUnitId = locationId };
                var response = dataProxy.ProcessRequest<ResolveOrgUnitContextResponse>(request);

                locationId = response.OrgUnitId;
                locationSiteUrl = response.OrgUnitSiteUrl;
            //}

            return new LocationContext(locationId, locationSiteUrl);
        }
 public static void SubmitLeadDataAsync(BrightWhistleLead lead, DataProxyBase dataProxy, BaseView viewSettings, IDictionary<string, string> parameters)
 {
     var locationContextId = LocationContextHelper.ResolveLocationContext(dataProxy, viewSettings, parameters).Id;
     lead.SourceUrl = ServiceContext.RequestReferrerUrl;
     ThreadPool.QueueUserWorkItem(c => SubmitLeadData(lead, locationContextId, dataProxy));
 }