This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -300,7 +301,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
//## CREATED EVENTS
|
//## CREATED EVENTS
|
||||||
if (ayaEvent == AyaEvent.Created || ayaEvent==AyaEvent.Modified)
|
if (ayaEvent == AyaEvent.Created || ayaEvent == AyaEvent.Modified)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@@ -309,38 +310,53 @@ namespace AyaNova.Biz
|
|||||||
//UNIT WARRANTY EXPIRY
|
//UNIT WARRANTY EXPIRY
|
||||||
{
|
{
|
||||||
//does the unit even have a model or warranty?
|
//does the unit even have a model or warranty?
|
||||||
int effectiveWarrantyMonths=0;
|
int effectiveWarrantyMonths = 0;
|
||||||
//unit has own warranty terms
|
//unit has own warranty terms
|
||||||
if(o.OverrideModelWarranty && !o.LifeTimeWarranty && o.WarrantyLength!=null && o.WarrantyLength>0){
|
if (o.OverrideModelWarranty && !o.LifeTimeWarranty && o.WarrantyLength != null && o.WarrantyLength > 0)
|
||||||
effectiveWarrantyMonths=(int)o.WarrantyLength;
|
|
||||||
}else{
|
|
||||||
if(o.UnitModelId!=null){
|
|
||||||
/todo: here is where I left off and some stuff above to delete once this below stuff is done.
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.UnitWarrantyExpiry).ToListAsync();
|
|
||||||
foreach (var sub in subs)
|
|
||||||
{
|
{
|
||||||
//not for inactive users
|
effectiveWarrantyMonths = (int)o.WarrantyLength;
|
||||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
}
|
||||||
|
else
|
||||||
//Tag match? (will be true if no sub tags so always safe to call this)
|
{
|
||||||
if (NotifyEventHelper.TagsMatch(o.Tags,sub.Tags))
|
//unit has model based warranty terms
|
||||||
|
if (o.UnitModelId != null)
|
||||||
{
|
{
|
||||||
|
UnitModel um = await ct.UnitModel.AsNoTracking().FirstOrDefaultAsync(z => z.Id == o.UnitModelId);
|
||||||
NotifyEvent n = new NotifyEvent()
|
if (!um.LifeTimeWarranty && um.WarrantyLength != null && um.WarrantyLength > 0)
|
||||||
{
|
{
|
||||||
EventType = NotifyEventType.UnitWarrantyExpiry,
|
effectiveWarrantyMonths = (int)um.WarrantyLength;
|
||||||
UserId = sub.UserId,
|
}
|
||||||
AyaType = o.AyaType,
|
}
|
||||||
ObjectId = o.Id,
|
}
|
||||||
NotifySubscriptionId = sub.Id,
|
if (effectiveWarrantyMonths > 0)
|
||||||
Name = o.Serial,
|
{
|
||||||
};
|
var WarrantyExpirydate = DateTime.UtcNow.AddMonths(effectiveWarrantyMonths);
|
||||||
await ct.NotifyEvent.AddAsync(n);
|
|
||||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
//notify users about warranty expiry (time delayed)
|
||||||
await ct.SaveChangesAsync();
|
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.UnitWarrantyExpiry).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.UnitWarrantyExpiry,
|
||||||
|
UserId = sub.UserId,
|
||||||
|
AyaType = o.AyaType,
|
||||||
|
ObjectId = o.Id,
|
||||||
|
NotifySubscriptionId = sub.Id,
|
||||||
|
Name = o.Serial,
|
||||||
|
EventDate = WarrantyExpirydate
|
||||||
|
};
|
||||||
|
await ct.NotifyEvent.AddAsync(n);
|
||||||
|
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ namespace AyaNova.Models
|
|||||||
//NOTE: Any non required field (nullable in DB) sb nullable here, i.e. decimal? not decimal,
|
//NOTE: Any non required field (nullable in DB) sb nullable here, i.e. decimal? not decimal,
|
||||||
//otherwise the server will call it an invalid record if the field isn't sent from client
|
//otherwise the server will call it an invalid record if the field isn't sent from client
|
||||||
|
|
||||||
|
|
||||||
|
//This class holds events that occur in the database for delivery to users
|
||||||
|
//it's the result of an event happening, not the subscription which is seperate and decides who gets what
|
||||||
|
//when an object is modified it may create a NotifyEvent record if anyone subscribes to that event
|
||||||
|
//it will create one of these for every user with that subscription
|
||||||
public class NotifyEvent
|
public class NotifyEvent
|
||||||
{
|
{
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
@@ -26,17 +31,19 @@ namespace AyaNova.Models
|
|||||||
public long UserId { get; set; }
|
public long UserId { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public long NotifySubscriptionId { get; set; }//source subscription that triggered this event to be created
|
public long NotifySubscriptionId { get; set; }//source subscription that triggered this event to be created
|
||||||
[Required]
|
|
||||||
public long IdValue { get; set; }
|
|
||||||
[Required]
|
|
||||||
public decimal DecValue { get; set; }
|
|
||||||
|
|
||||||
// [Required]// public TimeSpan AgeValue { get; set; }
|
//Not sure why these were put here, I'm commenting them out for now
|
||||||
|
//they seem to just be an artifact possibly of making this model from the subscription model? (copy paste)
|
||||||
|
//read the specs again and they aren't mentioned and I don't see any reference anywhere in actual delivery notification nor front end etc
|
||||||
|
//only for the subscription itself
|
||||||
|
//KEEP THIS UNTIL DONE THEN REMOVE IN FUTURE IF IT WASN"T NEEDED
|
||||||
|
// [Required]
|
||||||
|
// public long IdValue { get; set; }
|
||||||
|
// [Required]
|
||||||
|
// public decimal DecValue { get; set; }
|
||||||
|
|
||||||
//date of the event actually occuring, e.g. WarrantyExpiry date. Compared with subscription to determine if deliverable or not
|
//date of the event actually occuring, e.g. WarrantyExpiry date. Compared with subscription to determine if deliverable or not
|
||||||
public DateTime EventDate { get; set; }
|
public DateTime EventDate { get; set; }
|
||||||
//NO: Delivery code consults subscription instead of this
|
|
||||||
// public DateTime? DeliverDate { get; set; }//date user wants the event notification delivered, usually same as event date but could be set earlier if Advance setting in effect. This is the date consulted for delivery only.
|
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +52,6 @@ namespace AyaNova.Models
|
|||||||
Created = EventDate = DateTime.UtcNow;
|
Created = EventDate = DateTime.UtcNow;
|
||||||
IdValue = 0;
|
IdValue = 0;
|
||||||
DecValue = 0;
|
DecValue = 0;
|
||||||
// AgeValue = TimeSpan.Zero;
|
|
||||||
AyaType = AyaType.NoType;
|
AyaType = AyaType.NoType;
|
||||||
ObjectId = 0;
|
ObjectId = 0;
|
||||||
Name = string.Empty;
|
Name = string.Empty;
|
||||||
|
|||||||
@@ -891,7 +891,10 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
|||||||
|
|
||||||
await ExecQueryAsync("CREATE TABLE anotifyevent (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created timestamp not null, " +
|
await ExecQueryAsync("CREATE TABLE anotifyevent (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created timestamp not null, " +
|
||||||
"ayatype integer not null, objectid bigint not null, name text not null, eventtype integer not null, notifysubscriptionid bigint not null references anotifysubscription(id) on delete cascade, " +
|
"ayatype integer not null, objectid bigint not null, name text not null, eventtype integer not null, notifysubscriptionid bigint not null references anotifysubscription(id) on delete cascade, " +
|
||||||
"userid bigint not null REFERENCES auser (id), idvalue bigint not null, decvalue decimal(19,4) not null, eventdate timestamp not null, message text)");
|
"userid bigint not null REFERENCES auser (id), eventdate timestamp not null, message text)");
|
||||||
|
//these fields were in here but seem to not be required so commented out for now, see notifyevent model for deets but
|
||||||
|
//basically remove this comment once certain don't need these fields (close to release or after)
|
||||||
|
//idvalue bigint not null, decvalue decimal(19,4) not null,
|
||||||
|
|
||||||
|
|
||||||
await ExecQueryAsync("CREATE TABLE anotification (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, userid bigint not null REFERENCES auser (id), " +
|
await ExecQueryAsync("CREATE TABLE anotification (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, userid bigint not null REFERENCES auser (id), " +
|
||||||
|
|||||||
Reference in New Issue
Block a user