/// <summary> /// Creates the map object. /// </summary> /// <param name="regionId">The region identifier.</param> /// <param name="languageKey">The language key.</param> /// <returns> /// Boolean result true if new object was created. /// </returns> public bool CreateMapObject(int regionId, string languageKey) { if (string.IsNullOrEmpty(languageKey)) { return false; } if (regionId != 0) { var cityNode = new CityNode { LanguageKey = languageKey, RegionNodeId = regionId }; DataContext.AddDataObject(cityNode); } else { var regionNode = new RegionNode { LanguageKey = languageKey }; DataContext.AddDataObject(regionNode); } try { DataContext.SaveChanges(); } catch (Exception) { return false; } return true; }
/// <summary> /// Gets the route details by hash. /// </summary> /// <param name="hash">The hash.</param> /// <param name="language"></param> /// <returns>Return RouteDetailsData object.</returns> public RouteDetailsData GetRouteDetailsByHash(string hash, string language) { if (hash == null) { throw new ArgumentNullException("hash"); } if (language == null) { throw new ArgumentNullException("language"); } var routeDetailsData = new RouteDetailsData(); var trek = _routeRepository.GetTrekByHash(hash); if (trek != null) { string[] cityPoints = trek.Track.Split('-'); var nodes = new List<RouteNode>(); for (int i = 0; i < (cityPoints.Length - 1); i++) { long pointOrigin; long pointDestination; if (Int64.TryParse(cityPoints[i], out pointOrigin) && Int64.TryParse(cityPoints[i + 1], out pointDestination)) { var newItem = _routeRepository.GetRouteNode(pointOrigin, pointDestination); if (newItem == null) { newItem = _routeRepository.GetRouteNode(pointDestination, pointOrigin); if (newItem != null) { var destCityNode = new CityNode { CityNodeId = newItem.DestinationCityNode.CityNodeId, DestinationRouteNodes = newItem.DestinationCityNode.DestinationRouteNodes, DestinationTreks = newItem.DestinationCityNode.DestinationTreks, LanguageKey = newItem.DestinationCityNode.LanguageKey, OriginRouteNodes = newItem.DestinationCityNode.OriginRouteNodes, OriginTreks = newItem.DestinationCityNode.OriginTreks, RegionNode = newItem.DestinationCityNode.RegionNode, RegionNodeId = newItem.DestinationCityNode.RegionNodeId }; int destCityNodeId = newItem.DestinationCityNodeId; var origenCityNode = new CityNode { CityNodeId = newItem.OriginCityNode.CityNodeId, DestinationRouteNodes = newItem.OriginCityNode.DestinationRouteNodes, DestinationTreks = newItem.OriginCityNode.DestinationTreks, LanguageKey = newItem.OriginCityNode.LanguageKey, OriginRouteNodes = newItem.OriginCityNode.OriginRouteNodes, OriginTreks = newItem.OriginCityNode.OriginTreks, RegionNode = newItem.OriginCityNode.RegionNode, RegionNodeId = newItem.OriginCityNode.RegionNodeId }; int origenCityNodeId = newItem.OriginCityNodeId; newItem.OriginCityNodeId = destCityNodeId; newItem.OriginCityNode = destCityNode; newItem.DestinationCityNodeId = origenCityNodeId; newItem.DestinationCityNode = origenCityNode; } } nodes.Add(newItem); } else { nodes.Add(null); } } foreach (var routeNode in nodes) { var rdFeedbacks = _routeRepository.GetRoutDetailsFeedbackFor(routeNode, language); routeDetailsData.RouteDetailsItems.Add(rdFeedbacks); } } return routeDetailsData; }
/// <summary> /// Creates the translation with city node. /// </summary> /// <param name="objectTranslationData">The object translation data.</param> public void CreateTranslationWithCityNode(MapObjectTranslationData objectTranslationData) { if (objectTranslationData.RegionNodeId <= 0) { return; } if (!DataContext.CityNodes.Any(e => e.LanguageKey == objectTranslationData.LanguageKey)) { var newCity = new CityNode { RegionNodeId = (int)objectTranslationData.RegionNodeId, LanguageKey = objectTranslationData.LanguageKey, }; DataContext.AddDataObject(newCity); DataContext.SaveChanges(); } var newTranslation = new MapObjectTranslation { LanguageKey = objectTranslationData.LanguageKey, LanguageId = objectTranslationData.LanguageId, Value = objectTranslationData.Value }; DataContext.AddTranslationObject(newTranslation); DataContext.SaveChanges(); }
/// <summary> /// Gets the prepared suggestion. /// </summary> /// <param name="city">The city.</param> /// <param name="translation">The translation.</param> /// <param name="languageId">The language identifier.</param> /// <returns>The <see cref="Suggestion"/>.</returns> private Suggestion GetPreparedSuggestion(CityNode city, string translation, int languageId) { var regionName = string.Empty; var region = _mapObjectTranslationsRepository.GetRegionNode(city.RegionNodeId); if (region != null) { var regionTranslation = _mapObjectTranslationsRepository.GetMapObjectTranslations(region.LanguageKey, languageId); if (regionTranslation != null) { regionName = string.Format(", {0}", regionTranslation.Value); } } return new Suggestion(translation, regionName, city.CityNodeId); }