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() { try { List <ICommand> commands = commandsEntered.Where(command => command.Succeeded).ToList(); barcodeCli.DisplayCommandLog(commands); } catch (Exception e) { barcodeCli.DisplayGeneralError(e.ToString()); } base.Execute(); }
public BarcodeSystem AddProductDataStore(IDataStore <Product> productDataStore) { this.productDataStore = productDataStore; try { IEnumerable <Product> productStore = this.productDataStore.ReadData(); Products = productStore.ToList(); } catch { barcodeCli.DisplayGeneralError("Product data store not loaded." + "\n" + "Please make sure that you have provided the correct data." + "\n" + "Could not find:" + "\n" + $"{this.productDataStore.fullFilePath}"); barcodeCli.AwaitKeyPress().Close(); } return(this); }
public override void Execute() { try { CommandToUndo = commandsExecuted.FindLast(command => !command.Undone && command.Succeeded); CommandToUndo?.Undo(); Succeeded = true; barcodeCli.DisplayUndoCommand(CommandToUndo); } catch { barcodeCli.DisplayGeneralError("There is no command to undo."); } base.Execute(); }