This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user