-
Notifications
You must be signed in to change notification settings - Fork 38
/
Entities.cs
461 lines (368 loc) · 9.88 KB
/
Entities.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Collections.ObjectModel;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using DemoWebApi.DemoData.Base;
using System.Numerics;
using System.Text.Json.Serialization;
namespace DemoWebApi.DemoData.Base
{
/// <summary>
/// Base class of company and person
/// </summary>
[DataContract(Namespace = Constants.DataNamespace)]
public class Entity
{
public Entity()
{
Addresses = new List<Address>();
}
[DataMember]
public Guid? Id { get; set; }
/// <summary>
/// Name of the entity.
/// </summary>
[DataMember(IsRequired = true)]//MVC and Web API does not care
[System.ComponentModel.DataAnnotations.Required]//MVC and Web API care about only this
[MinLength(2), MaxLength(255)]
public string Name { get; set; }
/// <summary>
/// Multiple addresses
/// </summary>
[DataMember]
public IList<Address> Addresses { get; set; }
[DataMember]
public virtual ObservableCollection<PhoneNumber> PhoneNumbers { get; set; }
public override string ToString()
{
return Name;
}
[DataMember]
[RegularExpression(@"https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)")]
public Uri Web { get; set; }
[DataMember, EmailAddress, MaxLength(255)]
public string EmailAddress { get; set; }
}
}
namespace DemoWebApi.DemoData
{
public sealed class Constants
{
public const string DataNamespace = "http://fonlow.com/DemoData/2014/02";
}
[DataContract(Namespace = Constants.DataNamespace)]
public enum AddressType
{
[EnumMember]
Postal,
[EnumMember]
Residential,
};
[DataContract(Namespace = Constants.DataNamespace)]
public enum MyEnumType
{
[EnumMember]
First = 1,
[EnumMember]
Two = 2,
};
[DataContract(Namespace = Constants.DataNamespace)]
public enum Days
{
[EnumMember]
Sat = 1,
[EnumMember]
Sun,
[EnumMember]
Mon,
[EnumMember]
Tue,
[EnumMember]
Wed,
/// <summary>
/// Thursday
/// </summary>
[EnumMember]
Thu,
[EnumMember]
Fri
};
[DataContract(Namespace = Constants.DataNamespace)]
public class PhoneNumber
{
public PhoneNumber()
{
}
public Guid Id { get; set; }
[DataMember]
[MaxLength(120), Phone]
public string FullNumber { get; set; }
[DataMember]
public PhoneType PhoneType { get; set; }
public Guid EntityId { get; set; }
}
/// <summary>
/// Phone type
/// Tel, Mobile, Skyp and Fax
///
/// </summary>
[DataContract(Namespace = Constants.DataNamespace)]
public enum PhoneType
{
/// <summary>
/// Land line
/// </summary>
[EnumMember]
Tel = 0,
/// <summary>
/// Mobile phone
/// </summary>
[EnumMember]
Mobile = 1,
[EnumMember]
Skype = 2,
[EnumMember]
Fax = 3,
}
[DataContract(Namespace = Constants.DataNamespace)]
public class Address
{
[DataMember]
public Guid Id { get; set; }
public Entity Entity { get; set; }
/// <summary>
/// Foreign key to Entity
/// </summary>
public Guid EntityId { get; set; }
[DataMember]
[StringLength(100, MinimumLength = 2)]
public string Street1 { get; set; }
[DataMember]
[Length(2, 100)]
public string Street2 { get; set; }
[DataMember]
[StringLength(50, MinimumLength = 2)]
public string City { get; set; }
[DataMember]
[StringLength(30, MinimumLength = 2)]
public string State { get; set; }
[DataMember]
[StringLength(10, MinimumLength = 2)]
public string PostalCode { get; set; }
[DataMember]
[StringLength(30, MinimumLength = 2)]
[System.ComponentModel.DefaultValue("Australia")]
public string Country { get; set; }
[System.ComponentModel.DefaultValue(AddressType.Residential)]
[DataMember]
public AddressType Type { get; set; }
/// <summary>
/// It is a field
/// </summary>
[DataMember]
public DemoWebApi.DemoData.Another.MyPoint Location;
}
[DataContract(Namespace = Constants.DataNamespace)]
public class IntegralEntity : Entity
{
[DataMember]
public sbyte SByte { get; set; }
[DataMember]
public byte Byte { get; set; }
[DataMember]
public short Short { get; set; }
[DataMember]
public ushort UShort { get; set; }
[DataMember]
public int Int { get; set; }
[DataMember]
public uint UInt { get; set; }
[Range(-1000, 1000000)]
[DataMember]
public int ItemCount { get; set; }
}
[DataContract(Namespace = Constants.DataNamespace)]
public class Person : Entity
{
[DataMember]
public string Surname { get; set; }
[DataMember]
public string GivenName { get; set; }
/// <summary>
/// Date of Birth.
/// This is optional.
/// </summary>
[DataMember]
public DateOnly? DOB { get; set; }
[DataMember]
[DataType(DataType.Date)]
public DateTimeOffset? Baptised { get; set; }
public override string ToString()
{
return Surname + ", " + GivenName;
}
}
[DataContract(Namespace = Constants.DataNamespace)]
public class Company : Entity
{
/// <summary>
/// BusinessNumber to be serialized as BusinessNum
/// </summary>
[DataMember(Name = "business_no")]
[JsonPropertyName("business_no")]
public string BusinessNumber { get; set; }
[DataMember]
public string BusinessNumberType { get; set; }
[DataMember]
public string[][] TextMatrix
{ get; set; }
[DataMember]
public int[][] Int2DJagged;
[DataMember]
public int[,] Int2D;
[DataMember]
public IEnumerable<string> Lines;
[DataMember]
public DateOnly RegisterDate { get; set; }
[DataMember]
[DataType(DataType.Date)]
public DateTimeOffset FoundDate { get; set; }
}
[DataContract(Namespace = Constants.DataNamespace)]
public class MyPeopleDic
{
[DataMember]
public IDictionary<string, Person> Dic { get; set; }
[DataMember]
public IDictionary<string, string> AnotherDic { get; set; }
[DataMember]
public IDictionary<int, string> IntDic { get; set; }
}
[DataContract(Namespace = Constants.DataNamespace)]
public class MimsResult<T>
{
[DataMember]
public T Result { get; set; }
[DataMember]
public DateTime GeneratedAt { get; set; }
[DataMember]
public bool Success { get; set; } = true;
[DataMember]
public string Message { get; set; }
}
[DataContract(Namespace = Constants.DataNamespace)]
public class MimsPackage
{
[DataMember]
public MimsResult<decimal> Result { get; set; }
[DataMember]
public string Tag { get; set; }
[DataMember]
[Range(10, 100, ErrorMessage = "KK has to be between 10 and 100.")]
[System.ComponentModel.DefaultValue(20)]
public int KK { get; set; }
/// <summary>
/// Having an initialized value in the property is not like defining a DefaultValueAttribute. Such intialization happens at run time,
/// and there's no reliable way for a codegen to know if the value is declared by the programmer, or is actually the natural default value like 0.
/// </summary>
[DataMember]
public int KK2 { get; set; } = 2;
[DataMember]
public int? OptionalInt { get; set; }
[DataMember]
public MyEnumType? OptionalEnum { get; set; }
}
[DataContract(Namespace = Constants.DataNamespace)]
public class MyGeneric<T, K, U>
{
[DataMember]
public T MyT { get; set; }
[DataMember]
public K MyK { get; set; }
[DataMember]
public U MyU { get; set; }
[DataMember]
public string Status { get; set; }
}
[DataContract(Namespace = Constants.DataNamespace)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public enum MedicalContraindiationResponseTypeReason
{
[System.Runtime.Serialization.EnumMemberAttribute(Value = "Mm")]
M = 0,
[System.Runtime.Serialization.EnumMemberAttribute(Value = "Ss")]
S = 1,
[System.Runtime.Serialization.EnumMemberAttribute(Value = "Pp")]
P = 2,
[System.Runtime.Serialization.EnumMemberAttribute(Value = "I")]
I = 3,
[System.Runtime.Serialization.EnumMemberAttribute(Value = "A")]
A = 4,
}
[DataContract(Namespace = Constants.DataNamespace)]
//[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
public enum MedicalContraindiationResponseTypeTypeCode
{
[System.Runtime.Serialization.EnumMemberAttribute(Value = "P")]
P = 0,
[System.Runtime.Serialization.EnumMemberAttribute(Value = "Tt")]
T = 1,
}
/// <summary>
/// To test different serializations against Guid
/// </summary>
[DataContract(Namespace = Constants.DataNamespace)]
public class IdMap
{
[DataMember]
public Guid Id { get; set; }
[DataMember]
public Guid? NullableId { get; set; }
[DataMember(EmitDefaultValue = false)]
public Guid IdNotEmitDefaultValue { get; set; }
[DataMember(IsRequired = true)]
[Required] // ASP.NET with System.Text.Json won't respect DataMember(IsRequired = true), thus add this.
public string RequiredName { get; set; }
[DataMember()]
public string Text { get; set; }
}
/// <summary>
///
/// </summary>
[DataContract(Namespace = Constants.DataNamespace)]
public class BigNumbers
{
[DataMember]
public long Signed64 { get; set; }
[DataMember]
public ulong Unsigned64 { get; set; }
[DataMember]
public Int128 Signed128 { get; set; }
[DataMember]
public UInt128 Unsigned128 { get; set; }
[DataMember()]
public BigInteger BigInt { get; set; }
}
}
namespace DemoWebApi.DemoData.Another
{
/// <summary>
/// 2D position
/// with X and Y
/// for Demo
/// </summary>
[JsonObject]
public struct MyPoint
{
/// <summary>
/// X
/// </summary>
public double X;
/// <summary>
/// Y
/// </summary>
public double Y;
}
}