/// <summary> /// Add an item to the order. /// </summary> /// <exception cref="NotEnoughStockException">If there's not enough stock</exception> /// <param name="item"></param> /// <param name="amount"></param> public void AddItem(IItem item, int amount) { if (OrderLoc.CheckIfEnoughStock(item.name, amount)) { this._items.Add(new ItemCount(amount, item.name)); } else { throw new NotEnoughStockException("not enough stock to buy " + item.name); } }
/// <summary> /// Check if theres enough stock at the location for all items in the order. /// </summary> /// <returns>True if there's enough stock for the items in the order at the location.</returns> private bool EnoughStockForAllItems() { //CHECK LOCATION STOCKS bool EnoughStock = true; //Required Functionality foreach (ItemCount ic in Items) { EnoughStock = EnoughStock && OrderLoc.CheckIfEnoughStock(ic.ThisItem.name, ic.Count); } return(EnoughStock); }
//must check stocks, and if item is already in order. /// <summary> /// Add or change the amount of an item being ordered. /// </summary> /// <remarks> /// Can throw an argument out of range exception if the amount would lead to a negative /// number of itemname being in the order. Can also throw a Not Enough Stock exception /// if there is not enough stock to be bought at the current location for the new ammount. /// </remarks> /// <exception cref="NotEnoughStockException">If there's not enough stock.</exception> /// <exception cref="ArgumentOutOfRangeException">If there would be a negative amount in the order</exception> /// <param name="itemname">The name of the item</param> /// <param name="deltaAmount">The amount, + or -, to change the quantity of item in the order by.</param> public void EditOrderAmounts(string itemname, int deltaAmount) { ItemCount newcount; ItemCount oldcount; //find the old count for the item foreach (ItemCount ic in Items) { if (ic.ThisItem.name == itemname) { oldcount = ic; if (deltaAmount + oldcount.Count >= 0 && OrderLoc.CheckIfEnoughStock(itemname, deltaAmount + oldcount.Count)) { //avoid duplicate entries for the item in the list of items. _items.Remove(oldcount); //Make sure this isn't removing an item from the order before adding the new //ItemCount to the list of items in the order if (deltaAmount > 0) { newcount = new ItemCount(oldcount.Count + deltaAmount, oldcount.ThisItem.name); _items.Add(newcount); } } else { if (deltaAmount + oldcount.Count < 0) { throw new ArgumentOutOfRangeException("Error: Would be buying a negative amount of the item."); } else { throw new NotEnoughStockException("Not enough stock to add this many of the item."); } } break; } } }