-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-definitions.cs
123 lines (101 loc) · 3.6 KB
/
class-definitions.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
namespace classes
{
public class Product
{
public string name { get; set; }
public int price { get; set; }
public int stockStatus { get; set; }
public string description { get; set; }
public string category { get; set; }
public int id { get; set; }
public int quantity {get;set;}
//Konstruktør
public Product(string name, int price, int stockStatus, string description, string category,int id)
{
this.name = name;
this.price = price;
this.stockStatus = stockStatus;
this.description = description;
this.category = category;
this.id = id;
this.quantity=0;
}
//Metode der viser et produkt og dets information
public void showProductInfo()
{
Console.WriteLine($"[{this.id}] {this.name}");
System.Console.WriteLine(this.description);
System.Console.WriteLine($"price: {this.price} kr.");
System.Console.WriteLine($"{this.stockStatus} available in warehouse.");
}
public void ShoppingCartStatus(){
Console.WriteLine($"{this.quantity} x {this.name} : {this.price} kr. each");
}
}
public class Products
{
public List<Product> list { get; set; }
public int totalPrice { get; set; }
public int itemCount {get; set;}
public Products()
{
this.list = new List<Product>();
this.totalPrice = 0;
this.itemCount=0;
}
//Denne metode er "Tilføj produkt til indkøbskurv" use casen
//Denne metode tilføjer et produkt til indkøbskurven
public void addProductToShoppingCart(Product product, int amount)
{
bool foundProduct=false;
foreach (var item in this.list)
{
if (item==product){
item.quantity+=amount;
foundProduct=true;
}
}
if(!foundProduct){
product.quantity=amount;
this.list.Add(product);
}
this.totalPrice = this.totalPrice + product.price*amount;
this.itemCount++;
}
public int totalPriceCalc(){
this.totalPrice=0;
foreach (var item in this.list)
{
this.totalPrice=this.totalPrice+item.quantity*item.price;
}
return(this.totalPrice);
}
//tjekker om ønsket antal er ledig på lageret
public bool available(List<Product> products){
foreach (var product in products)
{
if(product.stockStatus<product.quantity){
return(false);
}
}
return(true);
}
//Denne metode opdaterer lageret
public void reduceStockStatus(List<Product> products){
foreach (var product in products)
{
product.stockStatus=product.stockStatus-product.quantity;
}
}
//Denne metode finder et produkt ud fra dets ID
public Product findProductById(int id){
foreach (var item in this.list)
{
if(item.id==id){
return(item);
}
}
return null;
}
}
}