public void Handle(CreateEstablishmentType command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (string.IsNullOrWhiteSpace(command.PluralEnglishName))
            {
                const int pluralNumber = 2;
                var       template     = string.Format("{{{0}}}", command.EnglishName);

                // ReSharper disable PossiblyMistakenUseOfParamsMethod
                command.PluralEnglishName = Pluralizer.Instance.Pluralize(template, pluralNumber);
                // ReSharper restore PossiblyMistakenUseOfParamsMethod
            }

            var category = _entities.FindByPrimaryKey <EstablishmentCategory>(command.CategoryCode);
            var entity   = new EstablishmentType
            {
                CategoryCode      = category.Code,
                EnglishName       = command.EnglishName.Replace(" Or ", " or "),
                EnglishPluralName = command.PluralEnglishName,
            };

            _entities.Create(entity);
        }
Ejemplo n.º 2
0
        public GeoNamesFeature Handle(SingleGeoNamesFeature query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var result = _entities.FindByPrimaryKey <GeoNamesFeature>(query.Code);

            return(result);
        }
Ejemplo n.º 3
0
        public void Handle(CreateLanguageName command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var language = _entities.FindByPrimaryKey <Language>(command.LanguageId);

            language.Names.Add(new LanguageName
            {
                Number = language.Names.NextNumber(),
                Text   = command.Text,
                TranslationToLanguageId = command.TranslationToLanguageId,
            });

            _entities.Update(language);
        }
        public GeoPlanetPlaceType Handle(SingleGeoPlanetPlaceType query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            var result = _entities.FindByPrimaryKey <GeoPlanetPlaceType>(query.Code);

            if (result != null)
            {
                return(result);
            }

            result = _geoPlanet.Type(query.Code, RequestView.Long).ToEntity();
            _entities.Create(result);

            return(result);
        }
Ejemplo n.º 5
0
        public GeoNamesToponym Handle(SingleGeoNamesToponym query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            // first look in the db
            var toponym = _entities.FindByPrimaryKey <GeoNamesToponym>(query.GeoNameId);

            if (toponym != null)
            {
                return(toponym);
            }

            // invoke geonames service
            var geoNamesToponym = _geoNames.Get(query.GeoNameId);

            if (geoNamesToponym == null)
            {
                return(null);
            }

            // convert geonames type to entity
            toponym = geoNamesToponym.ToEntity();

            // map parent
            var geoNamesHierarchy = _geoNames.Hierarchy(query.GeoNameId, ResultStyle.Short);

            if (geoNamesHierarchy != null && geoNamesHierarchy.Items.Count > 1)
            {
                toponym.Parent = Handle(new SingleGeoNamesToponym(
                                            geoNamesHierarchy.Items[geoNamesHierarchy.Items.Count - 2].GeoNameId));
            }

            // ensure no duplicate features or time zones are added to the db
            toponym.Feature.Class = new HandleSingleGeoNamesFeatureClassQuery(_entities)
                                    .Handle(new SingleGeoNamesFeatureClass(toponym.Feature.ClassCode))
                                    ?? toponym.Feature.Class;

            toponym.Feature = new HandleSingleGeoNamesFeatureQuery(_entities)
                              .Handle(new SingleGeoNamesFeature(toponym.FeatureCode))
                              ?? toponym.Feature;

            toponym.TimeZone = new HandleSingleGeoNamesTimeZoneQuery(_entities)
                               .Handle(new SingleGeoNamesTimeZone(toponym.TimeZoneId))
                               ?? toponym.TimeZone;

            // map country
            var geoNamesCountries = GetGeoNamesCountries(_geoNames);
            var geoNamesCountry   = geoNamesCountries.SingleOrDefault(c => c.GeoNameId == query.GeoNameId);

            if (geoNamesCountry != null)
            {
                toponym.AsCountry = geoNamesCountry.ToEntity();
            }

            // map ancestors
            DeriveNodes(toponym);

            // add to db and save
            _entities.Create(toponym);
            if (!query.NoCommit)
            {
                _unitOfWork.SaveChanges();
            }

            return(toponym);
        }
Ejemplo n.º 6
0
        public GeoPlanetPlace Handle(SingleGeoPlanetPlace query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            // first look in the db
            var place = _entities.FindByPrimaryKey <GeoPlanetPlace>(query.WoeId);

            if (place != null)
            {
                return(place);
            }

            // invoke geoplanet service
            var geoPlanetPlace = _geoPlanet.Place(query.WoeId);

            if (geoPlanetPlace == null)
            {
                return(null);
            }

            // convert yahoo type to entity
            place = geoPlanetPlace.ToEntity();

            // map parent
            var ancestors = _geoPlanet.Ancestors(query.WoeId, RequestView.Long);

            if (ancestors != null && ancestors.Items.Count > 0)
            {
                place.Parent = Handle(new SingleGeoPlanetPlace(ancestors.First().WoeId));
            }

            // add all belongtos
            place.BelongTos = place.BelongTos ?? new List <GeoPlanetPlaceBelongTo>();
            var geoPlanetBelongTos = _geoPlanet.BelongTos(query.WoeId);

            if (geoPlanetBelongTos != null && geoPlanetBelongTos.Items.Count > 0)
            {
                var rank = 0;
                foreach (var geoPlanetBelongTo in geoPlanetBelongTos.Items)
                {
                    place.BelongTos.Add(new GeoPlanetPlaceBelongTo
                    {
                        Rank      = rank++,
                        BelongsTo = Handle(new SingleGeoPlanetPlace(geoPlanetBelongTo.WoeId))
                    });
                }
            }

            // ensure no duplicate place types are added to db
            place.Type = new SingleGeoPlanetPlaceTypeHandler(_entities, _geoPlanet)
                         .Handle(new SingleGeoPlanetPlaceType(place.Type.Code));

            // map ancestors
            DeriveNodes(place);

            // add to db and save
            _entities.Create(place);

            return(place);
        }
Ejemplo n.º 7
0
        public void Handle(SeedEstablishment command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var parent = command.ParentId.HasValue
                ? _entities.FindByPrimaryKey <Establishment>(command.ParentId.Value)
                : null;

            var type = _entities.FindByPrimaryKey <EstablishmentType>(command.TypeId);

            var entity = new Establishment
            {
                OfficialName = command.OfficialName,
                Parent       = parent,
                WebsiteUrl   = command.OfficialWebsiteUrl,
                IsMember     = command.IsMember,
                Type         = type,
                Location     = new EstablishmentLocation(),
                VerticalRank = command.VerticalRank
            };

            // add official name to list
            entity.Names.Add(new EstablishmentName
            {
                Text           = command.OfficialName,
                IsOfficialName = true
            });

            // add non-official names
            if (command.NonOfficialNames != null && command.NonOfficialNames.Any())
            {
                foreach (var nonOfficialName in command.NonOfficialNames)
                {
                    entity.Names.Add(new EstablishmentName
                    {
                        Text                  = nonOfficialName.Text,
                        IsFormerName          = nonOfficialName.IsDefunct,
                        TranslationToLanguage = nonOfficialName.TranslationToLanguageId.HasValue
                            ? _entities.FindByPrimaryKey <Language>(nonOfficialName.TranslationToLanguageId.Value)
                            : null,
                    });
                }
            }

            // add official url to list
            if (!string.IsNullOrWhiteSpace(command.OfficialWebsiteUrl))
            {
                entity.Urls.Add(new EstablishmentUrl
                {
                    Value         = command.OfficialWebsiteUrl,
                    IsOfficialUrl = true,
                });
            }

            // add non-official URL's
            if (command.NonOfficialUrls != null && command.NonOfficialUrls.Any())
            {
                foreach (var nonOfficialUrl in command.NonOfficialUrls)
                {
                    entity.Urls.Add(new EstablishmentUrl
                    {
                        Value       = nonOfficialUrl.Value,
                        IsFormerUrl = nonOfficialUrl.IsDefunct,
                    });
                }
            }

            // add email domains
            if (command.EmailDomains != null && command.EmailDomains.Any())
            {
                foreach (var emailDomain in command.EmailDomains)
                {
                    entity.EmailDomains.Add(new EstablishmentEmailDomain
                    {
                        Value = emailDomain,
                    });
                }
            }

            // apply coordinates
            if (command.FindPlacesByCoordinates &&
                command.CenterLatitude.HasValue && command.CenterLongitude.HasValue)
            {
                var woeId = _queryProcessor.Execute(new WoeIdByCoordinates(
                                                        command.CenterLatitude.Value, command.CenterLongitude.Value));
                var place  = _queryProcessor.Execute(new PlaceByWoeId(woeId));
                var places = place.Ancestors.OrderByDescending(n => n.Separation)
                             .Select(a => a.Ancestor).ToList();
                places.Add(place);
                entity.Location.Center      = new Coordinates(command.CenterLatitude, command.CenterLongitude);
                entity.Location.BoundingBox = place.BoundingBox;
                entity.Location.Places      = places;
            }

            // apply addresses
            if (command.Addresses != null && command.Addresses.Any())
            {
                foreach (var address in command.Addresses)
                {
                    entity.Location.Addresses.Add(new EstablishmentAddress
                    {
                        Text = address.Text,
                        TranslationToLanguage = _entities.FindByPrimaryKey <Language>(address.TranslationToLanguageId),
                    });
                }
            }

            // apply contact info
            if (command.PublicContactInfo != null)
            {
                entity.PublicContactInfo = new EstablishmentContactInfo
                {
                    Email = command.PublicContactInfo.Email,
                    Phone = command.PublicContactInfo.Phone,
                    Fax   = command.PublicContactInfo.Fax,
                };
            }

            // apply CEEB / UCosmic code
            if (!string.IsNullOrWhiteSpace(command.UCosmicCode))
            {
                entity.UCosmicCode = command.UCosmicCode;
            }


            _entities.Create(entity);
            _hierarchy.Handle(new UpdateEstablishmentHierarchy(entity));
            command.CreatedEstablishment = entity;
        }