This commit is contained in:
2018-07-19 19:21:01 +00:00
parent ff6434f905
commit 10ded2681f
4 changed files with 54 additions and 4 deletions

View File

@@ -26,20 +26,52 @@ namespace rockfishCore.Controllers
//Get api/customer/list
[HttpGet("list")]
public IEnumerable<dtoNameIdActiveItem> GetList()
public IEnumerable<dtoCustomerListItem> 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;
}
/// <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
[HttpGet("{id}/sitelist")]
public IEnumerable<dtoNameIdItem> GetSiteList([FromRoute] long id)

View 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;
}
}

View File

@@ -39,7 +39,13 @@ namespace rockfishCore
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
//See authcontroller for usage

View File

@@ -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);
});
};