示例#1
0
 public CountryObject SaveCountry(CountryObject country)
 {
     if (country.CountryId > 0) // Update
     {
         string sql = @"
             UPDATE  lu_Country
             SET     Country = @Country,
                     CountryCode = @CountryCode,
                     Active = @Active
             WHERE   CountryId = @CountryId";
         Config.Conn.Execute(sql, country);
     }
     else
     {
         string sql = @"
             INSERT INTO lu_Country (
                 Country,
                 CountryCode,
                 Active
             )
             VALUES (
                 @Country,
                 @CountryCode,
                 @Active
             )
             SELECT CAST(SCOPE_IDENTITY() AS INT)";
         country.CountryId = Config.Conn.Query <int>(sql, country).Single();
     }
     return(country);
 }
示例#2
0
 public bool DeleteCountry(CountryObject country)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM lu_Country WHERE CountryId = @CountryId", country);
     }
     catch { return(false); }
     return(true);
 }
示例#3
0
        public static List <CountryObject> GetCountries(bool enabledOnly = false, int?requiredId = null)
        {
            try
            {
                var cache = HttpContext.Current.Cache;
                List <CountryObject> data = (List <CountryObject>)cache[CountryKey];
                if (data == null)
                {
                    data = CountryObject.GetCountries();
                    cache.Insert(CountryKey, data, null, DateTime.Now.AddMinutes(60), Cache.NoSlidingExpiration);
                }

                return(data.Where(n => (!enabledOnly || n.Active || (requiredId.HasValue && n.CountryId == requiredId.Value))).ToList());
            }
            catch { }

            return(CountryObject.GetCountries().Where(n => (!enabledOnly || n.Active || (requiredId.HasValue && n.CountryId == requiredId.Value))).ToList());
        }