Compare commits

...

3 Commits

Author SHA1 Message Date
677582d4bb Added Newtonsoft JSON.
Added input formatter for Cart saving.
Added preload for INV, Customers.
2023-05-18 15:16:14 -04:00
6466d17905 Added incoming Cart save functions. 2023-05-18 15:15:17 -04:00
ebf3d3069b Email Namespace change update from CVRLIB 2023-05-18 15:14:43 -04:00
5 changed files with 179 additions and 17 deletions

View File

@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc.Formatters;
namespace CA_ANC.Formatters;
public class Formatters {
}
public class ByteArrayInputFormatter : InputFormatter
{
public ByteArrayInputFormatter()
{
SupportedMediaTypes.Add(Microsoft.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/octet-stream"));
}
protected override bool CanReadType(Type type)
{
return type == typeof(byte[]);
}
public async override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context)
{
var stream = new MemoryStream();
await context.HttpContext.Request.Body.CopyToAsync(stream);
return await InputFormatterResult.SuccessAsync(stream.ToArray());
}
}

View File

@ -0,0 +1,73 @@
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Http;
using CVRLIB.CARTS;
using static CVRLIB.CVSTRINGS.TextFuncs;
using Newtonsoft.Json;
using CVRLIB;
namespace VSERVERWS.Controllers {
//https://vserverws.cvr.cvrco.ca/api/cart/CartStatus
[Route("api/Cart/[action]")]
[ApiController]
public class CartController : ControllerBase {
[HttpGet]
public IActionResult CartStatus() {
var rOBJ = new { STATUS = "OK" };
return new JsonResult(rOBJ);
}
[HttpPost]
public async Task<IActionResult> SubmitCartData([FromBody] byte[] data) {
var JSON = await NonSecureDecryptByteAToStringAsync(data);
var rOBJ = new TryCartOperationResult();
try {
var tCART = JsonConvert.DeserializeObject<ShoppingCart>(JSON);
if (tCART != null) {
tCART.TrySyncToInventory(CVGlobal.INVENTORY);
await tCART.SaveToDBAsync();
rOBJ.AddResult(true, "CART_SAVE_TO_DB");
} else {
rOBJ.AddResult(false, "CONVERT_TO_JSON", "Failed to convert to json from byte data.");
}
} catch (Exception ex) {
rOBJ.AddResult(false, "CART_SAVE_TRY", ex.Message, ex);
}
//return new result
return new JsonResult(rOBJ);
}
}
}

View File

@ -35,9 +35,9 @@ namespace VSERVERWS.Controllers {
[HttpGet]
public IActionResult PaymentStatus() {
//api/Payment/PaymentStatus
CVRPRINTER_MF264dw? CVP2 = CVP_MF264dw;
CVRPRINTER_MFC_L8900CDW? CVP3 = CVP_MFC_L8900CDW;
@ -115,7 +115,7 @@ namespace VSERVERWS.Controllers {
if (DateTime.Now.Subtract(LastError).Hours > 2) {
Email E = new Email();
E.SEND_FROM = Email.SEND_FROM_ENUM.OFFICE365;
E.SEND_FROM = SEND_FROM_ENUM.OFFICE365;
string B = "Payment System Printer error / offline: Check applicable printer(s) for error or offline!";
string S = "<cc> Payment System Printer Error: Check Printer(s)!";
@ -148,7 +148,7 @@ namespace VSERVERWS.Controllers {
object? rOBJ = null;
Email E = new Email();
E.SEND_FROM = Email.SEND_FROM_ENUM.OFFICE365;
E.SEND_FROM = SEND_FROM_ENUM.OFFICE365;
bool DupRetry = false;

View File

@ -1,18 +1,32 @@
using CVRLIB.CVENVIRONMENT;
using static CVRLIB.CVGlobal;
using CA_ANC.Formatters;
using CVRLIB;
using CVRLIB.Inventory;
using CVRLIB.Customers;
//ZXING.dll does not copy properly to publish folder, copy manually from another lib, ie cvrlib-nf.
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddControllers().AddJsonOptions((options => {
//was changing PRINTER_NAME to printeR_NAME (pascal Case: https://github.com/dotnet/runtime/issues/30887)
options.JsonSerializerOptions.PropertyNamingPolicy = null;
}));
//builder.Services.AddControllers().AddJsonOptions((options => {
// //was changing PRINTER_NAME to printeR_NAME (pascal Case: https://github.com/dotnet/runtime/issues/30887)
// options.JsonSerializerOptions.PropertyNamingPolicy = null;
//}));
builder.Services
.AddControllers(options => { options.InputFormatters.Add(new ByteArrayInputFormatter()); })
.AddNewtonsoftJson()
;
var app = builder.Build();
@ -27,6 +41,14 @@ if (!app.Environment.IsDevelopment()) {
VSERVERWS.Global.Globals.IsDevelopment = app.Environment.IsDevelopment();
VSERVERWS.Global.Globals.LoadPrinters();
CVGlobal.TryGlobalPRELoadCVCollections(new[] { typeof(CVINVENTORY), typeof(CVCustomers) });
app.UseHttpsRedirection();
app.UseStaticFiles();
@ -42,4 +64,19 @@ app.MapRazorPages();
app.Run();
VSERVERWS.Global.Globals.LoadPrinters();
public partial class Program {
public static CVSECRETS? CVS { get; set; } = null;
public static string AppPath { get; set; } = "";
public static string HTTPROOT { get; set; } = "";
public static bool IsDevMode { get; set; } = false;
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
@ -9,19 +9,43 @@
<ItemGroup>
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="11.3.0" />
<PackageReference Include="Magick.NET.Core" Version="11.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.16" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="ZXing.Net" Version="0.16.8" />
<FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup>
<ItemGroup>
<Reference Include="CVRLIB">
<HintPath>..\..\VB.NET\CVRLIB\CVRLIB\bin\Release\netstandard2.0\CVRLIB.dll</HintPath>
</Reference>
<Reference Include="CVRLIB-NF">
<HintPath>..\..\VB.NET\CVRLIB-NF\CVRLIB-NF\bin\Release\CVRLIB-NF.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition=" '$(Configuration)'=='Debug' ">
<ItemGroup>
<Reference Include="CVRLIB">
<HintPath>..\..\VB.NET\CVRLIB\CVRLIB\bin\Debug\netstandard2.0\CVRLIB.dll</HintPath>
</Reference>
<Reference Include="CVRLIB-NF">
<HintPath>..\..\VB.NET\CVRLIB-NF\CVRLIB-NF\bin\Debug\CVRLIB-NF.dll</HintPath>
</Reference>
<Reference Include="HtmlFactory">
<HintPath>..\HtmlFactory\HtmlFactory\bin\Debug\netstandard2.0\HtmlFactory.dll</HintPath>
</Reference>
</ItemGroup>
</When>
<When Condition=" '$(Configuration)'=='Release' ">
<ItemGroup>
<Reference Include="CVRLIB">
<HintPath>..\..\VB.NET\CVRLIB\CVRLIB\bin\Release\netstandard2.0\CVRLIB.dll</HintPath>
</Reference>
<Reference Include="CVRLIB-NF">
<HintPath>..\..\VB.NET\CVRLIB-NF\CVRLIB-NF\bin\Release\CVRLIB-NF.dll</HintPath>
</Reference>
<Reference Include="HtmlFactory">
<HintPath>..\HtmlFactory\HtmlFactory\bin\Release\netstandard2.0\HtmlFactory.dll</HintPath>
</Reference>
</ItemGroup>
</When>
</Choose>
</Project>