public ActionResult Delete(Guid id, FormCollection collection) { try { // TODO: Add delete logic here List <StudentModel> studentsList = studentRepository.GetAllStudentsByParentId(id); foreach (StudentModel student in studentsList) { List <InvoiceModel> invoices = invoiceRepository.GetAllInvoicesByStudentId(student.StudentId); foreach (InvoiceModel invoice in invoices) { invoiceRepository.Delete(invoice.InvoiceId); } studentRepository.Delete(student.StudentId); } parentRepository.Delete(id); return(RedirectToAction("Index")); } catch { return(View("Delete")); } }
public ActionResult Delete(int id) { if (_rep.Delete(id) == 1) { TempData["Message"] = "success"; TempData["SuccessMessage"] = MessageNaming.SuccessDataDelete; } else { TempData["Message"] = "error"; TempData["ErrorMessage"] = MessageNaming.ErrorDataDelete; } return(RedirectToAction("Index")); }