diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index bef27e20..5181a6e7 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -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