예제 #1
0
        public static MarkerCollection GetDistinctCustomFields(int moduleId, int maxPoints)
        {
            MarkerCollection customFields = new MarkerCollection();
            MarkerQuery      q            = new MarkerQuery();

            q.Select(q.CustomField, q.ModuleId);

            q.Where(q.ModuleId == moduleId);
            q.Where(q.Latitude.IsNotNull() && q.Longitude.IsNotNull() && q.CustomField != "");

            q.es.Distinct = true;
            q.OrderBy(q.CustomField.Ascending);

            customFields.Load(q);

            return(customFields);
        }
예제 #2
0
        public static MarkerCollection GetMarkersByCountry(int moduleId, string customField, string country, int maxPoints)
        {
            MarkerCollection markers = new MarkerCollection();
            MarkerQuery      q       = new MarkerQuery();

            q.Where(q.ModuleId == moduleId);
            q.Where(q.Country == country);

            if (!String.IsNullOrEmpty(customField))
            {
                q.Where(q.CustomField == customField);
            }

            q.Where(q.Latitude.IsNotNull() && q.Longitude.IsNotNull());

            markers.Load(q);

            return(markers);
        }
예제 #3
0
        private IEnumerable <Marker> GetModuleMarkers(int targetModule)
        {
            MarkerCollection markers = new MarkerCollection();
            MarkerQuery      q       = new MarkerQuery();

            q.Where(q.ModuleId == targetModule);

            markers.Load(q);

            return(markers);
        }
예제 #4
0
        private static MarkerCollection GetMarkersByModuleId(int moduleId)
        {
            MarkerCollection markers = new MarkerCollection();
            MarkerQuery      q       = new MarkerQuery();

            q.Where(q.ModuleId == moduleId);
            q.OrderBy(q.Title.Ascending);
            markers.Load(q);

            return(markers);
        }
예제 #5
0
        public static MarkerCollection FilterByCustomField(int moduleId, string customField, string country, string state, string city, int maxPoints)
        {
            MarkerCollection states = new MarkerCollection();
            MarkerQuery      q      = new MarkerQuery();

            q.Select(q.Country, q.ModuleId, q.Region, q.City);

            q.Where(q.ModuleId == moduleId);
            q.Where(q.CustomField == customField);

            if (!String.IsNullOrEmpty(country))
            {
                q.Where(q.Country == country);
            }

            if (!String.IsNullOrEmpty(state))
            {
                q.Where(q.Region == state);
            }

            if (!String.IsNullOrEmpty(city))
            {
                q.Where(q.City == city);
            }
            q.Where(q.Latitude.IsNotNull() && q.Longitude.IsNotNull());

            q.es.Distinct = true;
            q.OrderBy(q.Country.Ascending);

            states.Load(q);

            return(states);
        }
예제 #6
0
        public static MarkerCollection GetMarkersByCustomField(int moduleId, string customField, string country, string state, string city, int maxPoints)
        {
            MarkerCollection markers = new MarkerCollection();
            MarkerQuery      q       = new MarkerQuery();

            q.Where(q.ModuleId == moduleId);

            if (!String.IsNullOrEmpty(customField))
            {
                q.Where(q.CustomField.Like(String.Format("%{0}%", customField)));
                //q.Where(q.CustomField == customField);
            }

            if (!String.IsNullOrEmpty(country))
            {
                q.Where(q.Country == country);
            }

            if (!String.IsNullOrEmpty(state))
            {
                q.Where(q.Region == state);
            }

            if (!String.IsNullOrEmpty(city))
            {
                q.Where(q.City == city);
            }

            q.Where(q.Latitude.IsNotNull() && q.Longitude.IsNotNull());

            markers.Load(q);

            return(markers);
        }
예제 #7
0
        public static MarkerCollection GetMarkersByState(int moduleId, string customField, string country, string state, int maxPoints, int?markerId)
        {
            MarkerCollection markers = new MarkerCollection();
            MarkerQuery      q       = new MarkerQuery();

            q.Where(q.ModuleId == moduleId);

            if (!String.IsNullOrEmpty(customField))
            {
                q.Where(q.CustomField == customField);
            }

            if (!String.IsNullOrEmpty(country))
            {
                q.Where(q.Country == country);
            }

            if (!String.IsNullOrEmpty(state))
            {
                q.Where(q.Region == state);
            }

            if (markerId != null)
            {
                q.Where(q.MarkerId == markerId.Value);
            }

            q.es.Top = maxPoints;

            q.Where(q.Latitude.IsNotNull() && q.Longitude.IsNotNull());

            markers.Load(q);

            return(markers);
        }
예제 #8
0
        public static MarkerCollection GetTopMarkerByModuleId(int moduleId)
        {
            var markerQuery      = new MarkerQuery();
            var markerCollection = new MarkerCollection();

            markerQuery.es.Top = 1;
            markerQuery.Where(markerQuery.ModuleId == moduleId && markerQuery.Latitude.IsNull() && markerQuery.Longitude.IsNull());

            markerCollection.Query.es.Top = 1; // Not sure if the first "Top" assignment took care of this
            markerCollection.Load(markerQuery);

            return(markerCollection);
        }
예제 #9
0
        public static MarkerCollection GetDistinctCountriesByCustomField(int moduleId, int maxPoints, string customField)
        {
            MarkerCollection countries = new MarkerCollection();
            MarkerQuery      q         = new MarkerQuery();

            q.Select(q.Country, q.ModuleId);

            q.Where(q.ModuleId == moduleId);

            if (!String.IsNullOrEmpty(customField))
            {
                q.Where(q.CustomField == customField);
            }

            q.Where(q.Latitude.IsNotNull() && q.Longitude.IsNotNull());

            q.es.Distinct = true;
            q.OrderBy(q.Country.Ascending);

            countries.Load(q);

            return(countries);
        }
예제 #10
0
        public List <ViewAbleMarker> LoadMarkers(int moduleId, string customFieldFilter = "")
        {
            var markers          = new List <ViewAbleMarker>();
            var markerQuery      = new MarkerQuery();
            var markerCollection = new MarkerCollection();

            markerQuery.Where(markerQuery.ModuleId == moduleId && markerQuery.Latitude.IsNotNull() && markerQuery.Longitude.IsNotNull()).OrderBy("Priority").OrderBy(markerQuery.Title.Ascending);

            if (HidePointsOnPageLoad)
            {
                MaxPoints          = 0;
                markerQuery.es.Top = MaxPoints;
            }

            if (!string.IsNullOrEmpty(customFieldFilter))
            {
                markerQuery.Where(markerQuery.CustomField.Like(String.Format("%{0}%", customFieldFilter)));
            }

            markerCollection.Load(markerQuery);
            markerCollection.ToList().ForEach(marker => markers.Add(new ViewAbleMarker(marker)));
            return(markers);
        }
예제 #11
0
        private string ParseCsvFile()
        {
            var    fileName = Settings[ModuleSettingNames.FileName];
            var    filePath = HttpContext.Current.Server.MapPath(String.Format("{0}Maps/uploads/{1}", ModuleWebPath, fileName));
            string status   = string.Empty;

            if (!File.Exists(filePath))
            {
                status = String.Format("File {0} doesn't exist. Please upload a CSV file in the module settings.", fileName);
                return(status);
            }

            var csvOptions = new CsvReaderOptions()
            {
                HasHeaderRecord = true, Strict = false
            };
            var parser = new CsvParser(new StreamReader(filePath));
            var reader = new CsvReader(parser, csvOptions);

            // Get header names
            var address1       = (string)(Settings[ModuleSettingNames.Address1] ?? ModuleSettingNames.Address1);
            var address2       = (string)(Settings[ModuleSettingNames.Address2] ?? ModuleSettingNames.Address2);
            var city           = (string)(Settings[ModuleSettingNames.City] ?? ModuleSettingNames.City);
            var country        = (string)(Settings[ModuleSettingNames.Country] ?? ModuleSettingNames.Country);
            var iconUrl        = (string)(Settings[ModuleSettingNames.IconUrl] ?? ModuleSettingNames.IconUrl);
            var iconShadowUrl  = (string)(Settings[ModuleSettingNames.IconShadowUrl] ?? ModuleSettingNames.IconShadowUrl);
            var infoWindowHtml = (string)(Settings[ModuleSettingNames.InfoWindowHtml] ?? ModuleSettingNames.InfoWindowHtml);
            var latitude       = (string)(Settings[ModuleSettingNames.Latitude] ?? ModuleSettingNames.Latitude);
            var longitude      = (string)(Settings[ModuleSettingNames.Longitude] ?? ModuleSettingNames.Longitude);
            var postalCode     = (string)(Settings[ModuleSettingNames.PostalCode] ?? ModuleSettingNames.PostalCode);
            var region         = (string)(Settings[ModuleSettingNames.Region] ?? ModuleSettingNames.Region);
            var title          = (string)(Settings[ModuleSettingNames.Title] ?? ModuleSettingNames.Title);
            var customField    = (string)(Settings[ModuleSettingNames.CustomField] ?? ModuleSettingNames.CustomField);
            var priority       = (string)(Settings[ModuleSettingNames.Priority] ?? ModuleSettingNames.Priority);
            var phoneNumber    = (string)(Settings[ModuleSettingNames.PhoneNumber] ?? ModuleSettingNames.PhoneNumber);

            // Delete old markers
            var markerQuery = new MarkerQuery();

            markerQuery.Where(markerQuery.ModuleId == ModuleId);

            var markerCollection = new MarkerCollection();

            markerCollection.Load(markerQuery);
            markerCollection.MarkAllAsDeleted();
            markerCollection.Save();


            while (reader.Read())
            {
                // Add new markers to db from csv
                try
                {
                    var marker = new Marker
                    {
                        ModuleId       = ModuleId,
                        Title          = reader.GetField(title),
                        InfoWindowHtml = reader.GetField(infoWindowHtml),
                        Address1       = reader.GetField(address1),
                        Address2       = reader.GetField(address2),
                        City           = reader.GetField(city),
                        Region         = reader.GetField(region),
                        PostalCode     = reader.GetField(postalCode),
                        Country        = reader.GetField(country),
                        Latitude       = WA.Parser.ToDouble(reader.GetField(latitude)),
                        Longitude      = WA.Parser.ToDouble(reader.GetField(longitude)),
                        IconUrl        = reader.GetField(iconUrl),
                        IconShadowUrl  = reader.GetField(iconShadowUrl),
                        CustomField    = reader.GetField(customField),
                        PhoneNumber    = reader.GetField(phoneNumber),
                        Priority       = (reader.GetField(priority) == "" || reader.GetField(priority) == null) ? "zzzz" : reader.GetField(priority)
                    };

                    marker.Save();

                    if (!marker.Latitude.HasValue && !marker.Longitude.HasValue)
                    {
                        _markers.Add(marker);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            status  = String.Format("<h1>File {0} parsed successfully</h1><hr />", fileName);
            status += GeocodeMarkerList(_markers);

            return(status);
        }