Esempio n. 1
0
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public City Get(CityKey key)
        {
            if (key == null || (key.CountryId == 0 && string.IsNullOrWhiteSpace(key.ZipCode) && key.Id == 0))
            {
                return(null);
            }

            var rowList = _dbContext.City.Where(m => 1 == 1);

            if (key.CountryId > 0)
            {
                rowList = rowList.Where(m => m.CountryId == key.CountryId);
            }
            if (!string.IsNullOrWhiteSpace(key.ZipCode))
            {
                rowList = rowList.Where(m => m.ZipCode == key.ZipCode);
            }
            if (key.Id > 0)
            {
                rowList = rowList.Where(m => m.Id == key.Id);
            }

            var row = rowList.FirstOrDefault();

            if (row != null)
            {
                return(CityTransformer.ToBean(row));
            }
            return(null);
        }
Esempio n. 2
0
        public City GetCity(CityKey key)
        {
            City   city     = null;
            string cacheKey = key == null ? "CityKey_null" : key.GetCacheKey();

            if (key != null && !TryGetCacheData(cacheKey, out city))
            {
                city = GetCityManager().GetCity(key);
                SetCacheData(_cacheName, cacheKey, city);
            }
            return(city);
        }
Esempio n. 3
0
 internal City GetCity(CityKey key)
 {
     return(_module.Get(key));
 }