-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationDL.cs
More file actions
301 lines (281 loc) · 12.4 KB
/
NotificationDL.cs
File metadata and controls
301 lines (281 loc) · 12.4 KB
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
namespace RexStudios.LanguageDependentNotification
{
using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using RexStudios.LanguageDependentNotification.Core;
using RexStudios.Extensions;
using System.Linq;
using System.Collections.Generic;
internal class NotificationDL: EntityRetrieverBase<Entity>, INotificationRepo
{
private ITracingService tracingService = null;
public NotificationDL(IOrganizationService service, ITracingService tracingService)
: base(service, tracingService, "rex_notification")
{
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override bool Exists(Guid id)
{
return this.Retrieve(id, new ColumnSet(false)) != null;
}
/// <summary>
///
/// </summary>
/// <param name="entityId"></param>
/// <param name="columnSet"></param>
/// <returns></returns>
public override Entity Retrieve(Guid entityId, ColumnSet columnSet)
{
return base.Retrieve(entityId, columnSet);
}
/// <summary>
///
/// </summary>
/// <param name="EntityLogicalName"></param>
/// <returns></returns>
public IEnumerable<Entity> GetNotificationTextByEntityName(string EntityLogicalName, int languagecode)
{
try
{
if (orgService == null)
throw new InvalidPluginExecutionException($"GetNotificationTextByEntityName: Organization service is null, can't process the request");
if (StringExtensions.IsNullOrEmpty(EntityLogicalName))
throw new InvalidPluginExecutionException($"GetNotificationTextByEntityName: NotificationType is null, can't process the request");
QueryExpression query = new QueryExpression(base.EntityLogicalName)
{
ColumnSet = new ColumnSet(true),
Criteria = new FilterExpression()
{
Conditions = {
new ConditionExpression()
{
AttributeName = "rex",
Operator = ConditionOperator.Equal,
Values = { EntityLogicalName }
}
}
}
};
LinkEntity languageCodeLink = new LinkEntity(base.EntityLogicalName, "rex_languagecode", "rex_lcid", "rex_languagecodeid", JoinOperator.Inner);
languageCodeLink.EntityAlias = "ad";
languageCodeLink.Columns = new ColumnSet(true);
languageCodeLink.LinkCriteria.AddCondition("rex_language", ConditionOperator.Equal, languagecode);
query.LinkEntities.Add(languageCodeLink);
tracingService?.Trace($"1--> GetNotificationTextByEntityName: Query expression is completed ");
return base.RetrieveMultipleEntities(query);
}
catch (InvalidPluginExecutionException ex)
{
tracingService?.Trace($"Invalid Exception GetNotificationTextByEntityName: {ex.Message}");
throw ex;
}
catch (Exception ex)
{
tracingService?.Trace($"Invalid Exception GetNotificationTextByEntityName: {ex.Message}");
throw ex;
}
}
/// <summary>
/// Get Notification Message Text by sending the GUId
/// </summary>
/// <param name="NotificationId"></param>
/// <returns></returns>
public Entity GetNotificationTextByID(Guid? NotificationId)
{
try
{
if (orgService == null)
throw new InvalidPluginExecutionException($"GetNotificationTextByID: Organization service is null, can't process the request");
if (GuidExtensions.IsNullOrEmpty(NotificationId))
throw new InvalidPluginExecutionException($"GetNotificationTextByID: NotificationTypeId is null or empty, can't process the request");
return this.Retrieve(NotificationId.Value, new ColumnSet(true));
}
catch (InvalidPluginExecutionException ex)
{
tracingService?.Trace($"Invalid Exception GetNotificationTextByID: {ex.Message}");
throw ex;
}
catch (Exception ex)
{
tracingService?.Trace($"Invalid Exception GetNotificationTextByID: {ex.Message}");
throw ex;
}
}
/// <summary>
/// Get NotificationText by Sending the
/// </summary>
/// <param name="CommandText"></param>
/// <returns></returns>
public Entity GetNotificationTextByName(string CommandText)
{
try
{
if (orgService == null)
throw new InvalidPluginExecutionException($"GetNotificationTextByName: Organization service is null, can't process the request");
if (StringExtensions.IsNullOrEmpty(CommandText))
throw new InvalidPluginExecutionException($"GetNotificationTextByName: NotificationType is null, can't process the request");
QueryExpression query = new QueryExpression(base.EntityLogicalName)
{
ColumnSet = new ColumnSet(true),
Criteria = new FilterExpression()
{
Conditions = {
new ConditionExpression()
{
AttributeName = "name",
Operator = ConditionOperator.Equal,
Values = { CommandText }
}
}
}
};
tracingService?.Trace($"1--> GetNotificationTextByName: Query expression is completed ");
return base.RetrieveMultipleEntities(query).FirstOrDefault();
}
catch (InvalidPluginExecutionException ex)
{
tracingService?.Trace($"Invalid Exception GetNotificationTextByName: {ex.Message}");
throw ex;
}
catch (Exception ex)
{
tracingService?.Trace($"Invalid Exception GetNotificationTextByName: {ex.Message}");
throw ex;
}
}
/// <summary>
/// Get Notification Text based on the logical name and notificationType
/// </summary>
/// <param name="CommandText"></param>
/// <param name="EntityLogicalName"></param>
/// <param name="NotificationType"></param>
/// <returns></returns>
public IEnumerable<Entity> GetNotificationTextByName(string CommandText, string EntityLogicalName, string NotificationType)
{
try
{
if (orgService == null)
throw new InvalidPluginExecutionException($"GetNotificationTextByEntityName: Organization service is null, can't process the request");
if (StringExtensions.IsNullOrEmpty(EntityLogicalName))
throw new InvalidPluginExecutionException($"GetNotificationTextByEntityName: NotificationType is null, can't process the request");
QueryExpression query = new QueryExpression(base.EntityLogicalName)
{
ColumnSet = new ColumnSet(true),
Criteria = new FilterExpression()
{
Conditions = {
new ConditionExpression()
{
AttributeName = "rex_entityname",
Operator = ConditionOperator.Equal,
Values = { EntityLogicalName }
},
new ConditionExpression()
{
AttributeName = "name",
Operator = ConditionOperator.Equal,
Values = { CommandText }
}
},
FilterOperator = LogicalOperator.And
}
};
// Adding Link Entity rex_notificationtype directly within the LinkEntities collection
query.LinkEntities.Add(new LinkEntity(base.EntityLogicalName, "rex_notificationtype", "rex_notificationtype", "rex_notificationtypeid", JoinOperator.Inner)
{
EntityAlias = "ab",
Columns = new ColumnSet(true),
LinkCriteria = new FilterExpression()
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("rex_name", ConditionOperator.Equal, NotificationType)
}
}
});
tracingService?.Trace($"1--> GetNotificationTextByEntityName: Query expression is completed ");
return base.RetrieveMultipleEntities(query).ToList();
}
catch (InvalidPluginExecutionException ex)
{
tracingService?.Trace($"Invalid Exception GetNotificationTextByEntityName: {ex.Message}");
throw ex;
}
catch (Exception ex)
{
tracingService?.Trace($"Invalid Exception GetNotificationTextByEntityName: {ex.Message}");
throw ex;
}
}
/// <summary>
/// Get notification text by lanaguagecode
/// </summary>
/// <param name="entityName"></param>
/// <param name="commandText"></param>
/// <param name="languageCode"></param>
/// <returns></returns>
public Entity GetNotificationTexts(string entityName, string commandText, int languageCode)
{
try
{
if (orgService == null)
throw new InvalidPluginExecutionException($"GetNotificationTexts: Organization service is null, can't process the request");
if (StringExtensions.IsNullOrEmpty(EntityLogicalName))
throw new InvalidPluginExecutionException($"GetNotificationTexts: NotificationType is null, can't process the request");
QueryExpression query = new QueryExpression(base.EntityLogicalName)
{
ColumnSet = new ColumnSet(true),
Criteria = new FilterExpression()
{
Conditions = {
new ConditionExpression()
{
AttributeName = "rex_entityname",
Operator = ConditionOperator.Equal,
Values = { EntityLogicalName }
},
new ConditionExpression()
{
AttributeName = "name",
Operator = ConditionOperator.Equal,
Values = { commandText }
}
},
FilterOperator = LogicalOperator.And
}
};
query.LinkEntities.Add(new LinkEntity(base.EntityLogicalName, "rex_languagecode", "rex_language", "rex_languagecodeid", JoinOperator.Inner)
{
EntityAlias = "ad",
Columns = new ColumnSet(true),
LinkCriteria = new FilterExpression()
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("rex_language", ConditionOperator.Equal, languageCode)
}
}
});
tracingService?.Trace($"1--> GetNotificationTexts: Query expression is completed ");
return base.RetrieveMultipleEntities(query).FirstOrDefault();
}
catch (InvalidPluginExecutionException ex)
{
tracingService?.Trace($"Invalid Exception GetNotificationTexts: {ex.Message}");
throw ex;
}
catch (Exception ex)
{
tracingService?.Trace($"Invalid Exception GetNotificationTexts: {ex.Message}");
throw ex;
}
}
}
}