public ActionResult Delete(int id) { var movieToDelete = (from m in _entities.MovieSet where m.Id == id select m).FirstOrDefault(); _entities.DeleteObject(movieToDelete); _entities.SaveChanges(); return(PartialView("Movies", _entities.MovieSet.ToList())); }
public ActionResult Delete(int id) { try { Movie movie = _db.Movies.FirstOrDefault(m => m.Id == id); if (movie != null) { // Delete should is idempotent, ignore if not present _db.DeleteObject(movie); _db.SaveChanges(); } return(RedirectToRoute(this.GetResourceRouteName(routeName, ActionType.Index))); } catch (Exception exception) { throw new HttpException((int)HttpStatusCode.InternalServerError, "An error has occured; see details:", exception); } }