public void ShowHelp() { var data = _configService.GetAllData(null); _console.ForegroundColor = ConsoleColor.Green; _console.Write("\nTo buy a product insert coin (eg. -coin 11) and then select product (eg. -buy a1). Change will be given."); _console.WriteLine("\nOptions:"); _console.Write("\n-help Display help and commands"); _console.Write("\n-products Shows products to buy with current prices"); _console.Write("\n-buy <product-nr> If enough credits product will be dispatched and change given."); _console.Write("\n-coin <amount> Adds coins to credit"); _console.Write("\n-cancel Returns coins"); _console.Write("\n-currency <currency> Sets new currency"); _console.Write("\n-info Displays raw configuration"); _console.Write("\n-import <path-to-config> Import new configuration. " + "Files for new config (config.json, inventory.json, and exchange_rates.json) must be placed within folder <path-to-config>"); _console.Write("\nCoins credits: " + data.CoinsInSlot.ToString("#0.00")); _console.Write("\nCurrency: " + data.SelectedCurrency); _console.ForegroundColor = ConsoleColor.White; _console.WriteLine("\nType command or type c to exit..."); }
public decimal BuyProduct(string productNr) { productNr = productNr.ToUpperInvariant(); var config = _configService.GetAllData(null); var inventoryWithPrice = config.Inventories.FirstOrDefault(x => x.ProductNr == productNr); Validate(inventoryWithPrice, config); var change = (decimal)0; if (config.CoinsInSlot >= inventoryWithPrice.PriceByRate) { _logger.LogInformation(string.Format("Dispatching product: {0}-{1}", inventoryWithPrice.ProductNr, inventoryWithPrice.Name)); var inventory = _context.Inventory.First(x => x.ProductNr == productNr); inventory.Quantity--; change = config.CoinsInSlot - inventoryWithPrice.PriceByRate; _configService.UpdateCoins(0, true); _context.SaveChanges(); _logger.LogInformation(string.Format("Product dispatched: {0}-{1} ", inventoryWithPrice.ProductNr, inventoryWithPrice.Name)); } return(change); }
public ConfigViewModel Get(string currency) { var config = _configService.GetAllData(currency); return(config); }