From 082484c7a2b550aa4ea8187fc1376a713f0978f8 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 8 Mar 2022 20:33:40 +0000 Subject: [PATCH] --- server/AyaNova/biz/WorkOrderBiz.cs | 104 +++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 5 deletions(-) diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index 70d4825e..2a1a88ca 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -1315,7 +1315,7 @@ namespace AyaNova.Biz #endregion - #region CustomerServiceImminent "Service Reminder" + #region Customer centric notifications if (ayaEvent == AyaEvent.Created && oProposed.ServiceDate != null && oProposed.ServiceDate > DateTime.UtcNow) { @@ -1499,15 +1499,109 @@ namespace AyaNova.Biz } }//WorkorderCreatedForCustomer - #endregion + #endregion regular user notifications - }//end of process notifications + #region CUSTOMER "PROXY" NOTIFICATIONS + var custInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == oProposed.CustomerId).Select(x => new { x.Active, x.Tags, x.EmailAddress }).FirstOrDefaultAsync(); + if (custInfo != null && custInfo.Active && !string.IsNullOrWhiteSpace(custInfo.EmailAddress))//can this customer receive *any* customer notifications? + { + //-------- Customer is notifiable ------ + if (ayaEvent == AyaEvent.Created && oProposed.ServiceDate != null && oProposed.ServiceDate > DateTime.UtcNow) + { + var subs = await ct.CustomerNotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.CustomerServiceImminent).OrderBy(z => z.Id).ToListAsync(); + foreach (var sub in subs) + { + //Object tags must match and Customer tags must match + if (NotifyEventHelper.ObjectHasAllSubscriptionTags(oProposed.Tags, sub.Tags) && NotifyEventHelper.ObjectHasAllSubscriptionTags(custInfo.Tags, sub.CustomerTags)) + { + CustomerNotifyEvent n = new CustomerNotifyEvent() + { + EventType = NotifyEventType.CustomerServiceImminent, + CustomerId = oProposed.CustomerId, + AyaType = proposedObj.AyaType, + ObjectId = oProposed.Id, + CustomerNotifySubscriptionId = sub.Id, + Name = oProposed.Serial.ToString(), + EventDate = (DateTime)oProposed.ServiceDate + }; + await ct.CustomerNotifyEvent.AddAsync(n); + log.LogDebug($"Adding CustomerNotifyEvent: [{n.ToString()}]"); + await ct.SaveChangesAsync(); + break;//we have a match no need to process any further subs for this event + } + } - #endregion workorder level + }//CustomerServiceImminent "Service Reminder" + if (ayaEvent == AyaEvent.Modified && oProposed.ServiceDate != oCurrent.ServiceDate) + {// CustomerServiceImminent "Service Reminder" + //differences requiring re-processing of notification + await NotifyEventHelper.ClearPriorCustomerNotifyEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.CustomerServiceImminent); + //new has date? + if (oProposed.ServiceDate != null && oProposed.ServiceDate > DateTime.UtcNow) + { + var subs = await ct.CustomerNotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.CustomerServiceImminent).OrderBy(z => z.Id).ToListAsync(); + foreach (var sub in subs) + { + //Object tags must match and Customer tags must match + if (NotifyEventHelper.ObjectHasAllSubscriptionTags(oProposed.Tags, sub.Tags) && NotifyEventHelper.ObjectHasAllSubscriptionTags(custInfo.Tags, sub.CustomerTags)) + { + CustomerNotifyEvent n = new CustomerNotifyEvent() + { + EventType = NotifyEventType.CustomerServiceImminent, + CustomerId = oProposed.CustomerId, + AyaType = proposedObj.AyaType, + ObjectId = oProposed.Id, + CustomerNotifySubscriptionId = sub.Id, + Name = oProposed.Serial.ToString(), + EventDate = (DateTime)oProposed.ServiceDate + }; + await ct.CustomerNotifyEvent.AddAsync(n); + log.LogDebug($"Adding CustomerNotifyEvent: [{n.ToString()}]"); + await ct.SaveChangesAsync(); + break;//we have a match no need to process any further subs for this event + } + } + } + + }//CustomerServiceImminent "Service Reminder" + + //# WorkorderCreatedForCustomer + if (oProposed.CustomerId != 0 && (ayaEvent == AyaEvent.Created || (ayaEvent == AyaEvent.Modified && oCurrent.CustomerId != oProposed.CustomerId))) + { + //look for potential subscribers + var subs = await ct.CustomerNotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.WorkorderCreatedForCustomer).OrderBy(z => z.Id).ToListAsync(); + foreach (var sub in subs) + { + //Object tags must match and Customer tags must match + if (NotifyEventHelper.ObjectHasAllSubscriptionTags(oProposed.Tags, sub.Tags) && NotifyEventHelper.ObjectHasAllSubscriptionTags(custInfo.Tags, sub.CustomerTags)) + { + CustomerNotifyEvent n = new CustomerNotifyEvent() + { + EventType = NotifyEventType.WorkorderCreatedForCustomer, + CustomerId = oProposed.CustomerId, + AyaType = proposedObj.AyaType, + ObjectId = oProposed.Id, + CustomerNotifySubscriptionId = sub.Id, + Name = oProposed.Serial.ToString() + }; + await ct.CustomerNotifyEvent.AddAsync(n); + log.LogDebug($"Adding CustomerNotifyEvent: [{n.ToString()}]"); + await ct.SaveChangesAsync(); + break;//we have a match no need to process any further subs for this event + } + } + }//WorkorderCreatedForCustomer + //----------------------- + }//all customer proxy if notifiable + #endregion customer proxy notifications + + }//end of process WORKORDER HEADER notifications + + #endregion workorder level /* @@ -1891,7 +1985,7 @@ namespace AyaNova.Biz if (custInfo != null && custInfo.Active && !string.IsNullOrWhiteSpace(custInfo.EmailAddress))//can this customer receive *any* customer notifications? { //-------- Customer is notifiable ------ - + //# STATUS CHANGE (create new status) { //Conditions: must match specific status id value and also tags below