/
NotificationOrder.cs
120 lines (100 loc) · 3.36 KB
/
NotificationOrder.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
using System.Text.Json;
using Altinn.Notifications.Core.Enums;
using Altinn.Notifications.Core.Models.NotificationTemplate;
namespace Altinn.Notifications.Core.Models.Orders;
/// <summary>
/// Class representing a notification order
/// </summary>
public class NotificationOrder : IBaseNotificationOrder
{
/// <inheritdoc/>>
public Guid Id { get; internal set; } = Guid.Empty;
/// <inheritdoc/>>
public string? SendersReference { get; internal set; }
/// <inheritdoc/>>
public DateTime RequestedSendTime { get; internal set; }
/// <inheritdoc/>>
public NotificationChannel NotificationChannel { get; internal set; }
/// <inheritdoc/>>
public bool IgnoreReservation { get; internal set; }
/// <inheritdoc/>>
public Creator Creator { get; internal set; }
/// <inheritdoc/>>
public DateTime Created { get; internal set; }
/// <summary>
/// Gets the templates to create notifications based of
/// </summary>
public List<INotificationTemplate> Templates { get; internal set; } = new List<INotificationTemplate>();
/// <summary>
/// Gets a list of recipients
/// </summary>
public List<Recipient> Recipients { get; internal set; } = new List<Recipient>();
/// <summary>
/// Initializes a new instance of the <see cref="NotificationOrder"/> class.
/// </summary>
public NotificationOrder(
Guid id,
string? sendersReference,
List<INotificationTemplate> templates,
DateTime requestedSendTime,
NotificationChannel notificationChannel,
Creator creator,
DateTime created,
List<Recipient> recipients,
bool ignoreReservation)
{
Id = id;
SendersReference = sendersReference;
Templates = templates;
RequestedSendTime = requestedSendTime;
NotificationChannel = notificationChannel;
Creator = creator;
Created = created;
Recipients = recipients;
IgnoreReservation = ignoreReservation;
}
/// <summary>
/// Initializes a new instance of the <see cref="NotificationOrder"/> class.
/// </summary>
internal NotificationOrder()
{
Creator = new Creator(string.Empty);
}
/// <summary>
/// Json serializes the <see cref="NotificationOrder"/>
/// </summary>
public string Serialize()
{
return JsonSerializer.Serialize(this, JsonSerializerOptionsProvider.Options);
}
/// <summary>
/// Deserialize a json string into the <see cref="NotificationOrder"/>
/// </summary>
public static NotificationOrder? Deserialize(string serializedString)
{
return JsonSerializer.Deserialize<NotificationOrder>(serializedString, JsonSerializerOptionsProvider.Options);
}
/// <summary>
/// Try to parse a json string into a<see cref="NotificationOrder"/>
/// </summary>
public static bool TryParse(string input, out NotificationOrder value)
{
NotificationOrder? parsedOutput;
value = new NotificationOrder();
if (string.IsNullOrEmpty(input))
{
return false;
}
try
{
parsedOutput = Deserialize(input!);
value = parsedOutput!;
return value.Id != Guid.Empty;
}
catch
{
// try parse, we simply return false if fails
}
return false;
}
}