Пример #1
0
        public static async Task <int?> GetCountryByCode(CCSubmitDirect db, string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(null);
            }

            if (_countryCodeMap == null)
            {
                await Configure(db);
            }

            foreach (var entry in _countryCodeMap)
            {
                if (entry.Key.Contains(code.ToLower()))
                {
                    return(entry.Value);
                }
            }

            DirectContainer dc = await db.LoadContainerAsync(string.Format("SELECT countryid, name, code FROM [].tm_country WHERE code='{0}';", code.ToLower()));

            if (!dc.HasValue)
            {
                return(null);
            }

            _countryNameMap.Add(dc.GetString("name").ToLower(), dc.GetInt("countryid").Value);
            _countryCodeMap.Add(dc.GetString("code").ToLower(), dc.GetInt("countryid").Value);
            db.TransactionalManager.Add("INSERT INTO [].tm_country_used (countryid)", dc.GetInt("countryid").Value);

            return(dc.GetInt("countryid").Value);
        }
Пример #2
0
        protected override async void Init()
        {
            CCSubmitDirect db = this.Database;

            _data = new Dictionary <string, CountryCacheModel>();
            DirectContainer dc = await db.LoadContainerAsync(
                @"SELECT c.countryid, c.name, c.code FROM [].tm_country AS c
          LEFT OUTER JOIN [].tm_country_used AS u ON u.countryid=c.countryid
          WHERE u.countryusedid IS NOT NULL;");

            foreach (var row in dc.Rows)
            {
                CountryCacheModel country = new CountryCacheModel()
                {
                    ID   = row.GetInt("countryid").Value,
                    Name = row.GetString("name").ToLower(),
                    Code = row.GetString("code").ToLower()
                };

                if (!_data.ContainsKey(country.Code))
                {
                    _data.Add(country.Code, country);
                }

                if (!_data.ContainsKey(country.Name))
                {
                    _data.Add(country.Name, country);
                }
            }
        }
Пример #3
0
        private static async Task Configure(CCSubmitDirect db)
        {
            _countryNameMap = new Dictionary <string, int>();
            DirectContainer dc = await db.LoadContainerAsync(
                @"SELECT c.countryid, c.name, c.code FROM [].tm_country AS c
          LEFT OUTER JOIN [].tm_country_used AS u ON u.countryid=c.countryid
          WHERE u.countryusedid IS NOT NULL;");

            _countryNameMap = new Dictionary <string, int>();
            _countryCodeMap = new Dictionary <string, int>();
            foreach (var row in dc.Rows)
            {
                _countryNameMap.Add(row.GetString("name").ToLower(), row.GetInt("countryid").Value);
                _countryCodeMap.Add(row.GetString("code").ToLower(), row.GetInt("countryid").Value);
            }
        }
Пример #4
0
        public async Task <int?> Get(CCSubmitDirect db, string input)
        {
            input = input.ToLower();
            if (string.IsNullOrEmpty(input))
            {
                return(null);
            }

            if (_data.ContainsKey(input))
            {
                return(_data[input].ID);
            }

            DirectContainer dc = await db.LoadContainerAsync(string.Format("SELECT countryid, name, code FROM [].tm_country WHERE name LIKE '%{0}%' OR code='{0}';", input));

            if (!dc.HasValue)
            {
                return(null);
            }

            CountryCacheModel country = new CountryCacheModel()
            {
                ID   = dc.GetInt("countryid").Value,
                Name = dc.GetString("name").ToLower(),
                Code = dc.GetString("code").ToLower()
            };

            if (!_data.ContainsKey(country.Code))
            {
                _data.Add(country.Code, country);
            }

            if (!_data.ContainsKey(country.Name))
            {
                _data.Add(country.Name, country);
            }

            db.TransactionalManager.Add("INSERT INTO [].tm_country_used (countryid)", dc.GetInt("countryid").Value);
            return(dc.GetInt("countryid").Value);
        }