forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlan.cs
95 lines (84 loc) · 1.76 KB
/
Plan.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
using System;
using System.Collections.Generic;
namespace NHibernate.Test.Immutable
{
[Serializable]
public class Plan
{
private long id;
private long version;
private string description;
private ISet<Contract> contracts;
private ISet<Info> infos;
public Plan()
{
}
public Plan(string description)
{
this.description = description;
this.contracts = new HashSet<Contract>();
this.infos = new HashSet<Info>();
}
public virtual long Id
{
get { return id; }
set { id = value; }
}
public virtual long Version
{
get { return version; }
set { version = value; }
}
public virtual string Description
{
get { return description; }
set { description = value; }
}
public virtual ISet<Contract> Contracts
{
get { return contracts; }
set { contracts = value; }
}
public virtual ISet<Info> Infos
{
get { return infos; }
set { infos = value; }
}
public virtual void AddContract(Contract contract)
{
if (!contracts.Add(contract))
{
return;
}
if (contract.Parent != null)
{
AddContract(contract.Parent);
}
contract.Plans.Add(this);
foreach(Contract subContract in contract.Subcontracts)
{
AddContract(subContract);
}
}
public virtual void RemoveContract(Contract contract)
{
if (contract.Parent != null)
{
contract.Parent.Subcontracts.Remove(contract);
contract.Parent = null;
}
RemoveSubcontracts(contract);
contract.Plans.Remove(this);
contracts.Remove(contract);
}
public virtual void RemoveSubcontracts(Contract contract)
{
foreach(Contract subContract in contract.Subcontracts)
{
RemoveSubcontracts(subContract);
subContract.Plans.Remove(this);
contracts.Remove(subContract);
}
}
}
}