This commit is contained in:
197
Controllers/TrialController.cs
Normal file
197
Controllers/TrialController.cs
Normal file
@@ -0,0 +1,197 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Security.Claims;
|
||||
using rockfishCore.Models;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
|
||||
namespace rockfishCore.Controllers
|
||||
{
|
||||
//Authentication controller
|
||||
[Produces("application/json")]
|
||||
[Route("api/trial")]
|
||||
[Authorize]
|
||||
public class TrialController : Controller
|
||||
{
|
||||
private readonly rockfishContext ct;
|
||||
private readonly IConfiguration _configuration;
|
||||
public TrialController(rockfishContext context, IConfiguration configuration)//these two are injected, see startup.cs
|
||||
{
|
||||
ct = context;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
|
||||
//Fetch list of trial requests
|
||||
[HttpGet("requests")]
|
||||
public ActionResult GetRequests()
|
||||
{
|
||||
var ret=ct.trialre
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// STORED Trial KEY CRUD ROUTES
|
||||
//
|
||||
|
||||
//case 3233 Get api/Trial/list a list of generated Trials
|
||||
[HttpGet("list")]
|
||||
public IEnumerable<dtoTrialListItem> GetList()
|
||||
{
|
||||
var res = from c in ct.Trial.OrderByDescending(c => c.DtCreated)
|
||||
select new dtoTrialListItem
|
||||
{
|
||||
id = c.Id,
|
||||
created = c.DtCreated,
|
||||
regto = c.RegTo,
|
||||
fetched = c.Fetched,
|
||||
trial = (c.CustomerId==0)
|
||||
};
|
||||
return res.ToList();
|
||||
}
|
||||
|
||||
//case 3233 GET: api/Trial/5
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> GetTrial([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var l = await ct.Trial.SingleOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
if (l == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
string customerName = "<TRIAL>";
|
||||
|
||||
if (l.CustomerId != 0)
|
||||
{
|
||||
if (ct.Customer.Any(e => e.Id == l.CustomerId))
|
||||
{
|
||||
|
||||
var cust = await ct.Customer
|
||||
.Select(r => new { r.Id, r.Name })
|
||||
.Where(r => r.Id == l.CustomerId)
|
||||
.FirstAsync();
|
||||
customerName=cust.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
customerName = "< Customer " + l.CustomerId.ToString() + " not found (deleted?) >";
|
||||
}
|
||||
}
|
||||
|
||||
var ret = new
|
||||
{
|
||||
regTo = l.RegTo,
|
||||
customerName = customerName,
|
||||
dtcreated = l.DtCreated,
|
||||
email = l.Email,
|
||||
code = l.Code,
|
||||
fetched = l.Fetched,
|
||||
dtfetched = l.DtFetched,
|
||||
fetchFrom = l.FetchFrom,
|
||||
key = l.Key
|
||||
};
|
||||
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
// DELETE: api/Trial/5
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteTrial([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var rec = await ct.Trial.SingleOrDefaultAsync(m => m.Id == id);
|
||||
if (rec == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
ct.Trial.Remove(rec);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
return Ok(rec);
|
||||
}
|
||||
|
||||
|
||||
// PUT: api/Trial/5/true
|
||||
//Update a Trial and set it's fetched property only
|
||||
//used by client to make a Trial fetchable or not ad-hoc
|
||||
[HttpPut("fetched/{id}/{isFetched}")]
|
||||
public async Task<IActionResult> PutTrialFetched([FromRoute] long id, [FromRoute] bool isFetched)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var rec = await ct.Trial.SingleOrDefaultAsync(m => m.Id == id);
|
||||
if (rec == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
rec.Fetched = isFetched;
|
||||
|
||||
ct.Entry(rec).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!TrialExists(id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private bool TrialExists(long id)
|
||||
{
|
||||
return ct.Trial.Any(e => e.Id == id);
|
||||
}
|
||||
|
||||
//===================== UTILITY =============
|
||||
private string GetRFAuthorizedUserStamp()
|
||||
{
|
||||
foreach (Claim c in User.Claims)
|
||||
{
|
||||
if (c.Type == "id")
|
||||
{
|
||||
return "RFID" + c.Value;
|
||||
}
|
||||
}
|
||||
return "RFID unknown";
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
30
Models/TrialRequest.cs
Normal file
30
Models/TrialRequest.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace rockfishCore.Models
|
||||
{
|
||||
/*
|
||||
exec("CREATE TABLE trialrequest (" +
|
||||
"id INTEGER PRIMARY KEY, dbid text not null, companyname text not null, contactname text not null, notes text, email text not null, " +
|
||||
"emailvalidated boolean default 0 NOT NULL CHECK (emailvalidated IN (0,1)), dtrequested integer, " +
|
||||
"dtprocessed integer, status integer default 0 not null, rejectreason text, key text, dtfetched integer" +
|
||||
")");
|
||||
*/
|
||||
public partial class TrialRequest
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string DbId { get; set; }
|
||||
public string CompanyName { get; set; }
|
||||
public string ContactName { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string Email { get; set; }
|
||||
public bool EmailValidated { get; set; }
|
||||
public long? DtRequested { get; set; }
|
||||
public long? DtProcessed { get; set; }
|
||||
public int Status { get; set; }
|
||||
public string RejectReason { get; set; }
|
||||
public string Key { get; set; }
|
||||
public long? DtFetched { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,8 @@ namespace rockfishCore.Models
|
||||
//schema 10 case 3233
|
||||
public virtual DbSet<License> License { get; set; }
|
||||
|
||||
|
||||
//raven
|
||||
public virtual DbSet<TrialRequest> TrialRequest { get; set; }
|
||||
|
||||
//Note: had to add this constructor to work with the code in startup.cs that gets the connection string from the appsettings.json file
|
||||
//and commented out the above on configuring
|
||||
|
||||
@@ -238,6 +238,8 @@ app.shell = (function () {
|
||||
page('/rfcaseEdit/:id', rfcaseEdit);
|
||||
page('/rfsettings', rfsettings);
|
||||
page('/ops', ops);
|
||||
page('/trials', trials);
|
||||
page('/trialEdit/:id', trialEdit);
|
||||
page('*', notFound);
|
||||
page({
|
||||
hashbang: true
|
||||
@@ -549,6 +551,25 @@ app.shell = (function () {
|
||||
}
|
||||
|
||||
|
||||
//case 3233
|
||||
var trials = function (ctx) {
|
||||
app.nav.setSelectedMenuItem('trials');
|
||||
app.trials.configModule({
|
||||
context: ctx
|
||||
});
|
||||
app.trials.initModule();
|
||||
}
|
||||
|
||||
//case 3233
|
||||
var trialEdit = function (ctx) {
|
||||
app.nav.setSelectedMenuItem('trials');
|
||||
app.trialEdit.configModule({
|
||||
context: ctx
|
||||
});
|
||||
app.trialEdit.initModule();
|
||||
}
|
||||
|
||||
|
||||
var notFound = function (ctx) {
|
||||
app.fourohfour.configModule({
|
||||
context: ctx
|
||||
|
||||
116
wwwroot/js/app.trialEdit.js
Normal file
116
wwwroot/js/app.trialEdit.js
Normal file
@@ -0,0 +1,116 @@
|
||||
/*jslint browser : true, continue : true,
|
||||
devel : true, indent : 2, maxerr : 50,
|
||||
newcap : true, nomen : true, plusplus : true,
|
||||
regexp : true, sloppy : true, vars : false,
|
||||
white : true
|
||||
*/
|
||||
|
||||
/*global $, app */
|
||||
|
||||
app.trialEdit = (function () {
|
||||
'use strict';
|
||||
//---------------- BEGIN MODULE SCOPE VARIABLES --------------
|
||||
var
|
||||
stateMap = {},
|
||||
onSave, onDelete,
|
||||
configModule, initModule;
|
||||
//----------------- END MODULE SCOPE VARIABLES ---------------
|
||||
|
||||
|
||||
//------------------- BEGIN EVENT HANDLERS -------------------
|
||||
|
||||
//ONSAVE
|
||||
//
|
||||
onSave = function (event) {
|
||||
event.preventDefault();
|
||||
$.gevent.publish('app-clear-error');
|
||||
|
||||
var isFetched=$('#fetched').prop('checked')
|
||||
|
||||
// var submitData = { isFetched: isFetched };
|
||||
app.api.putAction('trial/fetched/' + stateMap.id + "/" + isFetched, function (res) {
|
||||
if (res.error) {
|
||||
$.gevent.publish('app-show-error', res.msg);
|
||||
}
|
||||
});
|
||||
|
||||
return false; //prevent default?
|
||||
};
|
||||
|
||||
//ONDELETE
|
||||
//
|
||||
onDelete = function (event) {
|
||||
event.preventDefault();
|
||||
$.gevent.publish('app-clear-error');
|
||||
var r = confirm("Are you sure you want to delete this record?");
|
||||
if (r == true) {
|
||||
app.api.remove('trial/' + stateMap.id, function (res) {
|
||||
if (res.error) {
|
||||
$.gevent.publish('app-show-error', res.msg);
|
||||
} else {
|
||||
page('#!/trials');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false; //prevent default?
|
||||
};
|
||||
|
||||
|
||||
//-------------------- END EVENT HANDLERS --------------------
|
||||
|
||||
//------------------- BEGIN PUBLIC METHODS -------------------
|
||||
|
||||
|
||||
//CONFIGMODULE
|
||||
//
|
||||
configModule = function (context) {
|
||||
stateMap.context = context.context;
|
||||
if (stateMap.context.params.id) {
|
||||
stateMap.id = stateMap.context.params.id;
|
||||
}
|
||||
};
|
||||
|
||||
//INITMODULE
|
||||
//
|
||||
initModule = function ($container) {
|
||||
if (typeof $container === 'undefined') {
|
||||
$container = $('#app-shell-main-content');
|
||||
}
|
||||
|
||||
$container.html(Handlebars.templates['app.trialEdit']({}));
|
||||
|
||||
document.title = 'trial ';
|
||||
|
||||
//fetch existing record
|
||||
app.api.get('trial/' + stateMap.id, function (res) {
|
||||
if (res.error) {
|
||||
$.gevent.publish('app-show-error', res.msg);
|
||||
} else {
|
||||
//fill out form
|
||||
app.utilB.formData(res);
|
||||
}
|
||||
});
|
||||
//Context menu
|
||||
app.nav.contextClear();
|
||||
app.nav.contextAddLink("trials/", "List", "");
|
||||
|
||||
|
||||
|
||||
// bind actions
|
||||
$('#btn-save').bind('click', onSave);
|
||||
$('#btn-delete').bind('click', onDelete);
|
||||
};
|
||||
|
||||
|
||||
// RETURN PUBLIC METHODS
|
||||
//
|
||||
return {
|
||||
configModule: configModule,
|
||||
initModule: initModule
|
||||
};
|
||||
//------------------- END PUBLIC METHODS ---------------------
|
||||
}());
|
||||
108
wwwroot/js/app.trials.js
Normal file
108
wwwroot/js/app.trials.js
Normal file
@@ -0,0 +1,108 @@
|
||||
/*jslint browser : true, continue : true,
|
||||
devel : true, indent : 2, maxerr : 50,
|
||||
newcap : true, nomen : true, plusplus : true,
|
||||
regexp : true, sloppy : true, vars : false,
|
||||
white : true
|
||||
*/
|
||||
|
||||
/*global $, app */
|
||||
|
||||
app.trials = (function() {
|
||||
"use strict";
|
||||
//---------------- BEGIN MODULE SCOPE VARIABLES --------------
|
||||
var stateMap = {},
|
||||
configModule,
|
||||
initModule;
|
||||
//----------------- END MODULE SCOPE VARIABLES ---------------
|
||||
|
||||
//------------------- BEGIN UTILITY METHODS ------------------
|
||||
|
||||
//-------------------- END UTILITY METHODS -------------------
|
||||
|
||||
//------------------- BEGIN EVENT HANDLERS -------------------
|
||||
|
||||
//-------------------- END EVENT HANDLERS --------------------
|
||||
|
||||
//------------------- BEGIN PUBLIC METHODS -------------------
|
||||
//CONFIGMODULE
|
||||
//
|
||||
configModule = function(context) {
|
||||
stateMap.context = context.context;
|
||||
if (stateMap.context.params.id) {
|
||||
stateMap.id = stateMap.context.params.id;
|
||||
}
|
||||
};
|
||||
|
||||
//INITMODULE
|
||||
//
|
||||
initModule = function($container) {
|
||||
if (typeof $container === "undefined") {
|
||||
$container = $("#app-shell-main-content");
|
||||
}
|
||||
$container.html(Handlebars.templates["app.trials"]({}));
|
||||
|
||||
//case 3513
|
||||
document.title = "trials";
|
||||
|
||||
//===================
|
||||
//Get trials
|
||||
app.api.get("trial/list", function(res) {
|
||||
if (res.error) {
|
||||
$.gevent.publish("app-show-error", res.msg);
|
||||
} else {
|
||||
var $appList = $("#rf-list");
|
||||
|
||||
$appList.append('<ul class="list-group">');
|
||||
|
||||
$.each(res, function(i, obj) {
|
||||
if (obj.fetched) {
|
||||
$appList.append(
|
||||
"<li class='rfc-list-item-inactive list-group-item'><a href=\"#!/trialView/" +
|
||||
obj.id +
|
||||
'">' +
|
||||
"<span class='text-muted'>" +
|
||||
(obj.trial
|
||||
? "Trial "
|
||||
: "") +
|
||||
app.utilB.genListColumn(obj.regto) +
|
||||
" " +
|
||||
app.utilB.genListColumn(
|
||||
app.utilB.epochToShortDate(obj.created)
|
||||
) +
|
||||
"</span>" +
|
||||
"</a></li>"
|
||||
);
|
||||
} else {
|
||||
$appList.append(
|
||||
"<li class='list-group-item'><a href=\"#!/trialView/" +
|
||||
obj.id +
|
||||
'">' +
|
||||
(obj.trial
|
||||
? "Trial "
|
||||
: "") +
|
||||
app.utilB.genListColumn(obj.regto) +
|
||||
" " +
|
||||
app.utilB.genListColumn(
|
||||
app.utilB.epochToShortDate(obj.created)
|
||||
) +
|
||||
"</a></li>"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$appList.append("</ul>");
|
||||
}
|
||||
});
|
||||
//=========/trials==============
|
||||
|
||||
app.nav.contextClear();
|
||||
};
|
||||
|
||||
//PUBLIC METHODS
|
||||
//
|
||||
return {
|
||||
configModule: configModule,
|
||||
initModule: initModule
|
||||
};
|
||||
//------------------- END PUBLIC METHODS ---------------------
|
||||
})();
|
||||
@@ -1,7 +1,7 @@
|
||||
<nav id="rf-nav" class="navbar fixed-top navbar-expand-lg navbar-dark" style="background-color: #00205B;">
|
||||
{{!-- navbar-dark bg-success --}}
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
{{!-- navbar-dark bg-success --}}
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
|
||||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
<a class="rfac nav-link mdi mdi-contacts" href="#!/customers">Customers </a>
|
||||
</li>
|
||||
|
||||
<li id="trials" class="nav-item">
|
||||
<a class="rfac nav-link mdi mdi-voice" href="#!/trials">Trial requests </a>
|
||||
</li>
|
||||
|
||||
<li id="subscriptions" class="nav-item">
|
||||
<a class="rfac nav-link mdi mdi-basket" href="#!/subscription">Subscriptions </a>
|
||||
</li>
|
||||
|
||||
56
wwwroot/js/templates/app.trialEdit.handlebars
Normal file
56
wwwroot/js/templates/app.trialEdit.handlebars
Normal file
@@ -0,0 +1,56 @@
|
||||
<div>
|
||||
<form id="frm" method="post" action="index.html">
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="regTo">Registered to</label>
|
||||
<input class="form-control" type="text" id="regTo" name="regTo" value="" readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="customerName">Rockfish customer name</label>
|
||||
<input class="form-control" type="text" id="customerName" name="customerName" value="" readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="dtcreated">Created</label>
|
||||
<input class="form-control" type="date" id="dtcreated" name="dtcreated" value="" readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input class="form-control" type="text" id="email" name="email" value="" readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="code">Fetch code</label>
|
||||
<input class="form-control" type="text" id="code" name="code" value="" readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-check">
|
||||
<label class="form-check-label text-success font-weight-bold" for="fetched">
|
||||
<input class="form-check-input" type="checkbox" name="fetched" id="fetched"> License fetched</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="dtFetched">Fetched on</label>
|
||||
<input class="form-control" type="date" id="dtfetched" name="dtfetched" value="" readonly>
|
||||
</div>
|
||||
|
||||
{{!-- <div class="form-group">
|
||||
<label for="fetchFrom">Fetched from</label>
|
||||
<input class="form-control" type="text" id="fetchFrom" name="fetchFrom" value="" readonly>
|
||||
</div> --}}
|
||||
|
||||
<div class="form-group">
|
||||
<label for="key">Key</label>
|
||||
<textarea class="form-control form-control-lg" id="key" name="key" rows="10" readonly/>
|
||||
</div>
|
||||
|
||||
<div class="app-frm-buttons mt-5">
|
||||
<button id="btn-save" class="btn btn-success">Save</button>
|
||||
<button id="btn-delete" class="btn btn-outline-dark">Delete</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
3
wwwroot/js/templates/app.trials.handlebars
Normal file
3
wwwroot/js/templates/app.trials.handlebars
Normal file
@@ -0,0 +1,3 @@
|
||||
<div>
|
||||
<div id="rf-list" class="rf-list"/>
|
||||
</div>
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user