Added web order hard copy save to local hdd
from external server.
This commit is contained in:
parent
ecb0873f7f
commit
8181f31d27
@ -1,73 +1,164 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using System.Web;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
|
||||||
using CVRLIB.CARTS;
|
using CVRLIB.CARTS;
|
||||||
using static CVRLIB.CVSTRINGS.TextFuncs;
|
using static CVRLIB.CVSTRINGS.TextFuncs;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using CVRLIB;
|
using CVRLIB;
|
||||||
|
using CVRLIB.Generic;
|
||||||
|
|
||||||
namespace VSERVERWS.Controllers {
|
|
||||||
|
|
||||||
//https://vserverws.cvr.cvrco.ca/api/cart/CartStatus
|
using ZXing;
|
||||||
|
using Newtonsoft.Json;
|
||||||
[Route("api/Cart/[action]")]
|
|
||||||
[ApiController]
|
|
||||||
public class CartController : ControllerBase {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[HttpGet]
|
namespace VSERVERWS.Controllers;
|
||||||
public IActionResult CartStatus() {
|
|
||||||
|
|
||||||
var rOBJ = new { STATUS = "OK" };
|
|
||||||
|
|
||||||
return new JsonResult(rOBJ);
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//https://localhost:7210/api/Cart/SubmitCartHTML?id=1337&source=beta%2Ecvr%2Ecvrco%2Eca
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Consumes("text/plain")]
|
||||||
|
public async Task<IActionResult> SubmitCartHTML(string id, string source) {
|
||||||
|
|
||||||
|
var rTOR = new TryOperationResult();
|
||||||
|
|
||||||
|
var isEncrypted = false;
|
||||||
|
var tdata = "";
|
||||||
|
var data = "";
|
||||||
|
|
||||||
|
var HTML_PATH = Program.XDRIVE + "\\CVRCO\\BU\\Carts\\HTML";
|
||||||
|
|
||||||
|
var inSource = HttpUtility.UrlDecode(source);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(inSource)) {
|
||||||
|
HTML_PATH = HTML_PATH + "\\" + inSource;
|
||||||
|
|
||||||
|
if (!Directory.Exists(HTML_PATH)) {
|
||||||
|
Directory.CreateDirectory(HTML_PATH);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
rTOR.AddResult(false, "READ_SOURCE", "no source provided!");
|
||||||
|
|
||||||
|
return new JsonResult(rTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
using (var SR = new StreamReader(Request.Body)) {
|
||||||
|
data = await SR.ReadToEndAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (!Directory.Exists(HTML_PATH)) {
|
||||||
|
Directory.CreateDirectory(HTML_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost]
|
if (!tdata.Contains("<html>")) { isEncrypted = true; }
|
||||||
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 {
|
try {
|
||||||
|
|
||||||
rOBJ.AddResult(false, "CONVERT_TO_JSON", "Failed to convert to json from byte data.");
|
if (isEncrypted) {
|
||||||
|
tdata = NonSecureDecryptHexStringToString(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
|
|
||||||
rOBJ.AddResult(false, "CART_SAVE_TRY", ex.Message, ex);
|
|
||||||
|
|
||||||
|
if (!tdata.Contains("<html>")) {
|
||||||
|
throw new Exception("Invalid html string");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//return new result
|
|
||||||
return new JsonResult(rOBJ);
|
using (var FS = new FileStream(HTML_PATH + "\\" + id + ".txt", FileMode.Create, FileAccess.Write, FileShare.None)) {
|
||||||
|
using (var SW = new StreamWriter(FS)) {
|
||||||
|
|
||||||
|
if (isEncrypted) {
|
||||||
|
await SW.WriteAsync(data);
|
||||||
|
} else {
|
||||||
|
await SW.WriteAsync(NonSecureEncryptStringToHexString(tdata));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
rTOR.AddResult(true, "TRY_SAVE_HTML_CART");
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
|
||||||
|
rTOR.AddResult(false, "TRY_SAVE_HTML_CART", ex.Message, ex);
|
||||||
|
|
||||||
|
Debug.WriteLine(ex.Message);
|
||||||
|
Debug.WriteLine(ex.StackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JsonResult(rTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,7 +97,7 @@ public partial class Program {
|
|||||||
if (Directory.Exists("X:\\Shares\\cvrdata")) {
|
if (Directory.Exists("X:\\Shares\\cvrdata")) {
|
||||||
return "X:\\Shares\\cvrdata";
|
return "X:\\Shares\\cvrdata";
|
||||||
} else {
|
} else {
|
||||||
return "X:\\";
|
return "X:";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user