public object receiveOrderProduct(int supplierOrderID, int productID, int quantity) { db.Configuration.ProxyCreationEnabled = false; dynamic toReturn = new ExpandoObject(); try { Supplier_Order_Product prod = db.Supplier_Order_Product.Where(x => x.ProductID == productID && x.SupplierOrderID == supplierOrderID).FirstOrDefault(); if (prod != null) { prod.SOPQuantityRecieved = quantity; db.SaveChanges(); toReturn.Message = "Product Quantity Saved"; } } catch { toReturn.Error = "Adding Product Qauntity Unsuccessful"; } return(toReturn); }
public object receiveProductStock(int supplierOrderID, int productID, int quantity, int containerID) { db.Configuration.ProxyCreationEnabled = false; dynamic toReturn = new ExpandoObject(); toReturn.product = new ExpandoObject(); try { //search for the supplier and product in the database // Supplier supplier = db.Suppliers.Where(X => X.SupplierID == supplierID).FirstOrDefault(); Product product = db.Products.Where(x => x.ProductID == productID).FirstOrDefault(); if (product != null) { //check to see if the supplier order was already created today in the current container Supplier_Order supplier_Order = db.Supplier_Order.Where(x => x.SupplierOrderID == supplierOrderID).FirstOrDefault(); if (supplier_Order != null) { //get Product Supplier_Order_Product prod = db.Supplier_Order_Product.Where(x => x.ProductID == product.ProductID && x.SupplierOrderID == supplier_Order.SupplierOrderID).FirstOrDefault(); if (prod != null) { prod.SOPQuantityRecieved = quantity; db.SaveChanges(); //returning the product so you can see it in the console if you want toReturn.product = db.Supplier_Order_Product.Where(x => x.ProductID == productID && x.SupplierOrderID == supplier_Order.SupplierOrderID).FirstOrDefault(); toReturn.Message = "Product Quantity Saved"; //adjust quantity on hand in container Container con = db.Containers.Where(x => x.ContainerID == containerID).FirstOrDefault(); if (con != null) { Container_Product conProd = db.Container_Product.Where(x => x.ContainerID == con.ContainerID && x.ProductID == productID).FirstOrDefault(); if (conProd != null) { conProd.CPQuantity = conProd.CPQuantity + quantity; db.SaveChanges(); toReturn.Message = "Container's Product Quantity Updated"; } } } else { toReturn.Error = "Product Not Found"; } } } } catch { toReturn.Error = "Receiving Stock Failed"; } return(toReturn); }
public object addProductToOrder(int containerID, int supplierID, int productID, int quantity) { db.Configuration.ProxyCreationEnabled = false; dynamic toReturn = new ExpandoObject(); toReturn.product = new ExpandoObject(); try { //search for the supplier and product in the database Supplier supplier = db.Suppliers.Where(X => X.SupplierID == supplierID).FirstOrDefault(); Product product = db.Products.Where(x => x.ProductID == productID).FirstOrDefault(); if (supplier != null && product != null) { DateTime date = DateTime.Now; string date_ = date.ToString("yyyy-MM-dd"); date = Convert.ToDateTime(date_); //check to see if the supplier order was already created today in the current container Supplier_Order supplier_Order = db.Supplier_Order.Where(x => x.SupplierID == supplierID && x.SODate == date && x.SupplierOrderStatusID == 1 && x.ContainerID == containerID).FirstOrDefault(); if (supplier_Order == null) { //get the "Placed" order status Supplier_Order_Status status = db.Supplier_Order_Status.Where(x => x.SupplierOrderStatusID == 1).FirstOrDefault(); //create new supplier order Supplier_Order newOrder = new Supplier_Order(); newOrder.SupplierID = supplierID; newOrder.SODate = DateTime.Now; newOrder.ContainerID = containerID; newOrder.SupplierOrderStatusID = status.SupplierOrderStatusID; db.Supplier_Order.Add(newOrder); db.SaveChanges(); //retrive the placed order Supplier_Order order = db.Supplier_Order.ToList().LastOrDefault(); if (order != null) { //add the product to the created order Supplier_Order_Product addProd = new Supplier_Order_Product(); addProd.ProductID = productID; addProd.SupplierOrderID = order.SupplierOrderID; addProd.SOPQuantityOrdered = quantity; addProd.SOPQuantityRecieved = 0; db.Supplier_Order_Product.Add(addProd); db.SaveChanges(); //returning the product so you can see it in the console toReturn.product = db.Supplier_Order_Product.Where(x => x.ProductID == productID && x.SupplierOrderID == order.SupplierOrderID).FirstOrDefault(); } } else { //add product to existing Order Supplier_Order_Product addProd = new Supplier_Order_Product(); addProd.ProductID = productID; addProd.SupplierOrderID = supplier_Order.SupplierOrderID; addProd.SOPQuantityOrdered = quantity; addProd.SOPQuantityRecieved = 0; db.Supplier_Order_Product.Add(addProd); db.SaveChanges(); //returning the product so you can see it in the console if you want toReturn.product = db.Supplier_Order_Product.Where(x => x.ProductID == productID && x.SupplierOrderID == supplier_Order.SupplierOrderID).FirstOrDefault(); } toReturn.Message = "Product Added To Order"; } else { toReturn.Error = "Supplier Or Product Details Not Found"; } } catch { toReturn.Error = "Product Already Ordered. Awaiting Supplier Order Deliery"; } return(toReturn); }