public ActionResult DeleteConfirmed(DeleteVocabularyViewModel request) { var vocabulary = db.Vocabularies.Find(request.Id); int groupId = vocabulary.Group.Id; try { db.Vocabularies.Remove(vocabulary); db.SaveChanges(); } catch (Exception ex) { return(RedirectToAction("Details", "Group", new { Id = groupId, error = "Can't delete this vocabulary. Some students are learning it." })); } return(RedirectToAction("Details", "Group", new { Id = groupId })); }
public ActionResult Delete(int id = 0) { var vocabulary = db.Vocabularies.Find(id); if (vocabulary == null) { return(HttpNotFound()); } var response = new DeleteVocabularyViewModel { Id = vocabulary.Id, Word = vocabulary.Word, ImageUrl = vocabulary.ImageId, GroupId = vocabulary.Group.Id }; return(View(response)); }