private static void RequestSoda() { // Identify which soda the user wants var sodas = _sodaMachine.ListTypesOfSoda(); var i = 1; Console.Clear(); Console.WriteLine("Which soda number would you like?:"); sodas.ForEach(x => Console.WriteLine($"{ i++ } - { x.Name }")); string sodaIdentifier = Console.ReadLine(); bool isValidIdentifier = int.TryParse(sodaIdentifier, out int sodaNumber); SodaModel soda; try { soda = sodas[sodaNumber - 1]; } catch { Console.WriteLine("That was not a valid soda number."); Console.WriteLine(); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); return; } // Request that soda var results = _sodaMachine.RequestSoda(soda, userId); // Handle the response if (results.errorMessage.Length > 0) { Console.WriteLine(results.errorMessage); } else { Console.Clear(); Console.WriteLine($"Here is your { results.soda.Name }"); if (results.change.Count > 0) { Console.WriteLine("Here is your change:"); results.change.ForEach(x => Console.WriteLine(x.Name)); } else { Console.WriteLine("No change returned. Used exact change."); } } Console.WriteLine(); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); }
private static void RequestSoda() { var sodaOptions = _sodaMachine.ListTypesOfSoda(); var i = 1; Console.Clear(); Console.WriteLine($"The soda options are "); sodaOptions.ForEach(x => Console.WriteLine($"{i++} - {x.Name}")); string sodaIndentifier = Console.ReadLine(); bool isValidNumber = int.TryParse(sodaIndentifier, out int sodaNumber); SodaModel soda; try { soda = sodaOptions[sodaNumber - 1]; } catch { Console.WriteLine("That was not a correct response"); Message(); return; } var results = _sodaMachine.RequestSoda(soda, userId); if (results.errorMessage.Length > 0) { Console.WriteLine(results.errorMessage); } else { Console.WriteLine($"Here is your {results.soda.Name}"); if (results.change.Count > 0) { Console.WriteLine("Here is your change: "); results.change.ForEach(x => Console.WriteLine(x.Name)); } else { Console.WriteLine("There is now change"); } } Message(); }
public void OnGet() { UserId = User.FindFirstValue(ClaimTypes.NameIdentifier); SodaPrice = _sodaMachine.GetSodaPrice(); DepositedAmount = _sodaMachine.GetMoneyInsertedTotal(UserId); SodaOptions = _sodaMachine.ListTypesOfSoda(); }
public IActionResult OnGet() { UserId = User.FindFirstValue(ClaimTypes.NameIdentifier); AcceptedCoinsValue = _sodaMachineLogic.AcceptedCoinValues; SodaPrice = _sodaMachineLogic.GetSodaPrice(); SodasInStock = _sodaMachineLogic.GetSodaInventory(); TypesOfSoda = _sodaMachineLogic.ListTypesOfSoda(); UserCredit = _sodaMachineLogic.GetMoneyInsertedTotal(UserId); SodaSelectList = SodasInStock.Select((sodaModel, index) => { return(new SelectListItem($"{sodaModel.Name} {sodaModel.SlotOccupied}", index.ToString())); }).ToList(); return(Page()); }