public virtual void Save(TEntity model, bool commit = true)
 {
     DbSet.Add(model);
     if (commit)
     {
         Context.SaveChanges();
     }
 }
示例#2
0
 public override void TestInitialize()
 {
     base.TestInitialize();
     Assert.AreEqual(0, db.Countries.Count());
     for (var i = 0; i < count; i++)
     {
         db.Countries.Add(GetRandom.Object <CountryDbRecord>());
         db.SaveChanges();
     }
 }
示例#3
0
        public ActionResult Create([Bind(Include = "Id,CountryName,CountryCode,Capital")] Country country)
        {
            if (ModelState.IsValid)
            {
                db.Countries.Add(country);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(country));
        }
示例#4
0
        public void Create(CityModel cityModel)
        {
            var city = _mapper.Map <City>(cityModel);

            // await _dbContext.Country.AddAsync(country);
            // await _dbContext.SaveChangesAsync();
            _dbContext.Add(city).State = EntityState.Added;
            _dbContext.SaveChanges();
        }
示例#5
0
 public Country AddCountry(Country country)
 {
     _context.Countries.Add(country);
     _context.SaveChanges();
     return(country);
 }