-
Notifications
You must be signed in to change notification settings - Fork 1
/
Order.cs
87 lines (79 loc) · 2.4 KB
/
Order.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace task_2
{
internal class Order
{
private Product[] allProducts;
private float totalPrice = 0;
private User buyerDetails;
public float TotalPrice
{
get { return totalPrice; }
set { totalPrice = SetOrderPrice(); }
}
public Order(Product[] products, int cart_size, User b)
{
SetCheckOut(cart_size, products);
totalPrice = SetOrderPrice();
buyerDetails = b;
}
private void SetCheckOut(int cart_size, Product[] cartProducts)
{
this.allProducts = new Product[cart_size];
for(int i = 0; i < cart_size; i++)
{
bool hasSpecialBox = cartProducts[i] is ProductExtraFields productExtra ? productExtra.GetHasSpecialBox() : false;
if (cartProducts[i] != null)
{
this.allProducts[i] = new ProductExtraFields(cartProducts[i].Id, cartProducts[i].Name, cartProducts[i].Price, cartProducts[i].Category, hasSpecialBox);
}
}
}
private float SetOrderPrice()
{
float price = 0;
foreach (ProductExtraFields product in allProducts)
{
if (product != null)
{
if (product.GetHasSpecialBox())
{
price += product.GetExtraPrice();
}
price += product.Price;
}
else
break;
}
return price;
}
public void HistroyCart()
{
foreach (var item in allProducts)
{
if(item != null)
{
Console.WriteLine(item.ToString());
}
}
}
public string ToString()
{
string resProducts = "";
foreach (Product product in allProducts)
{
if(product == null)
{
break;
}
resProducts += product.ToString();
}
return $"\t# total price: {TotalPrice}\n {resProducts}\n ";
}
}
}