This commit is contained in:
2021-03-09 00:01:09 +00:00
parent ea9f7bbf7c
commit 9a11e4bfb4
4 changed files with 137 additions and 18 deletions

View File

@@ -531,6 +531,54 @@ namespace AyaNova.Biz
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
//SPECIFIC EVENTS FOR THIS OBJECT
Customer o = (Customer)proposedObj;
//## 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.Customer, o.Id, NotifyEventType.ContractExpiring);
//## CREATED / MODIFIED EVENTS
if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified)
{
//# CONTRACT EXPIRY
{
if (o.ContractId != null && o.ContractExpires != null)
{
var ContractExpirydate = (DateTime)o.ContractExpires;
//notify users about contract expiry (time delayed)
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ContractExpiring).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.TagsMatch(o.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.ContractExpiring,
UserId = sub.UserId,
AyaType = o.AyaType,
ObjectId = o.Id,
NotifySubscriptionId = sub.Id,
Name = o.Name,
EventDate = ContractExpirydate
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}
}//Contract expiry event
}
}//end of process notifications

View File

@@ -489,7 +489,55 @@ namespace AyaNova.Biz
//STANDARD EVENTS FOR ALL OBJECTS
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
//SPECIFIC EVENTS FOR THIS OBJECT
//SPECIFIC EVENTS FOR THIS OBJECT
HeadOffice o = (HeadOffice)proposedObj;
//## 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.HeadOffice, o.Id, NotifyEventType.ContractExpiring);
//## CREATED / MODIFIED EVENTS
if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified)
{
//# CONTRACT EXPIRY
{
if (o.ContractId != null && o.ContractExpires != null)
{
var ContractExpirydate = (DateTime)o.ContractExpires;
//notify users about contract expiry (time delayed)
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ContractExpiring).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.TagsMatch(o.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.ContractExpiring,
UserId = sub.UserId,
AyaType = o.AyaType,
ObjectId = o.Id,
NotifySubscriptionId = sub.Id,
Name = o.Name,
EventDate = ContractExpirydate
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}
}//Contract expiry event
}
}//end of process notifications

View File

@@ -256,7 +256,7 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Serial", "no two units can have the same serial and same unitmodel");
}
}
if (proposedObj.ContractId != null)
if (proposedObj.ContractExpires == null)
AddError(ApiErrorCode.VALIDATION_REQUIRED, "ContractExpires");
@@ -484,30 +484,22 @@ namespace AyaNova.Biz
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
//SPECIFIC EVENTS FOR THIS OBJECT
/*
UnitWarrantyExpiry = 25,//* Unit object created, advance notice can be used, tag conditional
Unit o = (Unit)proposedObj;
*/
//## DELETED EVENTS
//TODO: there are no specific deleted events
//but any event added below needs to be removed, so
//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.Unit, o.Id, NotifyEventType.UnitWarrantyExpiry);
await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.Unit, o.Id, NotifyEventType.ContractExpiring);
//## CREATED / MODIFIED EVENTS
if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified)
{
Unit o = (Unit)proposedObj;
//# UNIT WARRANTY EXPIRY
{
//first remove any existing, potentially stale notifyevents for this exact object and notifyeventtype
//NOTE: this is only required for notify events that have an AgeValue where the eventdate is relevant
await NotifyEventHelper.ClearPriorEventsForObject(ct, AyaType.Unit, o.Id, NotifyEventType.UnitWarrantyExpiry);
//does the unit even have a model or warranty?
int effectiveWarrantyMonths = 0;
//unit has own warranty terms
@@ -560,6 +552,39 @@ namespace AyaNova.Biz
}
}//warranty expiry event
//# CONTRACT EXPIRY
{
if (o.ContractId != null && o.ContractExpires != null)
{
var ContractExpirydate = (DateTime)o.ContractExpires;
//notify users about contract expiry (time delayed)
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ContractExpiring).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.TagsMatch(o.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.ContractExpiring,
UserId = sub.UserId,
AyaType = o.AyaType,
ObjectId = o.Id,
NotifySubscriptionId = sub.Id,
Name = o.Serial,
EventDate = ContractExpirydate
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}
}//Contract expiry event
//#todo: METER READING EVENT
//MIGRATE_OUTSTANDING need meter reading object to complete unit notification for UnitMeterReadingMultipleExceeded
@@ -570,11 +595,7 @@ namespace AyaNova.Biz
//then check if unit is still metered etc etc and do the rest once the unit meter reading is coded
//}
}

View File

@@ -2638,6 +2638,8 @@ namespace AyaNova.Biz
//SPECIFIC EVENTS FOR THIS OBJECT
//todo: contract response time notification
}//end of process notifications