Added ReviewImminent notification event type and backing and fronting code

This commit is contained in:
2022-01-28 20:14:49 +00:00
parent 869a7db01a
commit e06cebcd13
8 changed files with 118 additions and 61 deletions

View File

@@ -43,7 +43,8 @@ namespace AyaNova.Biz
WorkorderCompleted = 30, //*Service work order is set to any status that is flagged as a "Completed" type of status. Customer & User (Note this is for users that don't want or can't pick status change to completed type)
WorkorderCreatedForCustomer = 31, //*Service work order is created for Customer, only applies to that customer user notify sub for that customer, customer id is in conditional ID value for subscription
PMGenerationFailed = 32, //indicates there was a failure during PM generation with error
SendUserCredentials = 33 // Internal System use only: When user generates new credentials and sends them this is the notification type for that see UserBiz GenerateCredsAndEmailUser
SendUserCredentials = 33, // Internal System use only: When user generates new credentials and sends them this is the notification type for that see UserBiz GenerateCredsAndEmailUser
ReviewImminent = 34,//*Review object, Advance notice setting tag conditional
//POTENTIAL OTHER NOTIFICATIONS:
//WorkOrderItemLoan unit is overdue from estimate

View File

@@ -501,7 +501,7 @@ namespace AyaNova.Biz
}
}
}//warranty expiry event
}//Reminder imminent event
}//end of process notifications
}

View File

@@ -527,76 +527,126 @@ namespace AyaNova.Biz
bool isNew = currentObj == null;
Review o = (Review)proposedObj;
//STANDARD EVENTS FOR ALL OBJECTS
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
//SPECIFIC EVENTS FOR THIS OBJECT
#region OLD
//CREATED / MODIFIED
//OLD general notification code removed in favor of specific event for review imminent
// //CREATED / MODIFIED
// if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified)
// {
// //OVERDUE pseudo event
// {
// //Remove prior
// await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.GeneralNotification);//assumes only general event for this object type is overdue here
// //set a deadman automatic internal notification if goes past due
// var r = (Review)proposedObj;
// //it not completed yet and not overdue already (which could indicate an import or something)
// if (r.CompletedDate == null && r.ReviewDate > DateTime.UtcNow)
// {
// //Notify user
// await NotifyEventHelper.EnsureDefaultInAppUserNotificationSubscriptionExists(r.UserId, ct);
// {
// var gensubs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == r.UserId).ToListAsync();
// foreach (var sub in gensubs)
// {
// var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.UserId);
// NotifyEvent n = new NotifyEvent()
// {
// EventType = NotifyEventType.GeneralNotification,
// UserId = r.UserId,
// ObjectId = proposedObj.Id,
// AyaType = AyaType.Review,
// NotifySubscriptionId = sub.Id,
// Name = $"{eventNameTranslated} - {proposedObj.Name}",
// EventDate = r.ReviewDate
// };
// await ct.NotifyEvent.AddAsync(n);
// log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
// }
// if (gensubs.Count > 0)
// await ct.SaveChangesAsync();
// }
// //Notify supervisor
// if (r.UserId != r.AssignedByUserId)
// {
// await NotifyEventHelper.EnsureDefaultInAppUserNotificationSubscriptionExists(r.AssignedByUserId, ct);
// var gensubs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == r.AssignedByUserId).ToListAsync();
// foreach (var sub in gensubs)
// {
// var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.AssignedByUserId);
// NotifyEvent n = new NotifyEvent()
// {
// EventType = NotifyEventType.GeneralNotification,
// UserId = r.AssignedByUserId,
// ObjectId = proposedObj.Id,
// AyaType = AyaType.Review,
// NotifySubscriptionId = sub.Id,
// Name = $"{eventNameTranslated} - {proposedObj.Name}",
// EventDate = r.ReviewDate
// };
// await ct.NotifyEvent.AddAsync(n);
// log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
// }
// if (gensubs.Count > 0)
// await ct.SaveChangesAsync();
// }
// }
// }//overdue event
// }//custom events for created / modified
#endregion old
//## DELETED EVENTS
//any event added below needs to be removed, so
//just blanket remove any event for this object of eventtype that would be added below here
//do it regardless any time there's an update and then
//let this code below handle the refreshing addition that could have changes
await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.Review, o.Id, NotifyEventType.ReviewImminent);
//## CREATED / MODIFIED EVENTS
if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified)
{
//OVERDUE pseudo event
//# REVIEW IMMINENT
{
//Remove prior
await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.GeneralNotification);//assumes only general event for this object type is overdue here
//set a deadman automatic internal notification if goes past due
var r = (Review)proposedObj;
//it not completed yet and not overdue already (which could indicate an import or something)
if (r.CompletedDate == null && r.ReviewDate > DateTime.UtcNow)
//notify users (time delayed)
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ReviewImminent).ToListAsync();
foreach (var sub in subs)
{
//Notify user
await NotifyEventHelper.EnsureDefaultInAppUserNotificationSubscriptionExists(r.UserId, ct);
{
var gensubs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == r.UserId).ToListAsync();
foreach (var sub in gensubs)
{
var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.UserId);
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.GeneralNotification,
UserId = r.UserId,
ObjectId = proposedObj.Id,
AyaType = AyaType.Review,
NotifySubscriptionId = sub.Id,
Name = $"{eventNameTranslated} - {proposedObj.Name}",
EventDate = r.ReviewDate
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
}
if (gensubs.Count > 0)
await ct.SaveChangesAsync();
}
//not for inactive users
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
//Notify supervisor
if (r.UserId != r.AssignedByUserId)
//Tag match? (will be true if no sub tags so always safe to call this)
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags))
{
await NotifyEventHelper.EnsureDefaultInAppUserNotificationSubscriptionExists(r.AssignedByUserId, ct);
var gensubs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.GeneralNotification && z.UserId == r.AssignedByUserId).ToListAsync();
foreach (var sub in gensubs)
NotifyEvent n = new NotifyEvent()
{
var eventNameTranslated = await TranslationBiz.GetTranslationForUserStaticAsync("ReviewOverDue", r.AssignedByUserId);
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.GeneralNotification,
UserId = r.AssignedByUserId,
ObjectId = proposedObj.Id,
AyaType = AyaType.Review,
NotifySubscriptionId = sub.Id,
Name = $"{eventNameTranslated} - {proposedObj.Name}",
EventDate = r.ReviewDate
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
}
if (gensubs.Count > 0)
await ct.SaveChangesAsync();
EventType = NotifyEventType.ReviewImminent,
UserId = sub.UserId,
AyaType = o.AyaType,
ObjectId = o.Id,
NotifySubscriptionId = sub.Id,
Name = o.Name,
EventDate = o.ReviewDate
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}//overdue event
}//custom events for created / modified
}//review imminent
}//end of process notifications
}//end of process notifications