/// <summary> /// Mapping Xml Data which has been retrieved by an xpath expression. /// </summary> /// <param name="list">The list.</param> /// <returns>a mapped item of type: <see cref="Common.Country"/></returns> private Common.Country MapData(XmlNodeList list) { Common.Country item = new Common.Country(); foreach (XmlNode n in list) { #region Map Data switch (n.Name) { case "nCountryId": item.CountryId = int.Parse(n.InnerText); break; case "cName": item.Name = n.InnerText; break; case "cIso2": item.Iso2 = n.InnerText; break; case "cIso3": item.Iso3 = n.InnerText; break; case "cCapitalCity": item.CapitalCityName = n.InnerText; break; case "cMapReference": item.MapReference = n.InnerText; break; case "cCurrency": item.CurrencyName = n.InnerText; break; } #endregion Map Data } return(item); }
/// <summary> /// Get item by id. /// </summary> /// <param name="id">The id.</param> /// <param name="loadRegion">if set to <c>true</c> [load region].</param> /// <returns> /// A list of <see cref="Common.Country"/> objects /// </returns> public Common.Country GetById(int id, bool loadRegion) { try { // create a unique key for this item. string key = string.Format(cacheKeyCountryById, id.ToString()); Common.Country result = Common.Util.CacheGet <Common.Country>(key); if (result == null) { foreach (Common.Country country in this.GetAll(false, loadRegion)) { if (id.Equals(country.CountryId)) { result = country; break; } } if (result == null) { return(null); } // now we can add it to the cache Common.Util.CacheAdd(key, result); } return(result); } catch (Exception ex) { Console.WriteLine(@"Error: " + ex.Message); throw ex; } }
/// <summary> /// Get item by name. /// </summary> /// <param name="name">The country name.</param> /// <param name="loadRegion">if set to <c>true</c> [load region].</param> /// <returns> /// A list of <see cref="Common.Country"/> objects /// </returns> public Common.Country GetByName(string name, bool loadRegion) { // create a unique key for this item. string key = string.Format(cacheKeyCountryByName, name); Common.Country result = Common.Util.CacheGet <Common.Country>(key); if (result == null) { foreach (Common.Country country in this.GetAll(false, loadRegion)) { if (name.Equals(country.Name)) { result = country; break; } } // now we can add it to the cache Common.Util.CacheAdd(key, result); } return(result); }
/// <summary> /// Mapping Xml Data which has been retrieved by an xpath expression. /// </summary> /// <param name="list">The list.</param> /// <returns>a mapped item of type: <see cref="Common.Country"/></returns> private Common.Country MapData(XmlNodeList list) { Common.Country item = new Common.Country(); foreach (XmlNode n in list) { #region Map Data switch (n.Name) { case "nCountryId": item.CountryId = int.Parse(n.InnerText); break; case "cName": item.Name = n.InnerText; break; case "cIso2": item.Iso2 = n.InnerText; break; case "cIso3": item.Iso3 = n.InnerText; break; case "cCapitalCity": item.CapitalCityName = n.InnerText; break; case "cMapReference": item.MapReference = n.InnerText; break; case "cCurrency": item.CurrencyName = n.InnerText; break; } #endregion Map Data } return item; }