/// <summary> /// Adds Order Items to a Supplier Order /// Level: Data /// </summary> /// <param name="OrderID">The Order ID</param> /// <param name="myOrderItems">A Collection of OrderItem</param> public void AddOrderItems(Guid OrderID, List<OrderItem> myOrderItems) { try { foreach (OrderItem myOrderItem in myOrderItems) { OrderProduct myProduct = new OrderProduct(); myProduct.OrderFK = OrderID; myProduct.ProductFK = myOrderItem.Id; myProduct.Quantity = myOrderItem.Quantity; myProduct.Price = myOrderItem.Price; Entities.AddToOrderProducts(myProduct); IncreaseStockQuantity(myOrderItem.Id, myOrderItem.Quantity); } Entities.SaveChanges(); } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Adds Order Items to A User Order /// Level: Data /// </summary> /// <param name="OrderID">The Order ID</param> /// <param name="myOrderItems">A collection of OrderItem</param> /// <returns>True if Insufficient Stock</returns> public bool AddUserOrderItems(Guid OrderID, List<OrderItem> myOrderItems) { try { bool StockQuantityMismatch = false; foreach (OrderItem myOrderItem in myOrderItems) { OrderProduct myProduct = new OrderProduct(); myProduct.OrderFK = OrderID; myProduct.ProductFK = myOrderItem.Id; myProduct.Quantity = myOrderItem.Quantity; myProduct.Price = myOrderItem.Price; Entities.AddToOrderProducts(myProduct); if (HasSufficientQuantity(myOrderItem.Id, myProduct.Quantity)) { DecreaseStockQuantity(myOrderItem.Id, myOrderItem.Quantity); } else { StockQuantityMismatch = true; } } Entities.SaveChanges(); return StockQuantityMismatch; //If Mismatch then Rollback and return false; } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Deprecated Method for adding a new object to the OrderProducts EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToOrderProducts(OrderProduct orderProduct) { base.AddObject("OrderProducts", orderProduct); }
/// <summary> /// Create a new OrderProduct object. /// </summary> /// <param name="orderFK">Initial value of the OrderFK property.</param> /// <param name="productFK">Initial value of the ProductFK property.</param> /// <param name="quantity">Initial value of the Quantity property.</param> /// <param name="price">Initial value of the Price property.</param> public static OrderProduct CreateOrderProduct(global::System.Guid orderFK, global::System.Guid productFK, global::System.Int32 quantity, global::System.Double price) { OrderProduct orderProduct = new OrderProduct(); orderProduct.OrderFK = orderFK; orderProduct.ProductFK = productFK; orderProduct.Quantity = quantity; orderProduct.Price = price; return orderProduct; }