private static void MapToDB(MC.GeoCoordinates from, EM.GeoCoordinate to) { to.Id = from.Id; to.JurisdictionId = from.ParentId; to.Name = from.Name; to.IsException = from.IsException; to.AddressRegion = from.Region; to.Country = from.Country; to.Latitude = from.Latitude; to.Longitude = from.Longitude; to.Url = from.GeoURI; if (from.GeoNamesId > 0) { to.GeoNamesId = from.GeoNamesId; } else { //extract from "http://geonames.org/6255149/" string geoNamesId = UtilityManager.ExtractNameValue(from.GeoURI, ".org", "/", "/"); if (IsInteger(geoNamesId)) { to.GeoNamesId = Int32.Parse(geoNamesId); } } }
} // #endregion #endregion #region GeoCoordinate ======================= #region GeoCoordinate Core ======================= public int GeoCoordinates_Add(MC.GeoCoordinates entity, int jpId, ref SaveStatus status) { if (entity == null || string.IsNullOrWhiteSpace(entity.GeoURI)) { return(0); } entity.ParentId = jpId; EM.GeoCoordinate efEntity = new EM.GeoCoordinate(); MC.GeoCoordinates existing = new MC.GeoCoordinates(); List <String> messages = new List <string>(); //extract from "http://geonames.org/6255149/" string geoNamesId = UtilityManager.ExtractNameValue(entity.GeoURI, ".org", "/", "/"); if (IsInteger(geoNamesId)) { entity.GeoNamesId = Int32.Parse(geoNamesId); } if (GeoCoordinates_Exists(entity.ParentId, entity.GeoNamesId, entity.IsException)) { status.AddWarning("Error this Region has aleady been selected."); return(0); } else { MapToDB(entity, efEntity); //ensure parent jp Id is present return(GeoCoordinate_Add(efEntity, ref status)); } }
// /// <summary> /// get all related GeoCoordinates for the parent /// </summary> /// <param name="parentId"></param> /// <returns></returns> public static List <MC.GeoCoordinates> GetAll(int parentId, bool isException = false) { MC.GeoCoordinates entity = new MC.GeoCoordinates(); List <MC.GeoCoordinates> list = new List <MC.GeoCoordinates>(); if (parentId == 0) { return(list); } using (var context = new EntityContext()) { List <EM.GeoCoordinate> Items = context.GeoCoordinate .Where(s => s.JurisdictionId == parentId && s.IsException == isException) .OrderBy(s => s.Id).ToList(); if (Items.Count > 0) { foreach (EM.GeoCoordinate item in Items) { entity = new MC.GeoCoordinates(); MapFromDB(item, entity); list.Add(entity); } } } return(list); }
private static void MapFromDB(EM.GeoCoordinate from, MC.GeoCoordinates to) { to.Id = from.Id; to.ParentId = (int)from.JurisdictionId; to.GeoNamesId = from.GeoNamesId != null ? ( int )from.GeoNamesId : 0; to.Name = from.Name; to.IsException = from.IsException != null ? ( bool )from.IsException : false; to.Region = from.AddressRegion; to.Country = from.Country; if (from.Latitude != null) { to.Latitude = (double)from.Latitude; } if (from.Longitude != null) { to.Longitude = ( double )from.Longitude; } to.GeoURI = from.Url; to.ProfileSummary = to.Name; if (!string.IsNullOrWhiteSpace(to.Region)) { to.ProfileSummary += ", " + to.Region; } if (!string.IsNullOrWhiteSpace(to.Country) && to.Country != to.Name) { to.ProfileSummary += ", " + to.Country; } } //
// public static MicroProfile ConvertRegionToMicroProfile(MC.GeoCoordinates item) { return(new MicroProfile() { Id = item.Id, RowId = item.RowId, Name = item.TitleFormatted, Description = item.LocationFormatted, Properties = new Dictionary <string, object>() { { "Latitude", item.Latitude }, { "Longitude", item.Longitude }, { "Url", item.GeoURI }, { "GeoNamesId", item.GeoNamesId } }, Selectors = new Dictionary <string, object>() { { "RecordId", item.Id }, { "GeoNamesId", item.GeoNamesId }, { "Name", item.Name }, { "ToponymName", item.ToponymName }, { "Region", item.Region }, { "Country", item.Country }, { "Latitude", item.Latitude }, { "Longitude", item.Longitude }, { "Url", item.GeoURI } } }); }
/// <summary> /// Get a list of geocoordinates from a list of IDs /// </summary> /// <param name="Ids"></param> /// <returns></returns> public static List <MC.GeoCoordinates> GeoCoordinates_GetList(List <int> Ids) { List <MC.GeoCoordinates> entities = new List <MC.GeoCoordinates>(); using (var context = new EntityContext()) { List <EM.GeoCoordinate> items = context.GeoCoordinate.Where(m => Ids.Contains(m.Id)).ToList(); foreach (var item in items) { MC.GeoCoordinates entity = new MC.GeoCoordinates(); MapFromDB(item, entity); entities.Add(entity); } } return(entities); }
/// <summary> /// Check if record (any) exist for the provided GeoNamesId /// </summary> /// <param name="geoNamesId"></param> /// <returns></returns> public static MC.GeoCoordinates GeoCoordinates_GetByGeoNamesId(int geoNamesId) { MC.GeoCoordinates entity = new MC.GeoCoordinates(); List <MC.GeoCoordinates> list = new List <MC.GeoCoordinates>(); using (var context = new EntityContext()) { EM.GeoCoordinate item = context.GeoCoordinate .FirstOrDefault(s => s.GeoNamesId == geoNamesId); if (item != null && item.Id > 0) { MapFromDB(item, entity); } } return(entity); }
/// <summary> /// Determine if a main region already exists for a jurisdiction. If found, then an update will be done rather than an add. /// This requirement may change in the future. /// </summary> /// <param name="parentUid"></param> /// <param name="isException"></param> /// <returns></returns> public static bool Jurisdiction_HasMainRegion(int parentId, ref MC.GeoCoordinates entity) { bool isFound = false; //MC.GeoCoordinates entity = new MC.GeoCoordinates(); using (var context = new EntityContext()) { List <EM.GeoCoordinate> list = context.GeoCoordinate .Where(s => s.JurisdictionId == parentId && s.IsException == false).ToList(); if (list != null && list.Count > 0) { isFound = true; MapFromDB(list[0], entity); } } return(isFound); }
public static MC.GeoCoordinates GeoCoordinates_GetByUrl(string geoUri) { MC.GeoCoordinates entity = new MC.GeoCoordinates(); if (string.IsNullOrWhiteSpace(geoUri)) { return(null); } geoUri = geoUri.ToLower(); using (var context = new EntityContext()) { EM.GeoCoordinate item = context.GeoCoordinate .FirstOrDefault(s => s.Url.ToLower() == geoUri); if (item != null && item.Id > 0) { MapFromDB(item, entity); } } return(entity); }
public Address() { GeoCoordinates = new GeoCoordinates(); ContactPoint = new List <ContactPoint>(); }
public JurisdictionProfile() { MainJurisdiction = new GeoCoordinates(); JurisdictionException = new List <GeoCoordinates>(); JurisdictionAssertion = new Enumeration(); }