-
Notifications
You must be signed in to change notification settings - Fork 0
/
MolioSpecificationFile.cs
211 lines (154 loc) · 6.7 KB
/
MolioSpecificationFile.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.IO;
using System.Text;
namespace MolioDocEF6
{
public class MolioSpecificationFile : DbContext
{
public DbSet<WorkSpecification> WorkSpecifications { get; set; }
public DbSet<WorkSpecificationSection> WorkSpecificationSections { get; set; }
public DbSet<ConstructionElementSpecificationSection> ConstructionElementSpecificationSections { get; set; }
public DbSet<ConstructionElementSpecification> ConstructionElementSpecifications { get; set; }
public DbSet<Attachment> Attachments { get; set; }
public DbSet<CustomData> CustomData { get; set; }
/// <param name="contextOwnsConnection">If set to true the connection is disposed when the context is disposed, otherwise the caller must dispose the connection.</param>
public MolioSpecificationFile(DbConnection connection, bool contextOwnsConnection)
: base(connection, contextOwnsConnection) { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
public interface ISection
{
int SectionNo { get; set; }
string Heading { get; set; }
string Body { get; set; }
Guid MolioSectionGuid { get; set; }
int? ParentId { get; set; }
}
[Table("work_specification")]
public partial class WorkSpecification
{
[Key, Column("work_specification_id")]
public int WorkSpecificationId { get; set; }
[Column("work_area_name")]
public string WorkAreaName { get; set; }
[Column("work_area_code")]
public string WorkAreaCode { get; set; }
public Guid Key { get; set; }
public List<WorkSpecificationSection> Sections { get; set; } = new List<WorkSpecificationSection>();
}
[Table("work_specification_section")]
public partial class WorkSpecificationSection : ISection
{
[Key, Column("work_specification_section_id")]
public int WorkSpecificationSectionId { get; set; }
[Column("work_specification_id")]
public int WorkSpecificationId { get; set; }
[Column("section_no")]
public int SectionNo { get; set; }
public string Heading { get; set; }
public string Body { get; set; } = "";
[Column("molio_section_guid")]
public Guid MolioSectionGuid { get; set; }
[Column("parent_id")]
public int? ParentId { get; set; }
[ForeignKey(nameof(ParentId))]
public WorkSpecificationSection Parent { get; set; }
public List<WorkSpecificationSection> Sections { get; set; } = new List<WorkSpecificationSection>();
public List<WorkSpecificationSectionConstructionElementSpecification> WorkSpecificationSectionConstructionElementSpecifications { get; set; }
= new List<WorkSpecificationSectionConstructionElementSpecification>();
}
[Table("work_specification_section_construction_element_specification")]
public class WorkSpecificationSectionConstructionElementSpecification
{
[Key, Column("work_specification_section_construction_element_specification_id")]
public int ArbejdsbeskrivelseSectionBygningsdelsbeskrivelseId { get; set; }
[Column("work_specification_section_id")]
public int WorkSpecificationSectionId { get; set; }
[Column("construction_element_specification_id")]
public int ConstructionElementSpecificationId { get; set; }
}
[Table("construction_element_specification")]
public partial class ConstructionElementSpecification
{
[Key, Column("construction_element_specification_id")]
public int ConstructionElementSpecificationId { get; set; }
[Column("molio_specification_guid")]
public Guid MolioSpecificationGuid { get; set; }
public string Title { get; set; }
public List<ConstructionElementSpecificationSection> Sections { get; set; } = new List<ConstructionElementSpecificationSection>();
}
[Table("construction_element_specification_section")]
public partial class ConstructionElementSpecificationSection : ISection
{
[Key, Column("construction_element_specification_section_id")]
public int ConstructionElementSpecificationSectionId { get; set; }
[Column("construction_element_specification_id")]
public int ConstructionElementSpecificationId { get; set; }
public ConstructionElementSpecification ConstructionElementSpecification { get; set; }
[Column("section_no")]
public int SectionNo { get; set; }
public string Heading { get; set; }
public string Body { get; set; } = "";
[Column("molio_section_guid")]
public Guid MolioSectionGuid { get; set; }
[Column("parent_id")]
public int? ParentId { get; set; }
[ForeignKey(nameof(ParentId))]
public ConstructionElementSpecificationSection Parent { get; set; }
public List<ConstructionElementSpecificationSection> Sections { get; set; } = new List<ConstructionElementSpecificationSection>();
}
[Table("attachment")]
public partial class Attachment
{
[Key, Column("attachment_id")]
public int AttachmentId { get; set; }
public string Name { get; set; }
[Column("mime_type")]
public string MimeType { get; set; }
public byte[] Content { get; set; }
public byte[] Hash { get; set; }
public static Attachment Json(string name, string content) =>
new Attachment
{
Name = name,
MimeType = "application/json",
Content = Encoding.UTF8.GetBytes(content)
};
public static Attachment Pdf(string name, Stream stream) =>
new Attachment
{
Name = name,
MimeType = "application/pdf",
Content = StreamToBytes(stream)
};
static byte[] StreamToBytes(Stream stream)
{
using (var memory = new MemoryStream())
{
stream.CopyTo(memory);
return memory.ToArray();
}
}
}
[Table("custom_data")]
public class CustomData
{
[Key]
public string Key { get; set; }
public byte[] Value { get; set; }
public CustomData(string key, byte[] value)
{
Key = key;
Value = value;
}
}
}