Example #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            InvTest invTest = db.InvTests.Find(id);

            db.InvTests.Remove(invTest);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #2
0
        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));
        }
Example #3
0
        // 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));
        }
Example #4
0
        // 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));
        }
Example #5
0
        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));
        }