public ActionResult CreateHero(Models.Superhero superhero) { Models.ApplicationDbContext context = new Models.ApplicationDbContext(); context.Superhero.Add(superhero); context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteHero(Models.Superhero superhero) { Models.ApplicationDbContext context = new Models.ApplicationDbContext(); context.Superhero.Attach(superhero); context.Superhero.Remove(superhero); context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult EditHero(Models.Superhero superhero) { Models.ApplicationDbContext context = new Models.ApplicationDbContext(); context.Superhero.Attach(superhero); context.Entry(superhero).State = EntityState.Modified; context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Models.Superhero superhero) { try { // TODO: Add insert logic here context.Superheroes.Add(superhero); context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, Models.Superhero collection) { try { context.Entry(collection).State = EntityState.Modified; context.SaveChanges(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Create(Models.Superhero collection) { try { // TODO: Add insert logic here context.Superhero.Add(collection); context.SaveChanges(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Delete(int id, Models.Superhero superhero) { try { // TODO: Add delete logic here var superheroToDelete = context.Superheroes.Find(id); context.Superheroes.Remove(superheroToDelete); context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id, Models.Superhero collection) { try { // TODO: Add insert logic here var superhero = context.Superhero.Where(s => s.Id == id).SingleOrDefault(); context.Superhero.Remove(superhero); context.SaveChanges(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Edit(int id, Models.Superhero superhero) { try { // TODO: Add update logic here var superheroToEdit = context.Superheroes.Find(id); superheroToEdit.name = superhero.name; superheroToEdit.alterEgo = superhero.alterEgo; superheroToEdit.primarySuperheroAbility = superhero.primarySuperheroAbility; superheroToEdit.secondarySuperheroAbility = superhero.secondarySuperheroAbility; superheroToEdit.catchphrase = superhero.catchphrase; context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: Superheros/Create public ActionResult Create() { Models.Superhero superhero = new Models.Superhero(); return(View(superhero)); }