public ActionResult Delete(int id) { DeleteWarrantViewModel model = new DeleteWarrantViewModel(); model.Warrant = db.Warrants.Find(id); model.deletedTipstaffRecord.TipstaffRecordID = id; if (model == null) { ErrorModel errModel = new ErrorModel(2); errModel.ErrorMessage = string.Format("Warrant {0} has been deleted, please raise a help desk call if you think this has been deleted in error.", id); TempData["ErrorModel"] = errModel; return(RedirectToAction("IndexByModel", "Error", new { area = "", model = errModel ?? null })); } return(View(model)); }
public ActionResult DeleteConfirmed(DeleteWarrantViewModel model) { //model.Warrant = db.Warrants.Find(model.deletedTipstaffRecord.TipstaffRecordID); //db.Warrants.Remove(model.Warrant); var w = db.Warrants.Find(model.deletedTipstaffRecord.TipstaffRecordID); foreach (var r in w.Respondents.ToList()) { db.Entry(r).State = EntityState.Deleted; } foreach (var a in w.addresses.ToList()) { db.Entry(a).State = EntityState.Deleted; } foreach (var an in w.AttendanceNotes.ToList()) { db.Entry(an).State = EntityState.Deleted; } foreach (var cr in w.caseReviews.ToList()) { db.Entry(cr).State = EntityState.Deleted; } foreach (var d in w.Documents.ToList()) { db.Entry(d).State = EntityState.Deleted; } foreach (var trs in w.LinkedSolicitors.ToList()) { db.Entry(trs).State = EntityState.Deleted; } foreach (var p in w.policeForces.ToList()) { db.Entry(p).State = EntityState.Deleted; } db.Entry(w).State = EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index", "Warrant")); }