This commit is contained in:
@@ -4345,28 +4345,31 @@ namespace AyaNova.Biz
|
|||||||
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
|
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
|
||||||
|
|
||||||
//SPECIFIC EVENTS FOR THIS OBJECT
|
//SPECIFIC EVENTS FOR THIS OBJECT
|
||||||
WorkOrderItemScheduledUser o = (WorkOrderItemScheduledUser)proposedObj;
|
WorkOrderItemScheduledUser oProposed = (WorkOrderItemScheduledUser)proposedObj;
|
||||||
|
// WorkOrderItemScheduledUser oCurrent=null;
|
||||||
|
// if(currentObj!=null)
|
||||||
|
// oCurrent = (WorkOrderItemScheduledUser)currentObj;
|
||||||
|
|
||||||
//## DELETED EVENTS
|
//## DELETED EVENTS
|
||||||
//any event added below needs to be removed, so
|
//standard process will remove any hanging around when deleted, nothing else specific here to deal with
|
||||||
//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
|
var woId = await GetWorkOrderIdFromRelativeAsync(AyaType.WorkOrderItem, oProposed.WorkOrderItemId, ct);
|
||||||
// await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, o.Id, NotifyEventType.ContractExpiring);
|
|
||||||
var woId = await GetWorkOrderIdFromRelativeAsync(AyaType.WorkOrderItem, o.WorkOrderItemId, ct);
|
|
||||||
var WorkorderInfo = await ct.WorkOrder.AsNoTracking().Where(x => x.Id == woId).Select(x => new { Serial = x.Serial, Tags = x.Tags }).FirstOrDefaultAsync();
|
var WorkorderInfo = await ct.WorkOrder.AsNoTracking().Where(x => x.Id == woId).Select(x => new { Serial = x.Serial, Tags = x.Tags }).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
|
||||||
//## CREATED
|
//## CREATED / UPDATED - ScheduledOnWorkorder event
|
||||||
if (ayaEvent == AyaEvent.Created)
|
//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 (oProposed.UserId != null)
|
||||||
if (o.UserId != null)
|
|
||||||
{
|
{
|
||||||
//Conditions: userid match and tags
|
//Conditions: userid match and tags
|
||||||
//delivery is immediate so no need to remove old ones of this kind
|
//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)
|
foreach (var sub in subs)
|
||||||
{
|
{
|
||||||
//not for inactive users
|
//not for inactive users
|
||||||
@@ -4377,26 +4380,97 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
NotifyEvent n = new NotifyEvent()
|
NotifyEvent n = new NotifyEvent()
|
||||||
{
|
{
|
||||||
EventType = NotifyEventType.WorkorderStatusChange,
|
EventType = NotifyEventType.ScheduledOnWorkorder,
|
||||||
UserId = sub.UserId,
|
UserId = sub.UserId,
|
||||||
AyaType = AyaType.WorkOrder,
|
AyaType = AyaType.WorkOrderItemScheduledUser,
|
||||||
ObjectId = o.WorkOrderId,
|
ObjectId = oProposed.Id,
|
||||||
NotifySubscriptionId = sub.Id,
|
NotifySubscriptionId = sub.Id,
|
||||||
Name = $"{WorkorderInfo.Serial.ToString()} - {wos.Name}"
|
Name = $"{WorkorderInfo.Serial.ToString()}"
|
||||||
};
|
};
|
||||||
await ct.NotifyEvent.AddAsync(n);
|
await ct.NotifyEvent.AddAsync(n);
|
||||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||||
await ct.SaveChangesAsync();
|
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
|
//## MODIFIED
|
||||||
if (ayaEvent == AyaEvent.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