This commit is contained in:
@@ -26,20 +26,52 @@ namespace rockfishCore.Controllers
|
|||||||
|
|
||||||
//Get api/customer/list
|
//Get api/customer/list
|
||||||
[HttpGet("list")]
|
[HttpGet("list")]
|
||||||
public IEnumerable<dtoNameIdActiveItem> GetList()
|
public IEnumerable<dtoCustomerListItem> GetList()
|
||||||
{
|
{
|
||||||
|
|
||||||
var res = from c in _context.Customer.OrderBy(c => c.Name)
|
var res = from c in _context.Customer.OrderBy(c => c.Name)
|
||||||
select new dtoNameIdActiveItem
|
select new dtoCustomerListItem
|
||||||
{
|
{
|
||||||
|
lapsed = false,
|
||||||
active = c.Active,
|
active = c.Active,
|
||||||
id = c.Id,
|
id = c.Id,
|
||||||
name = c.Name
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="customerId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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
|
//Get api/customer/77/sitelist
|
||||||
[HttpGet("{id}/sitelist")]
|
[HttpGet("{id}/sitelist")]
|
||||||
public IEnumerable<dtoNameIdItem> GetSiteList([FromRoute] long id)
|
public IEnumerable<dtoNameIdItem> GetSiteList([FromRoute] long id)
|
||||||
|
|||||||
11
Models/dtoCustomerListItem.cs
Normal file
11
Models/dtoCustomerListItem.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,7 +39,13 @@ namespace rockfishCore
|
|||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
|
||||||
services.AddDbContext<rockfishContext>(options => options.UseSqlite(Configuration.GetConnectionString("rfdb")));
|
services.AddDbContext<rockfishContext>(
|
||||||
|
options => {
|
||||||
|
options.UseSqlite(Configuration.GetConnectionString("rfdb"));
|
||||||
|
options.EnableSensitiveDataLogging(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
//Added this so that can access configuration from anywhere else
|
//Added this so that can access configuration from anywhere else
|
||||||
//See authcontroller for usage
|
//See authcontroller for usage
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ app.inbox = (function() {
|
|||||||
}
|
}
|
||||||
//do it every 5 minutes
|
//do it every 5 minutes
|
||||||
timerVar=setTimeout(getMessages,5*60*1000);
|
timerVar=setTimeout(getMessages,5*60*1000);
|
||||||
|
//timerVar=setTimeout(getMessages,5000);
|
||||||
console.log("INBOX.GETMESSAGES - started timer " + timerVar);
|
console.log("INBOX.GETMESSAGES - started timer " + timerVar);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user