This commit is contained in:
@@ -1315,7 +1315,7 @@ namespace AyaNova.Biz
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region CustomerServiceImminent "Service Reminder"
|
#region Customer centric notifications
|
||||||
if (ayaEvent == AyaEvent.Created && oProposed.ServiceDate != null && oProposed.ServiceDate > DateTime.UtcNow)
|
if (ayaEvent == AyaEvent.Created && oProposed.ServiceDate != null && oProposed.ServiceDate > DateTime.UtcNow)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -1499,17 +1499,111 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
}//WorkorderCreatedForCustomer
|
}//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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}//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
|
#endregion workorder level
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
███████╗████████╗ █████╗ ████████╗███████╗███████╗
|
███████╗████████╗ █████╗ ████████╗███████╗███████╗
|
||||||
|
|||||||
Reference in New Issue
Block a user