-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrder.cs
101 lines (85 loc) · 2.66 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Inventory_Management_System_Console_App
{
public class Order : ICloneable
{
private Product product;
private Customer customer;
private int quantity;
private double price;
private int orderID;
private static int nextOrderID = 1;
private List<Product> listOfProducts = new List<Product>();
public Order(Product product, Customer customer, int quantity, double price)
{
this.product = product;
this.customer = customer;
this.quantity = quantity;
this.price = this.quantity * price;
this.orderID = nextOrderID;
Order.nextOrderID++;
this.listOfProducts.Add(this.product);
product.GetQuantity -= quantity;
}
private Order(Order order)
{
this.product = order.product;
this.listOfProducts.Add(order.product);
this.customer = order.customer;
this.quantity = order.quantity;
this.price = order.price;
this.orderID = order.orderID;
}
public void AddProduct(Product product)
{
listOfProducts.Add(product);
}
//Doesn't remove the product, the logic is wrong; but at least there's no error
public void RemoveProduct(Product product, Order order, int productID)
{
Product? productToRemove = listOfProducts.Find(p => p.GetID == productID);
if (productToRemove != null)
listOfProducts.Remove(productToRemove);
}
public void UpdateQuantity(Product productQuantity)
{
Product product = new Product(productQuantity);
product.GetQuantity += productQuantity.GetQuantity;
}
public void UpdatePrice(Product productPrice)
{
Product product = new Product(productPrice);
product.GetPrice += productPrice.GetPrice;
}
public Product GetProduct
{
get { return product; }
}
public Customer GetCustomer
{
get { return customer; }
}
public int GetQuantity
{
get { return quantity; }
}
public double GetPrice
{
get {return price; }
}
public int GetID
{
get { return orderID; }
}
public object Clone()
{
return new Order(this);
}
}
}