public ActionResult DeleteConfirmed(int id) { InvTest invTest = db.InvTests.Find(id); db.InvTests.Remove(invTest); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "InvoiceID,InvoiceNumber,InvoiceDate")] InvTest invTest) { if (ModelState.IsValid) { db.InvTests.Add(invTest); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(invTest)); }
// GET: InvTest/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } InvTest invTest = db.InvTests.Find(id); if (invTest == null) { return(HttpNotFound()); } return(View(invTest)); }
// GET: InvTest/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // Invoice invoice = db.Invoices.Find(id); InvTest invoice = db.InvTests.Include(i => i.InvoiceLines) .Where(c => c.InvoiceID == id).FirstOrDefault(); if (invoice == null) { return(HttpNotFound()); } return(View(invoice)); }
public ActionResult Edit([Bind(Include = "InvoiceID,InvoiceNumber,InvoiceDate,InvoiceLines")] InvTest invTest) { if (ModelState.IsValid) { Dictionary <int, InvLineTest> invoiceLines = new Dictionary <int, InvLineTest>(); Dictionary <int, InvLineTest> removeLines = new Dictionary <int, InvLineTest>(); // Update new rows .. foreach (InvLineTest invLineTest in invTest.InvoiceLines) { if (invLineTest.InvoiceLineId == -1) { db.InvLineTests.Add(invLineTest); db.SaveChanges(); } invoiceLines.Add(invLineTest.InvoiceLineId, invLineTest); } // Remove deleted rows .. var invLineTests = from s in db.InvLineTests select s; invLineTests = invLineTests.Where(s => s.InvoiceID == invTest.InvoiceID); foreach (InvLineTest invLineTest in invLineTests) { if (!invoiceLines.ContainsKey(invLineTest.InvoiceLineId)) { db.InvLineTests.Remove(invLineTest); } else { db.Entry(invLineTest).State = EntityState.Detached; } } db.SaveChanges(); db.Entry(invTest).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(invTest)); }