diff --git a/Controllers/CustomerController.cs b/Controllers/CustomerController.cs index 2f5a0c4..9425e89 100644 --- a/Controllers/CustomerController.cs +++ b/Controllers/CustomerController.cs @@ -26,20 +26,52 @@ namespace rockfishCore.Controllers //Get api/customer/list [HttpGet("list")] - public IEnumerable GetList() + public IEnumerable GetList() { var res = from c in _context.Customer.OrderBy(c => c.Name) - select new dtoNameIdActiveItem + select new dtoCustomerListItem { + lapsed = false, active = c.Active, id = c.Id, name = c.Name }; - return res.ToList(); + + //Need to be made into a list before updating or else the changes would be lost + //The tolist is what triggers the actual query to run + var LapsedRes = res.ToList(); + foreach (dtoCustomerListItem i in LapsedRes) + { + i.lapsed = CustomerHasLapsed(i.id); + } + + return LapsedRes; } + /// + /// Check if a customer has any active subs + /// return true if no active subs + /// Active means cancel date is empty or not yet come to pass + /// and expire date is not empty and not yet come to pass + /// + /// + /// + private bool CustomerHasLapsed(long customerId) + { + long EpochNow = DateUtil.NowAsEpoch(); + + var count = _context.Purchase + .Where(c => c.CustomerId.Equals(customerId)) + .Where(c => c.CancelDate == null || c.CancelDate > EpochNow) + .Where(c => c.ExpireDate != null && c.ExpireDate > EpochNow) + .Count(); + + return count < 1; + + } + //Get api/customer/77/sitelist [HttpGet("{id}/sitelist")] public IEnumerable GetSiteList([FromRoute] long id) diff --git a/Models/dtoCustomerListItem.cs b/Models/dtoCustomerListItem.cs new file mode 100644 index 0000000..489d479 --- /dev/null +++ b/Models/dtoCustomerListItem.cs @@ -0,0 +1,11 @@ +namespace rockfishCore.Models +{ + //Used to populate list routes for return + public class dtoCustomerListItem + { + public bool active; + public bool lapsed; + public long id; + public string name; + } +} \ No newline at end of file diff --git a/Startup.cs b/Startup.cs index 963fb19..e07f0ce 100644 --- a/Startup.cs +++ b/Startup.cs @@ -39,7 +39,13 @@ namespace rockfishCore public void ConfigureServices(IServiceCollection services) { - services.AddDbContext(options => options.UseSqlite(Configuration.GetConnectionString("rfdb"))); + services.AddDbContext( + options => { + options.UseSqlite(Configuration.GetConnectionString("rfdb")); + options.EnableSensitiveDataLogging(false); + } + + ); //Added this so that can access configuration from anywhere else //See authcontroller for usage diff --git a/wwwroot/js/app.inbox.js b/wwwroot/js/app.inbox.js index 53eea47..07ec5e3 100644 --- a/wwwroot/js/app.inbox.js +++ b/wwwroot/js/app.inbox.js @@ -103,6 +103,7 @@ app.inbox = (function() { } //do it every 5 minutes timerVar=setTimeout(getMessages,5*60*1000); + //timerVar=setTimeout(getMessages,5000); console.log("INBOX.GETMESSAGES - started timer " + timerVar); }); };