This commit is contained in:
@@ -4345,28 +4345,31 @@ namespace AyaNova.Biz
|
||||
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
|
||||
|
||||
//SPECIFIC EVENTS FOR THIS OBJECT
|
||||
WorkOrderItemScheduledUser o = (WorkOrderItemScheduledUser)proposedObj;
|
||||
WorkOrderItemScheduledUser oProposed = (WorkOrderItemScheduledUser)proposedObj;
|
||||
// WorkOrderItemScheduledUser oCurrent=null;
|
||||
// if(currentObj!=null)
|
||||
// oCurrent = (WorkOrderItemScheduledUser)currentObj;
|
||||
|
||||
//## 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, proposedObj.AyaType, o.Id, NotifyEventType.ContractExpiring);
|
||||
var woId = await GetWorkOrderIdFromRelativeAsync(AyaType.WorkOrderItem, o.WorkOrderItemId, ct);
|
||||
//standard process will remove any hanging around when deleted, nothing else specific here to deal with
|
||||
|
||||
|
||||
var woId = await GetWorkOrderIdFromRelativeAsync(AyaType.WorkOrderItem, oProposed.WorkOrderItemId, ct);
|
||||
var WorkorderInfo = await ct.WorkOrder.AsNoTracking().Where(x => x.Id == woId).Select(x => new { Serial = x.Serial, Tags = x.Tags }).FirstOrDefaultAsync();
|
||||
|
||||
|
||||
//## CREATED
|
||||
if (ayaEvent == AyaEvent.Created)
|
||||
//## CREATED / UPDATED - ScheduledOnWorkorder event
|
||||
//Note: scheduled on workorder is immediate so same process regardless if modified or updated
|
||||
//because modified changes nearly all affect user so decision is just send it no matter what as any difference is enough to send
|
||||
if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified)
|
||||
{
|
||||
//this block is entirely about //ScheduledOnWorkorder event
|
||||
|
||||
//# ScheduledOnWorkorder event
|
||||
if (o.UserId != null)
|
||||
if (oProposed.UserId != null)
|
||||
{
|
||||
//Conditions: userid match and tags
|
||||
//delivery is immediate so no need to remove old ones of this kind
|
||||
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorder && z.UserId == o.UserId).ToListAsync();
|
||||
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorder && z.UserId == oProposed.UserId).ToListAsync();
|
||||
foreach (var sub in subs)
|
||||
{
|
||||
//not for inactive users
|
||||
@@ -4377,26 +4380,97 @@ namespace AyaNova.Biz
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.WorkorderStatusChange,
|
||||
EventType = NotifyEventType.ScheduledOnWorkorder,
|
||||
UserId = sub.UserId,
|
||||
AyaType = AyaType.WorkOrder,
|
||||
ObjectId = o.WorkOrderId,
|
||||
AyaType = AyaType.WorkOrderItemScheduledUser,
|
||||
ObjectId = oProposed.Id,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
Name = $"{WorkorderInfo.Serial.ToString()} - {wos.Name}"
|
||||
Name = $"{WorkorderInfo.Serial.ToString()}"
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}//workorder status change event
|
||||
|
||||
}//ScheduledOnWorkorder
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//## CREATED
|
||||
if (ayaEvent == AyaEvent.Created)
|
||||
{
|
||||
//ScheduledOnWorkorderImminent
|
||||
if (oProposed.UserId != null && oProposed.StartDate != null)
|
||||
{
|
||||
//Conditions: userid match and tags + time delayed age value
|
||||
//delivery is delayed so need to remove old ones of this kind on update
|
||||
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorderImminent && z.UserId == oProposed.UserId).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(WorkorderInfo.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.ScheduledOnWorkorderImminent,
|
||||
UserId = sub.UserId,
|
||||
AyaType = AyaType.WorkOrderItemScheduledUser,
|
||||
ObjectId = oProposed.Id,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
EventDate = (DateTime)oProposed.StartDate,
|
||||
Name = $"{WorkorderInfo.Serial.ToString()}"
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}//ScheduledOnWorkorderImminent
|
||||
}
|
||||
|
||||
|
||||
|
||||
//## MODIFIED
|
||||
if (ayaEvent == AyaEvent.Modified)
|
||||
{
|
||||
|
||||
//ScheduledOnWorkorderImminent
|
||||
//Always clear any old ones for this object as they are all irrelevant the moment changed:
|
||||
await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.ScheduledOnWorkorderImminent);
|
||||
|
||||
if (oProposed.UserId != null && oProposed.StartDate != null)
|
||||
{
|
||||
//Conditions: userid match and tags + time delayed age value
|
||||
//delivery is delayed so need to remove old ones of this kind on update
|
||||
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ScheduledOnWorkorderImminent && z.UserId == oProposed.UserId).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(WorkorderInfo.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.ScheduledOnWorkorderImminent,
|
||||
UserId = sub.UserId,
|
||||
AyaType = AyaType.WorkOrderItemScheduledUser,
|
||||
ObjectId = oProposed.Id,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
EventDate = (DateTime)oProposed.StartDate,
|
||||
Name = $"{WorkorderInfo.Serial.ToString()}"
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}//ScheduledOnWorkorderImminent
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user