public void Delete(TEntity obj, bool saveChanges = true) { dbContext.Remove(obj); if (saveChanges) { dbContext.SaveChanges(); } }
// --------------------------------------------------------------------- public IActionResult DeleteVillain(int villainID) { VillainsModel foundVillain = _context.villains.FirstOrDefault(v => v.id == villainID); if (foundVillain != null) { _context.Remove(foundVillain); _context.SaveChanges(); return(RedirectToAction("DisplayAllVillains")); } else { return(Content($"Someone is trying to erase our memories...")); } }
// --------------------------------------------------------------------- public IActionResult DeleteHero(int heroID) { HeroesModel foundHero = _context.heroes.FirstOrDefault(h => h.id == heroID); if (foundHero != null) { _context.Remove(foundHero); _context.SaveChanges(); return(RedirectToAction("DisplayAllHeroes")); } else { return(Content($"Someone is trying to erase our memories...")); } }
public void Delete(int id) { Hero hero = _context.hero.Where(h => h.Id == id).FirstOrDefault(); _context.Remove(hero); }
public virtual void Delete(T entity) { _context.Remove(entity); Save(); }