Added incoming Cart save functions.
This commit is contained in:
parent
ebf3d3069b
commit
6466d17905
28
AppCode/Formatters/Formatters.cs
Normal file
28
AppCode/Formatters/Formatters.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
73
Controllers/CartController.cs
Normal file
73
Controllers/CartController.cs
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user