This commit is contained in:
2021-06-10 14:01:32 +00:00
parent cd4da53210
commit fe4ce3f4ed

View File

@@ -1074,6 +1074,83 @@ namespace AyaNova.Biz
#endregion
#region CustomerServiceImminent
if (ayaEvent == AyaEvent.Created && oProposed.CompleteByDate != null)
{
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.CustomerServiceImminent).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
//Tag match? (will be true if no sub tags so always safe to call this)
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(proposedObj.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.CustomerServiceImminent,
UserId = sub.UserId,
AyaType = proposedObj.AyaType,
ObjectId = proposedObj.Id,
NotifySubscriptionId = sub.Id,
Name = oProposed.Serial.ToString(),
EventDate = (DateTime)oProposed.CompleteByDate
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}//CustomerServiceImminent
if (ayaEvent == AyaEvent.Modified)
{// CustomerServiceImminent modified in some way, could be tags, could be date either of which is relevant to this notification block
//differences requiring re-processing of notification??
if (oProposed.CompleteByDate != oCurrent.CompleteByDate || !SameTags)
{
await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.CustomerServiceImminent);
//new has date?
if (oProposed.CompleteByDate != null)
{
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.CustomerServiceImminent).ToListAsync();
foreach (var sub in subs)
{
//not for inactive users
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
//Tag match? (will be true if no sub tags so always safe to call this)
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(proposedObj.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.CustomerServiceImminent,
UserId = sub.UserId,
AyaType = proposedObj.AyaType,
ObjectId = proposedObj.Id,
NotifySubscriptionId = sub.Id,
Name = oProposed.Serial.ToString(),
EventDate = (DateTime)oProposed.CompleteByDate
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}
}
}//CustomerServiceImminent
#endregion
}//end of process notifications