Beispiel #1
0
        private void CheckDB(RatesContext db)
        {
            bool needSave = false;

            if (db.Countries.Count() == 0)
            {
                db.Countries.Add(new Country {
                    Name = "USA", Currency = "USD", Code = "R01235"
                });
                db.Countries.Add(new Country {
                    Name = "Japan", Currency = "JPY", Code = "R01820"
                });
                db.Countries.Add(new Country {
                    Name = "China", Currency = "CNY", Code = "R01375"
                });
                needSave = true;
            }
            if (db.Rates.Count() == 0)
            {
                var rates = GetRates(GetCodes());
                db.Rates.AddRange(rates);
                needSave = true;
            }
            if (needSave)
            {
                db.SaveChanges();
            }
        }
Beispiel #2
0
 public void AddRates(List<Rate> rates)
 {
     using (var db = new RatesContext(connectionStringName))
     {
         db.Rates.AddRange(rates);
         db.SaveChanges();
     }
 }
Beispiel #3
0
 public void AddRates(List <Rate> rates)
 {
     using (var db = new RatesContext(connectionStringName))
     {
         db.Rates.AddRange(rates);
         db.SaveChanges();
     }
 }
Beispiel #4
0
 private void CheckDB(RatesContext db)
 {
     bool needSave = false;
     if (db.Countries.Count() == 0)
     {
         db.Countries.Add(new Country { Name = "USA", Currency = "USD", Code = "R01235" });
         db.Countries.Add(new Country { Name = "Japan", Currency = "JPY", Code = "R01820" });
         db.Countries.Add(new Country { Name = "China", Currency = "CNY", Code = "R01375" });
         needSave = true;
     }
     if (db.Rates.Count() == 0)
     {
         var rates = GetRates(GetCodes());
         db.Rates.AddRange(rates);
         needSave = true;
     }
     if (needSave) db.SaveChanges();
 }