-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserInput.cs
67 lines (51 loc) · 1.8 KB
/
UserInput.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace drinks_info
{
public class UserInput
{
//1 passo - criar a classe que pega o input do usuário
DrinksService drinksService = new();
public void GetCategoriesInput()
{
var categories = drinksService.GetCategories();
Console.WriteLine("Choose category:");
string category = Console.ReadLine();
while (!Validator.IsStringValid(category))
{
Console.WriteLine("\nInvalid category");
category = Console.ReadLine();
}
if (!categories.Any(x => x.strCategory == category))
{
Console.WriteLine("Category doesn't exist.");
GetCategoriesInput();
}
GetDrinksInput(category);
}
private void GetDrinksInput(string category)
{
var drinks = drinksService.GetDrinksByCategory(category);
Console.WriteLine("Choose a drink or go back to category menu by type 0");
string drink = Console.ReadLine();
if (drink == "0")
GetCategoriesInput();
while (!Validator.IsIdValid(drink))
{
Console.WriteLine("\nInvalid drink");
drink = Console.ReadLine();
}
if (!drinks.Any(x => x.idDrink == drink))
{
Console.WriteLine("Drink doesn't exist.");
GetDrinksInput(category);
}
drinksService.GetDrink(drink);
Console.WriteLine("Press any key to go back to categories menu");
Console.ReadKey();
if (!Console.KeyAvailable) GetCategoriesInput();
}
}
}