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 AddCreditsToUser(string[] commandArr) { if (commandArr.Length == 3) { if (commandArr[2].All(char.IsDigit)) { try { StregSystem.AddCreditsToAccount((StregSystem.GetUserByUsername(commandArr[1])), decimal.Parse(commandArr[2])); } catch (UserDoesNotExistException) { StregsystemUI.DisplayUserNotFound(commandArr[1]); } } } }
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 :)"); } }
private void DisplayRelevantUserInfo(string username) { try { User user = StregSystem.GetUserByUsername(username); List <Transaction> trans = StregSystem.GetTransactions(user, 10); if (!trans.Any()) { StregsystemUI.DisplayUserInfo(user); } else { StregsystemUI.DisplayUserInfo(user, trans); } } catch (UserDoesNotExistException) { StregsystemUI.DisplayUserNotFound(username); } }