public async Task <IActionResult> DeleteConfirmed(int id) { var stuff = await db.Stuffs.FindAsync(id); foreach (Order o in db.Orders) { if (o.StuffId == id) { db.Remove(o); } } foreach (Review r in db.Reviews) { if (r.StuffId == id) { db.Remove(r); } } db.Stuffs.Remove(stuff); await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
//public async Task<IActionResult> Delete(int? id) //{ // if (id == null) // { // return NotFound(); // } // var article = await db.Articles // .FirstOrDefaultAsync(m => m.Id == id); // if (article == null) // { // return NotFound(); // } // return View(article); //} public IActionResult Delete(int id) { Article article = db.Articles.Include(x => x.Comments) .FirstOrDefault(x => x.Id == id); foreach (Comment comment in db.Comments) { if (comment.ArticleId == id) { db.Remove(comment); } } db.Articles.Remove(article); db.SaveChanges(); return(RedirectToAction("Index")); }