From bcf2277664ff1da71ade2bca2fc3249a84a16907 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 17 Jun 2020 22:07:37 +0000 Subject: [PATCH] --- Controllers/RvlController.cs | 9 +++++-- Controllers/SiteController.cs | 42 ++++++++++++++++++------------- wwwroot/js/app.api.js | 6 ++--- wwwroot/js/app.ravLicense.js | 3 +++ wwwroot/js/app.ravLicenses.js | 2 +- wwwroot/js/app.shell.js | 4 +-- wwwroot/js/templates/templates.js | 2 +- 7 files changed, 41 insertions(+), 27 deletions(-) diff --git a/Controllers/RvlController.cs b/Controllers/RvlController.cs index 7a4502c..5bc4b65 100644 --- a/Controllers/RvlController.cs +++ b/Controllers/RvlController.cs @@ -14,7 +14,7 @@ namespace rockfishCore.Controllers { //### OUR ROUTE CALLED FROM ROCKFISH CLIENT #### [Produces("application/json")] - [Route("rvl")] + [Route("api/rvl")] [Authorize] public class RvlController : Controller { @@ -143,9 +143,14 @@ namespace rockfishCore.Controllers } } + [HttpGet] + public ActionResult GetTest() + { + return Ok("hi"); + } [HttpGet("list/{siteId}")] - public async Task GetList(long siteId) + public async Task GetList([FromRoute] long siteId) { return Ok(await ct.License.AsNoTracking().Where(z => z.SiteId == siteId).OrderByDescending(z => z.Id).ToListAsync()); } diff --git a/Controllers/SiteController.cs b/Controllers/SiteController.cs index c61624e..b6a3e8a 100644 --- a/Controllers/SiteController.cs +++ b/Controllers/SiteController.cs @@ -15,11 +15,11 @@ namespace rockfishCore.Controllers [Authorize] public class SiteController : Controller { - private readonly rockfishContext _context; + private readonly rockfishContext ct; public SiteController(rockfishContext context) { - _context = context; + ct = context; } @@ -27,7 +27,7 @@ namespace rockfishCore.Controllers [HttpGet("{id}/purchases")] public IEnumerable GetPurchases([FromRoute] long id) { - var l = _context.Purchase + var l = ct.Purchase .Where(b => b.SiteId.Equals(id)) .OrderByDescending(b => b.PurchaseDate) .ToList(); @@ -46,16 +46,16 @@ namespace rockfishCore.Controllers // return l; // } - //Get api/site/77/activepurchases + //Get api/site/77/activepurchases [HttpGet("{id}/activepurchases")] public IEnumerable GetActivePurchases([FromRoute] long id) { - var res = from c in _context.Purchase + var res = from c in ct.Purchase .Where(c => c.SiteId.Equals(id)) - .Where(c => c.CancelDate==null) + .Where(c => c.CancelDate == null) .OrderByDescending(c => c.PurchaseDate) select new dtoNameIdItem - { + { id = c.Id, name = c.Name }; @@ -94,7 +94,7 @@ namespace rockfishCore.Controllers return BadRequest(ModelState); } - var ret = await _context.Site + var ret = await ct.Site .Select(r => new { r.Id, r.Name, r.CustomerId }) .Where(r => r.Id == id) .FirstAsync(); @@ -107,7 +107,7 @@ namespace rockfishCore.Controllers [HttpGet] public IEnumerable GetSite() { - return _context.Site; + return ct.Site; } // GET: api/Site/5 @@ -119,7 +119,7 @@ namespace rockfishCore.Controllers return BadRequest(ModelState); } - var site = await _context.Site.AsNoTracking().SingleOrDefaultAsync(m => m.Id == id); + var site = await ct.Site.AsNoTracking().SingleOrDefaultAsync(m => m.Id == id); if (site == null) { @@ -143,11 +143,11 @@ namespace rockfishCore.Controllers return BadRequest(); } - _context.Entry(site).State = EntityState.Modified; + ct.Entry(site).State = EntityState.Modified; try { - await _context.SaveChangesAsync(); + await ct.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { @@ -173,8 +173,8 @@ namespace rockfishCore.Controllers return BadRequest(ModelState); } - _context.Site.Add(site); - await _context.SaveChangesAsync(); + ct.Site.Add(site); + await ct.SaveChangesAsync(); return CreatedAtAction("GetSite", new { id = site.Id }, site); } @@ -190,7 +190,7 @@ namespace rockfishCore.Controllers } - var site = await _context.Site.SingleOrDefaultAsync(m => m.Id == id); + var site = await ct.Site.SingleOrDefaultAsync(m => m.Id == id); if (site == null) { @@ -198,15 +198,21 @@ namespace rockfishCore.Controllers } - _context.Site.Remove(site); - await _context.SaveChangesAsync(); + if (await ct.License.Where(z => z.SiteId == id).AnyAsync()) + { + return BadRequest("This site has licenses and can not be deleted"); + } + + + ct.Site.Remove(site); + await ct.SaveChangesAsync(); return Ok(site); } private bool SiteExists(long id) { - return _context.Site.Any(e => e.Id == id); + return ct.Site.Any(e => e.Id == id); } } } \ No newline at end of file diff --git a/wwwroot/js/app.api.js b/wwwroot/js/app.api.js index c40a029..ae58e17 100644 --- a/wwwroot/js/app.api.js +++ b/wwwroot/js/app.api.js @@ -24,6 +24,7 @@ app.api = (function () { putAction, postAction, createLicense, + createRavLicense, getLicenseRequests, generateFromRequest, licenseEmailResponse; @@ -273,8 +274,7 @@ app.api = (function () { }); }; - -/////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////// //CreateRavLicense //Route app.post('/api/license/create', function (req, res) { // @@ -299,7 +299,6 @@ app.api = (function () { }); }; - /////////////////////////////////////////////////////////// //GetLicenseRequests //Fetch license requests @@ -387,6 +386,7 @@ app.api = (function () { putAction: putAction, postAction: postAction, createLicense: createLicense, + createRavLicense: createRavLicense, getLicenseRequests: getLicenseRequests, generateFromRequest: generateFromRequest, licenseEmailResponse: licenseEmailResponse diff --git a/wwwroot/js/app.ravLicense.js b/wwwroot/js/app.ravLicense.js index 82ebd75..eebf01a 100644 --- a/wwwroot/js/app.ravLicense.js +++ b/wwwroot/js/app.ravLicense.js @@ -131,6 +131,9 @@ app.ravLicense = (function () { } $container.html(Handlebars.templates['app.ravLicense']({})); + ///ravLicense/:id/:site_id + //either fetch one to display or start one to create + debugger; //case 3233 customer list //Fill customer list combo diff --git a/wwwroot/js/app.ravLicenses.js b/wwwroot/js/app.ravLicenses.js index 9086492..b8d1832 100644 --- a/wwwroot/js/app.ravLicenses.js +++ b/wwwroot/js/app.ravLicenses.js @@ -46,7 +46,7 @@ app.ravLicenses = (function() { //=================== //Get licenses - app.api.get("rvl/list/"+ stateMap.id, function(res) { + app.api.get("rvl/list/"+ stateMap.id, function(res) { if (res.error) { $.gevent.publish("app-show-error", res.msg); } else { diff --git a/wwwroot/js/app.shell.js b/wwwroot/js/app.shell.js index a4684dc..63f514b 100644 --- a/wwwroot/js/app.shell.js +++ b/wwwroot/js/app.shell.js @@ -240,8 +240,8 @@ app.shell = (function () { page('/ops', ops); page('/trials', trials); page('/trialEdit/:id', trialEdit); - page('/ravLicenses/:id/', ravLicenses); - page('/ravLicense/:id/:site_id', ravLicense); + page('/ravLicenses/:id', ravLicenses); + page('/ravLicense/:id', ravLicense); page('*', notFound); page({ hashbang: true diff --git a/wwwroot/js/templates/templates.js b/wwwroot/js/templates/templates.js index 1a6fefb..5db7502 100644 --- a/wwwroot/js/templates/templates.js +++ b/wwwroot/js/templates/templates.js @@ -1 +1 @@ -!function(){var n=Handlebars.template,e=Handlebars.templates=Handlebars.templates||{};e["app.authenticate"]=n({compiler:[8,">= 4.3.0"],main:function(n,e,a,l,i){return'
\n Rockfish logo\n

Login

\n
\n

\n

\n

\n
\n
'},useData:!0}),e["app.customerEdit"]=n({compiler:[8,">= 4.3.0"],main:function(n,e,a,l,i){return'
\n
\n\n\n
\n \n \n
\n\n
\n \n \n
\n\n
\n \n \n
\n\n
\n \n \n
\n\n
\n \n
\n\n\n
\n \n
\n\n\n\n
\n \n