public override void Execute() { if (!HasEnoughArguments(3)) { barcodeCli.DisplayNotEnoughArguments(Command); return; } string username = Command[1]; string amountString = Command[2]; try { User user = barcodeSystem.GetUserByUsername(username); if (decimal.TryParse(amountString, out decimal amount)) { transaction = barcodeSystem.AddCreditsToAccount(user, amount); barcodeCli.DisplayAddCreditsTransaction(transaction); Succeeded = true; } } catch (UserNotFoundException) { barcodeCli.DisplayUserNotFound(username); } base.Execute(); }
public override void Execute() { if (!HasEnoughArguments(2)) { return; } string username = Command[0]; string productIdString = Command[1]; int amountToPurchase = 1; Product product; User user; if (Command.Length == 3 && !int.TryParse(Command[2], out amountToPurchase)) { barcodeCli.DisplayGeneralError($"{Command[2]} is not a valid amount."); return; } try { user = barcodeSystem.GetUserByUsername(username); if (uint.TryParse(productIdString, out uint productId)) { try { product = barcodeSystem.GetProductById(productId); try { BuyTransaction transaction = barcodeSystem.BuyProduct(user, product, amountToPurchase); this.transaction = transaction; Succeeded = transaction.Succeeded; barcodeCli.DisplayUserBuysProduct(transaction); } catch (InsufficientCreditsException) { barcodeCli.DisplayInsufficientCash(user, product); } } catch (ProductNotFoundException) { barcodeCli.DisplayProductNotFound(productIdString); } } } catch (UserNotFoundException) { barcodeCli.DisplayUserNotFound(username); } base.Execute(); }
public override void Execute() { string username = Command[0]; try { User user = barcodeSystem.GetUserByUsername(username); List <Transaction> transactionsForUser = new List <Transaction>(); transactionsForUser = barcodeSystem .GetTransactionsForUser(user, 10) .Where(t => !t.Undone) .ToList(); barcodeCli.DisplayUserInfo(user, transactionsForUser); } catch (UserNotFoundException) { barcodeCli.DisplayUserNotFound(username); } base.Execute(); }