-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileContent.cs
117 lines (97 loc) · 2.5 KB
/
FileContent.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
using Newtonsoft.Json;
namespace NACHAParser
{
public class Root
{
#region Properties
[JsonProperty("fileContents")]
public FileContents? FileContents { get; set; }
#endregion
}
public class FileContents
{
#region Properties
[JsonProperty("fileId")]
public string FileId { get; set; } = string.Empty;
[JsonProperty("achFile")]
public ACHFile? ACHFile { get; set; }
#endregion
#region Constructors
public FileContents()
{
FileId = Guid.NewGuid().ToString();
Console.WriteLine($"FileId: '{FileId}'");
}
#endregion
}
public class ACHFile
{
#region Fields
private Batch? _currentBatch;
private List<Batch>? _batches = new List<Batch>();
#endregion
#region Properties
[JsonProperty("achFileId")]
public string AchFileId { get; set; } = string.Empty;
[JsonProperty("fileHeader")]
public FileHeaderRecord? FileHeader { get; set; }
[JsonProperty("batches")]
public IReadOnlyList<Batch>? Batches
{
get
{
return _batches;
}
}
[JsonProperty("fileControl")]
public FileControlRecord? FileControl { get; set; }
public Batch? CurrentBatch
{
get
{
return _currentBatch;
}
private set
{
_currentBatch = value;
}
}
#endregion
#region Constructors
public ACHFile()
{
AchFileId = Guid.NewGuid().ToString();
Console.WriteLine($"AchFileId: '{AchFileId}'");
}
#endregion
#region Methods
public void AddBatch(Batch batch)
{
_batches.Add(batch);
SetCurrentBatch(batch);
}
public void SetCurrentBatch(Batch batch)
{
if (_batches.Contains(batch))
{
CurrentBatch = batch;
}
else
{
throw new Exception("Batch not found in list of batches");
}
}
public Batch GetCurrentBatch()
{
if (CurrentBatch == null)
{
throw new Exception("CurrentBatch is null");
}
else
{
return CurrentBatch;
}
}
#endregion
}
}