-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cart.cs
72 lines (62 loc) · 1.79 KB
/
Cart.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
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KisokDemo1
{
class Cart
{
private List<Product> products;
private decimal total;
public Cart()
{
products = new List<Product>();
}
public void AddToCart(Product product)
{
products.Add(product);
}
public void RemoveFromCart(Product product)
{
products.Remove(product);
}
public List<Product> GetAllProducts()
{
return products;
}
public decimal Total()
{
total = 0.0m;
foreach (var item in products)
{
total += item.price;
}
return total;
}
public string GetOrder()
{
List<string> output = new List<string>();
foreach (var item in products)
{
if (item is CustomSandwich)
{
CustomSandwich custom = (CustomSandwich)item;
List<string> output2 = new List<string>();
//custom.Toppings
foreach (var topping in custom.Toppings)
{
output.Add(topping.name + "," + item.price);
}
output.Add(item.name + "," + item.price + "," + string.Join(",", output2));
}
else
{
output.Add(item.name + "," + item.price);
}
}
output.Add("Total:" + Total());
return string.Join("\r\n", output);
}
}
}