public void Instantiate() { Delivery_Lineitem deliveryLI = new Delivery_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 SelectItem(int?id, int?deliveryScheduleID, int?Quantity) { var newDeliveryLI = db.Delivery_Lineitem.Find(id); if (newDeliveryLI != null) { if (Quantity != null && Quantity > newDeliveryLI.lineitem_unit_quantity) { ViewBag.ErrorMessage = "Please enter the quantity as equal or less than linvoice lineitem."; } else if (deliveryScheduleID != null && Quantity <= newDeliveryLI.lineitem_unit_quantity) { newDeliveryLI.delivery_schedule_id = Convert.ToInt32(deliveryScheduleID); // check quantity if (Quantity < newDeliveryLI.lineitem_unit_quantity) { var secondDeliveryLI = new Delivery_Lineitem(); secondDeliveryLI.product_inventory_id = newDeliveryLI.product_inventory_id; secondDeliveryLI.lineitem_unit_quantity = newDeliveryLI.lineitem_unit_quantity - Convert.ToInt32(Quantity); secondDeliveryLI.invoice_lineitem_id = newDeliveryLI.invoice_lineitem_id; db.Delivery_Lineitem.Add(secondDeliveryLI); } newDeliveryLI.lineitem_unit_quantity = Convert.ToInt32(Quantity); db.Entry(newDeliveryLI).State = EntityState.Modified; var result = db.SaveChanges(); if (result == 0) { return(View("Error")); } return(RedirectToAction("Edit", "Delivery_Schedule", new { id = deliveryScheduleID })); } else { ViewBag.ErrorMessage = "Something went wrong. Please try again."; } } var deliveryQ = db.Delivery_Lineitem.Where(dl => dl.delivery_schedule_id == null).OrderBy(dl => dl.Invoice_Lineitem.invoice_id).ToList(); foreach (var i in deliveryQ) { i.CalculateTotal(i.product_inventory_id); } ViewBag.DeliveryScheduleID = deliveryScheduleID; return(View(deliveryQ)); }
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)); }