This commit is contained in:
2020-07-17 19:16:06 +00:00
parent c0839f9d08
commit 9782a2086e
3 changed files with 65 additions and 10 deletions

View File

@@ -128,13 +128,45 @@ namespace AyaNova.Biz
{
case AyaEvent.Created:
//------------------------------
//Specific created related subscriptions for AyaType
// AyaType Specific created related subscriptions
//
switch (newObject.AyaType)
{
//AyaTypes with their own special notification related events
case AyaType.WorkOrder:
{
//WorkorderStatusChange
{
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.WorkorderStatusChange).ToListAsync();
foreach (var sub in subs)
{
if (TagsMatch(newObject.Tags, sub.Tags))
{
//Note: this is a "deadman switch" event
//it will deliver if it's not removed before the age selected
// age is set by advance notice which is consulted by CoreJobNotify in it's run so the deliver date is not required here only the reference EventDate to check for deliver
throw new System.NotImplementedException("Awaiting workorder object completion");
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.ObjectAge,
UserId = sub.UserId,
ObjectId = newObject.Id,
SubscriptionId = sub.Id,
//TODO: IdValue=((WorkOrder)newObject).WorkorderStatusId
EventDate = DateTime.UtcNow
};
await ct.NotifyEvent.AddAsync(n);
log.LogTrace($"Adding NotifyEvent: [{n.ToString()}]");
//Note: in same event but for MODIFY below if need to delete old notifyevent here
// var deleteEventList = await ct.NotifyEvent.Where(z => z.ObjectId == ev.ObjectId && z.AyaType == ev.AyaType).ToListAsync();
// ct.NotifyEvent.RemoveRange(deleteEventList);
SaveContext = true;
}
}
}
//ScheduledOnWorkorder
//ScheduledOnWorkorderImminent
//tentative WorkorderCloseByPassed
@@ -151,21 +183,41 @@ namespace AyaNova.Biz
//QuoteStatusChange
//QuoteStatusAge
break;
case AyaType.Contract:
//ContractExpiring
break;
case AyaType.Reminder:
//ReminderImminent
break;
case AyaType.Unit:
//UnitWarrantyExpiry
break;
case AyaType.UnitMeterReading:
//UnitMeterReadingMultipleExceeded
break;
}
//-----------------------------------------------
//ObjectAge
//
{
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ObjectAge && z.AyaType == newObject.AyaType).ToListAsync();
foreach (var sub in subs)
{
if (TagsMatch(newObject.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent() {
EventType = NotifyEventType.ObjectAge, UserId = sub.UserId, AyaType = newObject.AyaType, ObjectId = newObject.Id,
SubscriptionId = sub.Id, EventDate=DateTime.UtcNow
};
//Note: age is set by advance notice which is consulted by CoreJobNotify in it's run so the deliver date is not required here only the reference EventDate to check for deliver
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.ObjectAge,
UserId = sub.UserId,
AyaType = newObject.AyaType,
ObjectId = newObject.Id,
SubscriptionId = sub.Id,
EventDate = DateTime.UtcNow
};
await ct.NotifyEvent.AddAsync(n);
log.LogTrace($"Adding NotifyEvent: [{n.ToString()}]");
SaveContext = true;
@@ -173,7 +225,8 @@ namespace AyaNova.Biz
}
}
//------------------------------------------
//General ObjectCreated subscriptions
//ObjectCreated
//
{
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ObjectCreated && z.AyaType == newObject.AyaType).ToListAsync();
foreach (var sub in subs)