-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
101 lines (95 loc) · 4.78 KB
/
Program.cs
File metadata and controls
101 lines (95 loc) · 4.78 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using Ecommerce_API.Dtos;
using Ecommerce_API.models;
using System.Text.Json;
using System.Threading.Tasks;
using Ecommerce_API.Menus;
using System.Security.Cryptography.X509Certificates;
namespace Ecommerce_API
{
internal class Program
{
static async Task Main(string[] args)
{
using (HttpClient client = new HttpClient())
{
try
{
string response = await client.GetStringAsync("https://dummyjson.com/products?limit=100");
var data = JsonSerializer.Deserialize<ProductsResponse>(response, new JsonSerializerOptions {
PropertyNameCaseInsensitive = true
});
var products = data?.Products ?? new List<Product>();
Cart cart = new Cart();
ShowMenuOptions(products, cart);
}
catch (Exception excecao)
{
Console.WriteLine("Ocorreu um erro: " + excecao.Message);
}
}
}
static void ShowProjectLogo()
{
Console.WriteLine(@"
██ ▄▄▄ ▄▄ ▄▄ ▄▄ ▄▄ ▄▄ ▄▄ ▄▄▄ ▄▄ ▄▄ ▄▄▄ ▄█████ ▄▄▄ ▄▄ ▄▄ ▄▄▄▄ ▄▄▄ ▄▄ ▄▄▄▄▄
██ ██▀██ ██ ██ ███▄██ ██▄██ ██▀██ ███▄██ ██▀██ ██ ██▀██ ███▄██ ███▄▄ ██▀██ ██ ██▄▄
██████ ▀███▀ ▄▄█▀ ██ ██ ▀██ ██ ██ ██▀██ ██ ▀██ ▀███▀ ▀█████ ▀███▀ ██ ▀██ ▄▄██▀ ▀███▀ ██▄▄▄ ██▄▄▄
");
Console.WriteLine("***** Boas vindas a Lojinha no Console! *****");
}
public static void ShowMenuOptions(List<Product> products, Cart cart)
{
ShowProjectLogo();
Console.WriteLine("\n============== Menu de Opções: ==============\n");
Console.WriteLine("> Digite 1 para visualizar todos os produtos");
Console.WriteLine("> Digite 2 para buscar um produto");
Console.WriteLine("> Digite 3 para adicionar um produto ao carrinho");
Console.WriteLine("> Digite 4 para remover um produto do carrinho");
Console.WriteLine("> Digite 5 para pagar");
Console.WriteLine("> Digite -1 para sair");
Console.WriteLine("\n=============================================");
Console.Write("Selecione uma opção: ");
string userInput = Console.ReadLine()!;
int option = int.Parse(userInput);
switch (option)
{
case 1:
ViewProductsMenu viewProductsMenu = new ViewProductsMenu();
viewProductsMenu.ShowProducts(products);
ShowMenuOptions(products, cart);
break;
case 2:
SearchProductMenu searchProductMenu = new SearchProductMenu();
searchProductMenu.SearchProduct(products);
ShowMenuOptions(products, cart);
break;
case 3:
AddToCartMenu addToCartMenu = new AddToCartMenu();
addToCartMenu.AddProductToCart(products, cart);
ShowMenuOptions(products, cart);
break;
case 4:
RemoveToCartMenu removeToCartMenu = new RemoveToCartMenu();
removeToCartMenu.RemoveProductToCart(cart);
ShowMenuOptions(products, cart);
break;
case 5:
PaymentMenu paymentMenu = new PaymentMenu();
paymentMenu.PayCart(products, cart);
ShowMenuOptions(products, cart);
break;
case -1:
Console.WriteLine("\n=> Obrigado por usar a Lojinha no Console! Até a próxima.");
Thread.Sleep(2000);
Environment.Exit(0);
break;
default:
Console.WriteLine("Opção inválida. Tente novamente.");
Thread.Sleep(2000);
Console.Clear();
ShowMenuOptions(products, cart);
break;
}
}
}
}