示例#1
0
 public void Add(TEntity obj, bool saveChanges = true)
 {
     dbContext.Add(obj);
     if (saveChanges)
     {
         dbContext.SaveChanges();
     }
 }
示例#2
0
// ---------------------------------------------------------------------

        public IActionResult AddVillain(VillainsModel newVillain)
        {
            if (ModelState.IsValid)
            {
                _context.villains.Add(newVillain);
                _context.SaveChanges();
                return(RedirectToAction("DisplayAllVillains"));
            }
            else
            {
                return(View("AddVillainForm", newVillain));
            }
        }
示例#3
0
// ---------------------------------------------------------------------
        public IActionResult AddHero(HeroesModel newHero)
        {
            if (ModelState.IsValid)
            {
                _context.heroes.Add(newHero);
                _context.SaveChanges();
                return(RedirectToAction("DisplayAllHeroes"));
            }
            else
            {
                return(View("AddHeroForm", newHero));
            }
        }
示例#4
0
        public void CreateHero(HeroInfo heroInfo)
        {
            using (var context = new HeroDbContext(_nameOrConnectionString))
            {
                var hero = new Hero(heroInfo.Id, heroInfo.SerialNumber, heroInfo.Name, heroInfo.Power,
                    heroInfo.AlterEgo);

                context.Set<Hero>().Add(hero);

                context.SaveChanges();
            }
        }
示例#5
0
 public void Post([FromBody] Hero hero)
 {
     _context.hero.Add(hero);
     _context.SaveChanges();
 }
示例#6
0
 public static void InitializeDbForTests(HeroDbContext db)
 {
     db.Heroes.AddRange(GetSeedingHeroes());
     db.SaveChanges();
 }
示例#7
0
 protected void Save() => _context.SaveChanges();