From 7f65c843e022846c2c27cd5220fd568ca13fd7e8 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 18 Jun 2020 13:45:12 +0000 Subject: [PATCH] --- Controllers/CustomerController.cs | 41 +++++++++++++++++-------------- Controllers/RvlController.cs | 2 +- Models/License.cs | 2 ++ util/RfSchema.cs | 2 ++ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Controllers/CustomerController.cs b/Controllers/CustomerController.cs index afd1e04..2fa57c8 100644 --- a/Controllers/CustomerController.cs +++ b/Controllers/CustomerController.cs @@ -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 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 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 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 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); } } } \ No newline at end of file diff --git a/Controllers/RvlController.cs b/Controllers/RvlController.cs index 8ec4145..496603f 100644 --- a/Controllers/RvlController.cs +++ b/Controllers/RvlController.cs @@ -136,7 +136,7 @@ namespace rockfishCore.Controllers //Key generated, record saved successfully //inform customer and return no content - var body = $"Thank you for your purchase!\nYour AyaNova license key is ready to be installed.\nAyaNova will fetch it automatically within 24 hours or you can force it to fetch immediately from the License page in AyaNova now.\n---\n{l}"; + var body = $"Thank you for your purchase!\nYour AyaNova license key is ready to be installed.\nAyaNova will fetch it automatically within 24 hours or you can force it to fetch immediately from the License page in AyaNova now.\n---\n{l.ToString()}"; //send license email #if (DEBUG) RfMail.SendMessage("support@ayanova.com", "cardjohn@ayanova.com", "AyaNova license key", body, false); diff --git a/Models/License.cs b/Models/License.cs index 75a4b23..52810d3 100644 --- a/Models/License.cs +++ b/Models/License.cs @@ -18,6 +18,8 @@ namespace rockfishCore.Models public long? DtFetched { get; set; } public bool Fetched { get; set; } public Guid DbId { get; set; } + public long DtLicenseExpiration { get; set; } + public long DtMaintenanceExpiration { get; set; } } } diff --git a/util/RfSchema.cs b/util/RfSchema.cs index 54497e5..aeb0529 100644 --- a/util/RfSchema.cs +++ b/util/RfSchema.cs @@ -374,6 +374,8 @@ namespace rockfishCore.Util exec("update site set legacyv7 = 1"); exec("alter table license add dbid text default 'v7_no_dbid' NOT NULL"); exec("alter table license add siteid integer"); + exec("alter table license add dtLicenseExpiration integer"); + exec("alter table license add dtMaintenanceExpiration integer"); exec("alter table purchase add quantity integer default 1 not null"); exec("insert into product (name, productCode, price, renewPrice) values ('TEST RAVEN schedulable resource 1 year subscription license','testfeatscheduser',15900, 5565);"); exec("insert into product (name, productCode, price, renewPrice) values ('TEST RAVEN Accounting 1 year subscription license','testfeatacct',15000, 5250);");