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

        public IActionResult AddVillain(VillainsModel newVillain)
        {
            if (ModelState.IsValid)
            {
                _context.villains.Add(newVillain);
                _context.SaveChanges();
                return(RedirectToAction("DisplayAllVillains"));
            }
            else
            {
                return(View("AddVillainForm", newVillain));
            }
        }
// ---------------------------------------------------------------------
        public IActionResult AddHero(HeroesModel newHero)
        {
            if (ModelState.IsValid)
            {
                _context.heroes.Add(newHero);
                _context.SaveChanges();
                return(RedirectToAction("DisplayAllHeroes"));
            }
            else
            {
                return(View("AddHeroForm", newHero));
            }
        }
Beispiel #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();
            }
        }
Beispiel #5
0
 public void Post([FromBody] Hero hero)
 {
     _context.hero.Add(hero);
     _context.SaveChanges();
 }
Beispiel #6
0
 public static void InitializeDbForTests(HeroDbContext db)
 {
     db.Heroes.AddRange(GetSeedingHeroes());
     db.SaveChanges();
 }
 protected void Save() => _context.SaveChanges();