public void Add(TEntity obj, bool saveChanges = true) { dbContext.Add(obj); if (saveChanges) { dbContext.SaveChanges(); } }
// --------------------------------------------------------------------- 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)); } }
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(); } }
public void Post([FromBody] Hero hero) { _context.hero.Add(hero); _context.SaveChanges(); }
public static void InitializeDbForTests(HeroDbContext db) { db.Heroes.AddRange(GetSeedingHeroes()); db.SaveChanges(); }
protected void Save() => _context.SaveChanges();