public Guid Create(string LocationTypeName)
        {
            LocationType newLocType = new LocationType();
            newLocType.Name = LocationTypeName;
            Repositories.LocationTypeRepo.Insert(newLocType);

            //var Result = Repositories.LocationTypeRepo.GetByKey(newLocType.Key);
            var Result = newLocType.Key;

            return Result;
        }
        /// <summary>
        /// The get empty default location type definition.
        /// </summary>
        /// <returns>
        /// The <see cref="ILocationTypeDefinition"/>.
        /// </returns>
        public ILocationType GetEmptyDefaultLocationTypeDefinition()
        {
            var def = new LocationType()
                       {
                           Id = Constants.DefaultLocationTypeId,
                           Name = "Default",
                           Fields = new CustomFieldsCollection()
                       };

            //TODO: HLF - this needs to be fixed...
            def.Fields.SetValue(new CustomField() { Label = "Address 1", Alias = Constants.DefaultLocPropertyAlias.Address1, PropertyEditorAlias = Constants.PropertyEditorAlias.TextBox, SortOrder = 1 });
            def.Fields.SetValue(new CustomField() { Label = "Address 2", Alias = Constants.DefaultLocPropertyAlias.Address2, PropertyEditorAlias = Constants.PropertyEditorAlias.TextBox, SortOrder = 2 });
            def.Fields.SetValue(new CustomField() { Label = "Locality", Alias = Constants.DefaultLocPropertyAlias.Locality, PropertyEditorAlias = Constants.PropertyEditorAlias.TextBox, SortOrder = 3 });
            def.Fields.SetValue(new CustomField() { Label = "Region", Alias = Constants.DefaultLocPropertyAlias.Region, PropertyEditorAlias = Constants.PropertyEditorAlias.TextBox, SortOrder = 4 });
            def.Fields.SetValue(new CustomField() { Label = "Country", Alias = Constants.DefaultLocPropertyAlias.CountryCode, PropertyEditorAlias = Constants.PropertyEditorAlias.DropDownList, SortOrder = 5 });
            def.Fields.SetValue(new CustomField() { Label = "Region", Alias = Constants.DefaultLocPropertyAlias.PostalCode, PropertyEditorAlias = Constants.PropertyEditorAlias.TextBox, SortOrder = 6 });

            return def;
        }
        public JsonLocationType(LocationType ConvertedFromLocationType)
        {
            this.Key = ConvertedFromLocationType.Key;
            this.Name = ConvertedFromLocationType.Name;
            this.Description = ConvertedFromLocationType.Description;
            this.Icon = ConvertedFromLocationType.Icon;
            this.Properties = new List<JsonTypeProperty>();
            foreach (var Prop in ConvertedFromLocationType.Properties.OrderBy(p => p.SortOrder))
            {
                var JsonProp = new JsonTypeProperty();

                JsonProp.PropAlias = Prop.Alias;
                JsonProp.PropName = Prop.Name;
                JsonProp.PropType = Prop.DataTypeId;
                JsonProp.IsDefaultProp = Prop.IsDefaultProp;
                JsonProp.Key = Prop.Key;
                JsonProp.SortOrder = Prop.SortOrder;
                this.Properties.Add(JsonProp);
            }
        }
Beispiel #4
0
        public LocationType ToLocationTypeEntity(LocationTypeDto dto)
        {
            var Entity = new LocationType()
            {
                Key = dto.Key,
                Name = dto.Name,
                Description = dto.Description,
                Icon = dto.Icon,
                UpdateDate = dto.UpdateDate,
                CreateDate = dto.CreateDate
            };

            return Entity;
        }
Beispiel #5
0
        public LocationTypeDto ToLocationTypeDto(LocationType entity)
        {
            var dto = new LocationTypeDto()
            {
                Key = entity.Key,
                Name = entity.Name,
                Description = entity.Description,
                Icon = entity.Icon,
                UpdateDate = entity.UpdateDate,
                CreateDate = entity.CreateDate
            };

            return dto;
        }
        private LocationType CreateNew()
        {
            //Create new entity
            var Entity = new LocationType()
            {
                Key = this.Key,
                Name = this.Name,
                Description = this.Description,
                Icon = this.Icon,
            };

            return Entity;
        }
Beispiel #7
0
        private static StatusMessage ImportRow(DataRow row, LocationType LocType, int GeocodeCount, DataColumnCollection ImportColumns, out int geocodeCountReturn)
        {
            string locName = row.Field<string>("LocationName");

            var ReturnMsg = new StatusMessage();
            ReturnMsg.ObjectName = locName;
            ReturnMsg.Success = true;
            var Msg = new StringBuilder();
            var geocodeCountNew = GeocodeCount;

            //Create new Location for row
            var newLoc = new Location(locName, LocType.Key);
            Repositories.LocationRepo.Insert(newLoc);

            try
            {
                //Default Props
                var locationTypeService = new LocationTypeService();
                var defaultLocType = locationTypeService.GetLocationType(Constants.DefaultLocationTypeKey);
                foreach (var prop in defaultLocType.Properties)
                {
                    string colName = prop.Alias;
                    if (ImportColumns.Contains(colName))
                    {
                        newLoc.AddPropertyData(colName, row.Field<object>(colName));
                    }
                    else
                    {
                        newLoc.AddPropertyData(colName, null);
                        Msg.AppendLine(string.Concat("Data for '", colName, "' was not included in the import file."));
                    }
                }

                //Custom Props
                if (LocType.Key != defaultLocType.Key)
                {
                    foreach (var prop in LocType.Properties)
                    {
                        string colName = prop.Alias;

                        if (ImportColumns.Contains(colName))
                        {
                            newLoc.AddPropertyData(colName, row.Field<object>(colName));
                        }
                        else
                        {
                            newLoc.AddPropertyData(colName, null);
                            Msg.AppendLine(string.Concat("Data for '", colName, "' was not included in the import file."));
                        }
                    }
                }

                // SAVE properties of new location to db
                try
                {
                    Repositories.LocationRepo.Update(newLoc);
                }
                catch (Exception eSave)
                {
                    ReturnMsg.Success = false;
                    ReturnMsg.RelatedException = eSave;
                    ReturnMsg.Code = ReturnMsg.Code != "" ? ReturnMsg.Code + ",InsertError" : "InsertError";
                    Msg.AppendLine("There was a problem saving the new location data.");
                }

                //Check for Lat/Long values - import if present
                if (ImportColumns.Contains("Latitude"))
                {
                    int convertedInt = 0;
                    Int32.TryParse(row.Field<string>("Latitude"), out convertedInt);
                    newLoc.Latitude = convertedInt;
                }

                if (ImportColumns.Contains("Longitude"))
                {
                    int convertedInt = 0;
                    Int32.TryParse(row.Field<string>("Longitude"), out convertedInt);
                    newLoc.Longitude = convertedInt;
                }

                //If Lat/Long are both 0... attempt geocoding
                if (newLoc.Latitude == 0 && newLoc.Longitude == 0)
                {
                    //TODO: make dynamic based on provider limit
                    if (GeocodeCount >= MAX_GEOCODE)
                    {
                        ReturnMsg.Success = true;
                        ReturnMsg.Code = "GeocodingProblem";
                        Msg.AppendLine(
                            "This address exceeded the limits for geo-coding in a batch. Please run maintenance to update geo-codes later.");
                    }
                    else
                    {
                        try
                        {
                            var newCoordinate = DoGeocoding.GetCoordinateForAddress(newLoc.Address);
                            newLoc.Latitude = newCoordinate.Latitude;
                            newLoc.Longitude = newCoordinate.Longitude;

                            geocodeCountNew++;
                        }
                        catch (Exception e1)
                        {
                            ReturnMsg.Success = true;
                            ReturnMsg.RelatedException = e1;
                            ReturnMsg.Code = "GeocodingProblem";
                            Msg.AppendLine(
                                "There was a problem geo-coding the address. Please run maintenance to update geo-codes later.");
                            LogHelper.Error(
                                typeof(Import),
                                string.Format("Geo-coding error while importing '{0}'", ReturnMsg.ObjectName),
                                e1);
                        }
                    }
                }

                // SAVE properties of new location to db again
                try
                {
                    Repositories.LocationRepo.Update(newLoc);
                }
                catch (Exception eSave)
                {
                    ReturnMsg.Success = false;
                    ReturnMsg.RelatedException = eSave;
                    ReturnMsg.Code = ReturnMsg.Code != "" ? ReturnMsg.Code + ",InsertError" : "InsertError";
                    Msg.AppendLine("There was a problem saving the new location data.");
                }

                // UPDATE Geography DB field using Lat/Long
                try
                {
                    if (newLoc.Latitude != 0 && newLoc.Longitude != 0)
                    {
                        Repositories.LocationRepo.UpdateDbGeography(newLoc);
                    }
                    else
                    {
                        newLoc.DbGeogNeedsUpdated = true;
                        Repositories.LocationRepo.Update(newLoc);
                    }
                }
                catch (Exception eGeoDB)
                {
                    ReturnMsg.Success = true;
                    ReturnMsg.RelatedException = eGeoDB;
                    ReturnMsg.Code = ReturnMsg.Code != "" ? ReturnMsg.Code + ",UnableToUpdateDBGeography" : "UnableToUpdateDBGeography";
                    Msg.AppendLine("Unable to update the coordinates in the database.");
                }

            }
            catch (Exception ex)
            {
                ReturnMsg.Success = false;
                ReturnMsg.RelatedException = ex;
                ReturnMsg.Code = ReturnMsg.Code != "" ? ReturnMsg.Code + ",UnknownException" : "UnknownException";
                Msg.AppendLine(ex.Message);
                LogHelper.Error(typeof(Import), string.Format("ImportRow: Error importing location '{0}'", locName), ex);
            }

            ReturnMsg.Message = Msg.ToString();

            geocodeCountReturn = geocodeCountNew;

            return ReturnMsg;
        }
        public IEnumerable<LocationType> TestPopulateSomeLocationTypes()
        {
            int NewItemId = 0;
            string Msg = "";

            //TEST Add "Business" location type with 2 properties
            var NewItem1 = new LocationType();
            NewItem1.Name = "Business";
            NewItem1.AddProperty("BusinessWebsite", "Business Website URL", uLocate.Constants.DataTypeId.TextBox);
            NewItem1.AddProperty("BusinessHours", "Hours of Operation", uLocate.Constants.DataTypeId.TextBoxMultiple);
            Repositories.LocationTypeRepo.Insert(NewItem1);
            Msg += string.Format("Type '{0}' added. ", NewItem1.Name);

            //TEST Add "Shopping Center" location type with 2 properties
            var NewItem2 = new LocationType();
            NewItem2.Name = "Shopping Center";
            NewItem2.AddProperty("SCName", "Shopping Center Name", uLocate.Constants.DataTypeId.TextBox);
            NewItem2.AddProperty("SCHours", "Hours of Operation", uLocate.Constants.DataTypeId.TextBoxMultiple);
            Repositories.LocationTypeRepo.Insert(NewItem2);
            Msg += string.Format("Type '{0}' added. ", NewItem2.Name);

            //TEST: Return all Location Types
            var Result = Repositories.LocationTypeRepo.GetAll();

            return Result;
        }