public ActionResult DeleteConfirmed(int id, int?optionalID) { Invoice_Lineitem invoice_Lineitem = db.Invoice_Lineitem.Find(id); db.Invoice_Lineitem.Remove(invoice_Lineitem); db.SaveChanges(); return(RedirectToAction("Edit", "invoices", new { id = optionalID })); }
public void Instantiate() { Invoice_Lineitem deliveryLI = new Invoice_Lineitem(); deliveryLI.product_inventory_id = 2; Lineitem result1 = deliveryLI as Lineitem; //Assert.IsFalse(result == null); Assert.AreSame(result1, deliveryLI); Assert.IsTrue(result1.product_inventory_id == 2); }
public ActionResult Create([Bind(Include = "Id,product_inventory_id,lineitem_unit_quantity,invoice_id")] Invoice_Lineitem invoice_Lineitem, int?optionalID) { if (ModelState.IsValid) { db.Invoice_Lineitem.Add(invoice_Lineitem); db.SaveChanges(); Session["InvoiceLineitem"] = null; return(RedirectToAction("Edit", "Invoices", new { id = invoice_Lineitem.invoice_id })); } ViewBag.OptionalID = optionalID; return(View(invoice_Lineitem)); }
public ActionResult Edit([Bind(Include = "Id,product_inventory_id,lineitem_unit_quantity,invoice_id")] Invoice_Lineitem invoice_Lineitem, int?optionalID, int?lineitemID) { if (ModelState.IsValid) { db.Entry(invoice_Lineitem).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Edit", "invoices", new { id = optionalID })); } ViewBag.OptionalID = optionalID; ViewBag.LineitemID = lineitemID; return(View(invoice_Lineitem)); }
//// GET: Invoice_Lineitem/Delete/5 //public ActionResult Delete(int? id) //{ // if (id == null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } // Invoice_Lineitem invoice_Lineitem = db.Invoice_Lineitem.Find(id); // if (invoice_Lineitem == null) // { // return HttpNotFound(); // } // return View(invoice_Lineitem); //} // GET: Invoice_Lineitem/Delete/5 public PartialViewResult PartialDelete(int?id, int?optionalID) { if (id == null) { return(PartialView(HttpStatusCode.BadRequest)); } Invoice_Lineitem invoice_Lineitem = db.Invoice_Lineitem.Find(id); invoice_Lineitem.CalculateTotal(invoice_Lineitem.product_inventory_id); if (invoice_Lineitem == null) { return(PartialView("Error")); } ViewBag.OptionalID = optionalID; return(PartialView(invoice_Lineitem)); }
// GET: Invoice_Lineitem/Edit/5 public ActionResult Edit(int?id, int?optionalID, int?productID, int?Quantity) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Invoice_Lineitem invoice_Lineitem = db.Invoice_Lineitem.Find(id); if (productID != null && Quantity != null) { invoice_Lineitem.lineitem_unit_quantity = Convert.ToInt32(Quantity); invoice_Lineitem.product_inventory_id = Convert.ToInt32(productID); } invoice_Lineitem.CalculateTotal(invoice_Lineitem.product_inventory_id); if (invoice_Lineitem == null) { return(HttpNotFound()); } ViewBag.OptionalID = optionalID; ViewBag.LineitemID = id; return(View(invoice_Lineitem)); }
//// GET: Invoice_Lineitem/Details/5 //public ActionResult Details(int? id) //{ // if (id == null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } // Invoice_Lineitem invoice_Lineitem = db.Invoice_Lineitem.Find(id); // if (invoice_Lineitem == null) // { // return HttpNotFound(); // } // return View(invoice_Lineitem); //} // GET: Invoice_Lineitem/Create public ActionResult Create(int?invoiceID, int?id, int?Quantity) { var invoiceLineitem = new Invoice_Lineitem(); if (Session["InvoiceLineitem"] != null) { invoiceLineitem = (Invoice_Lineitem)Session["InvoiceLineitem"]; } if (invoiceID != null) { invoiceLineitem.invoice_id = Convert.ToInt32(invoiceID); } if (id != null && Quantity != null) { invoiceLineitem.CalculateTotal(Convert.ToInt32(id)); invoiceLineitem.lineitem_unit_quantity = Convert.ToInt32(Quantity); } ViewBag.OptionalID = invoiceID; Session["InvoiceLineitem"] = invoiceLineitem; return(View(invoiceLineitem)); }
public ActionResult Create([Bind(Include = "Id,invoice_date,employee_id,customer_id")] Invoice invoice) { if (ModelState.IsValid && invoice.employee_id != null && invoice.customer_id != 0) { db.Invoices.Add(invoice); var result = db.SaveChanges(); if (result > 0) { var li = (List <Lineitem>)Session["InvoiceItems"]; foreach (var item in li) { // create invoice lineitem var invoiceLI = new Invoice_Lineitem() { product_inventory_id = item.product_inventory_id, lineitem_unit_quantity = item.lineitem_unit_quantity }; invoiceLI.invoice_id = db.Invoices.Max(i => i.Id); db.Invoice_Lineitem.Add(invoiceLI); db.SaveChanges(); // create delivery lineitem queue var deliveryLI = new Delivery_Lineitem() { product_inventory_id = item.product_inventory_id, lineitem_unit_quantity = item.lineitem_unit_quantity }; deliveryLI.invoice_lineitem_id = db.Invoice_Lineitem.Max(i => i.Id); db.Delivery_Lineitem.Add(deliveryLI); db.SaveChanges(); // update product inventory quantity var productInventory = db.Product_Inventory.Find(item.product_inventory_id); productInventory.unit_quantity -= item.lineitem_unit_quantity; db.Entry(productInventory).State = EntityState.Modified; db.SaveChanges(); } } Session["InvoiceItems"] = null; Session["CurrentInvoice"] = null; return(RedirectToAction("Index")); } if (invoice.employee_id != null || invoice.employee_id != "") { invoice.AspNetUser = db.AspNetUsers.Find(invoice.employee_id); } if (invoice.customer_id != 0) { invoice.Customer = db.Customers.Find(invoice.customer_id); } var employeeError = ""; var customerError = ""; if (invoice.employee_id == null) { employeeError = "Please select an employee."; } if (invoice.customer_id == 0) { customerError = "Please select a customer."; } ViewBag.EmployeeError = employeeError; ViewBag.CustomerError = customerError; ViewBag.ActionTitle = "Create "; Session["CurrentInvoice"] = invoice; return(View(invoice)); }