-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceHistory.cs
More file actions
114 lines (104 loc) · 3.25 KB
/
Copy pathServiceHistory.cs
File metadata and controls
114 lines (104 loc) · 3.25 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
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace mp2
{
internal class ServiceHistory
{
private static List<ServiceHistory> _serviceHistoryExtent = new();
public static List<ServiceHistory> ServiceHistoryExtent
{
get => _serviceHistoryExtent.ToList();
}
//assocjacja zwykła
private Car _car;
public Car Car
{
get => _car;
set
{
if (value == null)
{
throw new Exception("Car cannot be null");
}
else if(value.Equals(this.Car))
{
return;
}
else
{
_car = value;
value.ServiceHistory = this;
}
}
}
//assocjacja kwalifikowana
private Dictionary<int, Service> _pastservices = new();
public Dictionary<int, Service> PastServices
{
get => _pastservices.ToDictionary(val => val.Key, val => val.Value);
set
{
if (value != null)
{
foreach (var pastservice in value)
{
if (pastservice.Value == null)
{
throw new Exception("PastService cannot be null");
}
else if (pastservice.Value.Equals(this.PastServices))
{
throw new Exception("PastService cannot be the same");
}
else
{
_pastservices.Add(pastservice.Key, pastservice.Value);
}
}
}
else
{
throw new Exception("PastServices cannot be null");
}
}
}
public ServiceHistory(Car car)
{
this.Car = car;
_serviceHistoryExtent.Add(this);
}
//assocjacja kwalifikowana
public void AddNewServiceToHistory(Service service)
{
if ( service == null)
{
throw new Exception("Service cannot be null");
}
//tu zmnieniłem na czeka rekurencje
//else if (service.ServiceHistory.Equals(this))
//{
// return;
//}
else
{
_pastservices.Add(service.ServiceId, service);
service.ServiceHistory = this;
}
}
public string GetServiceHistory()
{
StringBuilder sb = new();
sb.Append($"======== ServiceHistory for Car idndetified by VIN: {Car.VIN} ======== \n");
sb.Append($"PastServices: \n");
foreach (var pastservice in PastServices)
{
sb.Append($"{pastservice.Value.ToString()} \n");
}
sb.Append($"=================================================\n");
return sb.ToString();
}
}
}