private void QuickBuy(string[] inputArray, int inputCount, User user) { Product product; BuyTransaction transaction; int id; if (int.TryParse(inputArray[1], out id)) { product = LineSystem.GetProduct(id); if (product != null && product.Active) { transaction = LineSystem.BuyProduct(user, product); if (LineSystem.ExecuteTransaction(transaction)) { UI.DisplayUserBuysProduct(transaction); } else { UI.DisplayInsufficientCash(user, product); } } else { UI.DisplayProductNotFound(inputArray[1]); } } else { UI.DisplayGeneralError(inputArray[1] + " is not a invalid productID"); } }
private void MultiBuy(string[] inputArray, int inputCount, User user) { List <BuyTransaction> transactions = new List <BuyTransaction>(); Product product; int amount, id, price; if (int.TryParse(inputArray[1], out amount) && amount > 0) { if (int.TryParse(inputArray[2], out id)) { product = LineSystem.GetProduct(id); if (product != null && product.Active) { for (int i = 0; i < amount; i++) { transactions.Add(LineSystem.BuyProduct(user, product)); } price = transactions[0].Amount * amount; if (price <= user.Balance) { foreach (var transaction in transactions) { LineSystem.ExecuteTransaction(transaction); } UI.DisplayUserBuysProduct(transactions[0], amount); } else { UI.DisplayInsufficientCash(user, product, amount); } } else { UI.DisplayProductNotFound(inputArray[2]); } } else { UI.DisplayGeneralError(inputArray[2] + " is not a valid productID"); } } else { UI.DisplayGeneralError(inputArray[1] + " is not a valid amount"); } }
//Changes a field of a product depending on the parameters of the method private void ChangeProductBoolField(string commandName, string[] args, ProductBoolField field, bool newValue) { Product product; int id; if (IsValidArgs(commandName, args, 1)) { if (int.TryParse(args[0], out id)) { product = LineSystem.GetProduct(id); if (product != null) { switch (field) { case ProductBoolField.Active: product.Active = newValue; break; case ProductBoolField.CanBeBoughtOnCredit: product.CanBeBoughtOnCredit = newValue; break; default: break; } UI.DisplayGeneralMessage(product.Name + "'s " + field.ToString() + " field was set to " + newValue.ToString()); } else { UI.DisplayProductNotFound(args[0]); } } else { UI.DisplayGeneralError(args[0] + " is not a invalid productID"); } } }
public void NullGetProduct() { Assert.Null(lineSystem.GetProduct(10000)); Assert.NotNull(lineSystem.GetProduct(24)); }