This commit is contained in:
2020-06-18 13:45:12 +00:00
parent e5858bebd1
commit 7f65c843e0
4 changed files with 27 additions and 20 deletions

View File

@@ -17,11 +17,11 @@ namespace rockfishCore.Controllers
[Authorize]
public class CustomerController : Controller
{
private readonly rockfishContext _context;
private readonly rockfishContext ct;
public CustomerController(rockfishContext context)
{
_context = context;
ct = context;
}
//Get api/customer/list
@@ -29,7 +29,7 @@ namespace rockfishCore.Controllers
public IEnumerable<dtoCustomerListItem> GetList()
{
var res = from c in _context.Customer.OrderBy(c => c.Name)
var res = from c in ct.Customer.OrderBy(c => c.Name)
select new dtoCustomerListItem
{
lapsed = false,
@@ -88,12 +88,15 @@ namespace rockfishCore.Controllers
{
long EpochNow = DateUtil.NowAsEpoch();
var count = _context.Purchase
var count = ct.Purchase
.Where(c => c.CustomerId.Equals(customerId))
.Where(c => c.CancelDate == null || c.CancelDate > EpochNow)
.Where(c => c.ExpireDate != null && c.ExpireDate > EpochNow)
.Count();
//handle raven keys here
// var ravActiveMaintenanceCount=ct.License.Where(z=>z.CustomerId==customerId && z.)
return count < 1;
}
@@ -103,7 +106,7 @@ namespace rockfishCore.Controllers
public IEnumerable<dtoNameIdItem> GetSiteList([FromRoute] long id)
{
var res = from c in _context.Site
var res = from c in ct.Site
.Where(c => c.CustomerId.Equals(id)).OrderBy(c => c.Name)
select new dtoNameIdItem
{
@@ -121,7 +124,7 @@ namespace rockfishCore.Controllers
long EpochNow = DateUtil.NowAsEpoch();
var res = from c in _context.Site
var res = from c in ct.Site
.Where(c => c.CustomerId.Equals(id)).OrderBy(c => c.Name)
select new dtoNameIdChildrenItem
{
@@ -134,7 +137,7 @@ namespace rockfishCore.Controllers
foreach (dtoNameIdChildrenItem child in resList)
{
var subs = from c in _context.Purchase
var subs = from c in ct.Purchase
.Where(c => c.SiteId.Equals(child.id))
.Where(c => c.CancelDate == null || c.CancelDate > EpochNow)
.OrderByDescending(c => c.PurchaseDate)
@@ -160,7 +163,7 @@ namespace rockfishCore.Controllers
public IEnumerable<Site> GetSites([FromRoute] long id)
{
//from https://docs.microsoft.com/en-us/ef/core/querying/basic
var sites = _context.Site
var sites = ct.Site
.Where(b => b.CustomerId.Equals(id))
.OrderByDescending(b => b.Id)
.ToList();
@@ -206,7 +209,7 @@ namespace rockfishCore.Controllers
//on this client url
//http://localhost:5000/default.htm#!/customerSites/85
var ret = await _context.Customer
var ret = await ct.Customer
.Select(r => new { r.Id, r.Name })
.Where(r => r.Id == id)
.FirstAsync();
@@ -226,7 +229,7 @@ namespace rockfishCore.Controllers
[HttpGet]
public IEnumerable<Customer> GetCustomer()
{
return _context.Customer;
return ct.Customer;
}
@@ -241,7 +244,7 @@ namespace rockfishCore.Controllers
return BadRequest(ModelState);
}
var customer = await _context.Customer.SingleOrDefaultAsync(m => m.Id == id);
var customer = await ct.Customer.SingleOrDefaultAsync(m => m.Id == id);
if (customer == null)
{
@@ -265,11 +268,11 @@ namespace rockfishCore.Controllers
return BadRequest();
}
_context.Entry(customer).State = EntityState.Modified;
ct.Entry(customer).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
await ct.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
@@ -296,8 +299,8 @@ namespace rockfishCore.Controllers
return BadRequest(ModelState);
}
_context.Customer.Add(customer);
await _context.SaveChangesAsync();
ct.Customer.Add(customer);
await ct.SaveChangesAsync();
return CreatedAtAction("GetCustomer", new { id = customer.Id }, customer);
}
@@ -311,21 +314,21 @@ namespace rockfishCore.Controllers
return BadRequest(ModelState);
}
var customer = await _context.Customer.SingleOrDefaultAsync(m => m.Id == id);
var customer = await ct.Customer.SingleOrDefaultAsync(m => m.Id == id);
if (customer == null)
{
return NotFound();
}
_context.Customer.Remove(customer);
await _context.SaveChangesAsync();
ct.Customer.Remove(customer);
await ct.SaveChangesAsync();
return Ok(customer);
}
private bool CustomerExists(long id)
{
return _context.Customer.Any(e => e.Id == id);
return ct.Customer.Any(e => e.Id == id);
}
}
}