private void BuyItem(string username, int id) { User user; Product product; try { product = StregSystem.GetProductByID(id); user = StregSystem.GetUserByUsername(username); if (product.Active) { try { StregsystemUI.DisplayUserBuysProduct(StregSystem.BuyProduct(user, product)); } catch (InsufficientCreditsException) { StregsystemUI.DisplayInsufficientCash(user, product); } } } catch (UserDoesNotExistException) { StregsystemUI.DisplayUserNotFound(username); } catch (InvalidProductIdException) { StregsystemUI.DisplayProductNotFound(id); } }
private void BuyMultipleItems(string[] userCommandArr) { string username = userCommandArr[0]; int amount = int.Parse(userCommandArr[1]); int productId = int.Parse(userCommandArr[2]); List <BuyTransaction> buyTransactions = new List <BuyTransaction>(); if (amount > 0) { try { User user = StregSystem.GetUserByUsername(username); Product product = StregSystem.GetProductByID(productId); if (product.Active) { for (int i = 0; i < amount; i++) { try { buyTransactions.Add(StregSystem.BuyProduct(user, product)); } catch (InsufficientCreditsException) { StregsystemUI.DisplayInsufficientCash(user, product); } } StregsystemUI.DisplayUserBuysProducts(buyTransactions); } } catch (UserDoesNotExistException) { StregsystemUI.DisplayUserNotFound(username); } catch (InvalidProductIdException) { StregsystemUI.DisplayProductNotFound(productId); } } else { StregsystemUI.DisplayGeneralError("You have to buy atleast one item :)"); } }