Files
rockfish/Controllers/RvrController.cs
2020-06-11 20:15:01 +00:00

90 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using rockfishCore.Models;
using rockfishCore.Util;
using System.ComponentModel.DataAnnotations;
namespace rockfishCore.Controllers
{
[Produces("text/plain")]
[Route("rvr")]
public class RvrController : Controller //RAVEN trial license request
{
private readonly rockfishContext ct;
public RvrController(rockfishContext context)
{
ct = context;
}
public class dtoRequest
{
[Required]
public Guid DbId { get; set; }
[Required, EmailAddress]
public string Email { get; set; }
[Required]
public string Company { get; set; }
[Required]
public string Contact { get; set; }
}
[HttpPost]
public async Task<IActionResult> Post([FromBody] dtoRequest r)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (r.DbId == Guid.Empty)
{
return BadRequest("DBId invalid");
}
//can't do this if there is a purchased license with this dbid already
if (await ct.License.Where(z => z.DbId == r.DbId).AnyAsync())
{
return BadRequest("E1000 - Can't trial; there is already a purchased license issued for this database ID");
}
//if there is an active trial then can't do this
var MustBeOlderThan=DateUtil.DateToEpoch(DateTime.Now.AddDays(-45))
if (await ct.TrialRequest.Where(z => z.DbId == r.DbId && z.DtProcessed != null && z.DtProcessed < MustBeOlderThan).AnyAsync())
{
// //is it a trial request
// var TrialRequest = await ct.TrialRequest.Where(z => z.DbId == dbid && z.DtFetched == null).FirstOrDefaultAsync();
// LicenseKey = TrialRequest.Key;
// TrialRequest.DtFetched = DateUtil.NowAsEpoch();
// await ct.SaveChangesAsync();
}
//TODO: closer to release as ROCKFISH might change before then
//Attempt to match customer by dbid if not then create new customer of trial type for the indicated dbid and regto
//ensure this email goes into the adminEmail array if not already there
//Flag customer record has having an unfulfilled trial request
//If it's a new customer or an existing one with non-matching email then send a verification email to the customer
//When a response is spotted in email then Rockfish should see it and flag the customer as verified
//Probably some general purpose email Verify code would be helpful here as it would likely be useful for all manner of things
//When user releases trial in Rockfish a license key will be generated ready for the customers RAVEN to retrieve
return Ok("Request accepted. Awaiting email verification and approval.");
}
}//eoc
}//eons