/// <summary> /// Validates that the quantity of the line item is less than the limit. Throws an exception /// if it is not. /// </summary> /// <param name="product">The product of the line item to validate</param> /// <param name="qty">The quantity of the line item</param> private void ValidateQuantityBelowLimit(BusinessProduct product, int qty) { if (qty > maxQuantity) { throw new BusinessOrderException($"[!] {product} of quantity {qty} item has a quantity greater than {maxQuantity}"); } }
/// <summary> /// Validates the quantity of the line item is greater than zero. Throws an exception if it /// is not. /// </summary> /// <param name="product">The product of the line item to validate</param> /// <param name="qty">The quantity of the line item</param> private void ValidateQuantityGreaterThanZero(BusinessProduct product, int qty) { if (qty <= 0) { throw new BusinessOrderException($"[!] {product} of quantity {qty} item does not have a quantity greater than 0"); } }
/// <summary> /// Decrements the stock of the inventory of this location. /// </summary> /// <param name="bProduct">The product to decrement</param> /// <param name="qty">The amount of the product to decrement</param> public void DecrementStock(BusinessProduct bProduct, int qty) { Log.Information($"Decrementing stock of location {Id} of product {bProduct} with quantity {qty}"); if (!inventory.Keys.Any(p => p.Id == bProduct.Id)) { throw new BusinessLocationException($"[!] Location does not have {bProduct} in stock"); } BusinessProduct selectedProduct = inventory.Keys.Where(p => p.Id == bProduct.Id).FirstOrDefault(); if (qty > inventory[selectedProduct]) { throw new BusinessLocationException($"[!] Location {Id} does not have {selectedProduct} with {qty} stock, only has {inventory[selectedProduct]} in stock"); } inventory[selectedProduct] -= qty; }
/// <summary> /// Adds a product to this location's inventory. /// </summary> /// <param name="bProduct">The product to add</param> /// <param name="stock">The quantity of the product to add</param> public void AddProduct(BusinessProduct bProduct, int stock) { inventory.Add(bProduct, stock); }