public Models.CoffeeMachine SelectCoffeeMachineTotals() { string commandText = @"Select * from CoffeeMachine"; Models.CoffeeMachine coffeeMachine = new Models.CoffeeMachine(); using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { using (var dr = command.ExecuteReader()) { while (dr.Read()) { coffeeMachine.Id = (int)dr["Id"]; coffeeMachine.TotalCoffee = (int)dr["TotalCoffee"]; coffeeMachine.TotalSugar = (int)dr["TotalSugar"]; coffeeMachine.TotalWater = (int)dr["TotalWater"]; } } } } return(coffeeMachine); }
private Models.CoffeeMachine Recalculation(Models.CoffeeMachine coffeeMachine, int tempCoffeeAmount, int tempSugarAmount, int tempWaterAmount) { coffeeMachine.TotalCoffee -= tempCoffeeAmount; coffeeMachine.TotalSugar -= tempSugarAmount; coffeeMachine.TotalWater -= tempWaterAmount; return(coffeeMachine); }
public void RecalculationTotals(Models.CoffeeMachine coffeeMachine, int id) { string commandText = @$ "Update CoffeeMachine set TotalCoffee = @coffee, TotalSugar = @sugar, TotalWater = @water where Id = {id}"; using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = new SqlCommand(commandText, connection)) { command.Parameters.AddWithValue("@coffee", coffeeMachine.TotalCoffee); command.Parameters.AddWithValue("@sugar", coffeeMachine.TotalSugar); command.Parameters.AddWithValue("@water", coffeeMachine.TotalWater); command.ExecuteNonQuery(); } } }
public Tuple <Coffee, Models.CoffeeMachine> ChooseCoffee(List <Coffee> coffees, Models.CoffeeMachine coffeeMachineTotals, int totalMoney) { Console.WriteLine("Please choose coffee."); Console.WriteLine("Coffees list: -----------------------\n"); for (int i = 0; i < coffees.Count; i++) { Console.WriteLine($"{i + 1}: CoffeeAmount: {coffees[i].Amount}, Price: {coffees[i].Price}, SugarAmount: {coffees[i].Sugar.Amount}, WaterAmount: {coffees[i].Water.Amount}"); } bool exactNumber = true; int coffeeNumber = 0; while (exactNumber) { Console.Write("\nEnter 1-10 to choose coffee: "); coffeeNumber = int.Parse(Console.ReadLine()); if (coffeeNumber > 0 && coffeeNumber < 11) { Console.WriteLine($"Selected number {coffeeNumber} coffee."); try { if (coffees[coffeeNumber - 1].Price > totalMoney) { throw new InsufficientFundsException("Your money is not enough."); } if (coffees[coffeeNumber - 1].Amount > coffeeMachineTotals.TotalCoffee || coffees[coffeeNumber - 1].Sugar.Amount > coffeeMachineTotals.TotalSugar || coffees[coffeeNumber - 1].Water.Amount > coffeeMachineTotals.TotalWater) { throw new InsufficientFundsException("Insufficient funds in coffee machine!!! Please enter other coffee."); } } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } Recalculation(coffeeMachineTotals, coffees[coffeeNumber - 1].Amount, coffees[coffeeNumber - 1].Sugar.Amount, coffees[coffeeNumber - 1].Water.Amount); var money = RefundableMoney(coffees[coffeeNumber - 1].Price, totalMoney); Console.WriteLine($"{coffeeNumber}: CoffeeAmount: {coffees[coffeeNumber - 1].Amount}, SugarAmount: {coffees[coffeeNumber - 1].Sugar.Amount}, WaterAmount: {coffees[coffeeNumber - 1].Water.Amount}"); exactNumber = false; Console.WriteLine("Coffee is ready!"); Console.WriteLine($"Refundable money is {money}"); } else { try { throw new ArgumentException("There is no coffee with this number, please indicate the correct number."); } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } } } return(Tuple.Create(coffees[coffeeNumber - 1], coffeeMachineTotals)); }