140 lines
4.9 KiB
C#
140 lines
4.9 KiB
C#
using Lux.Core.RestPayload;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Diagnostics;
|
|
|
|
namespace Lux.API.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class JwdController : ControllerBase
|
|
{
|
|
#region Public Constructors
|
|
|
|
public JwdController(ILogger<JwdController> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Chiamata POST: riceve Json in formato JwdDto, restituisce jpeg file
|
|
/// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000
|
|
/// </summary>
|
|
/// <param name="id">token comunicazione</param>
|
|
/// <returns></returns>
|
|
[HttpPost("jpegfile/{id}")]
|
|
public async Task<IActionResult> jpegFile(string id, [FromBody] Lux.Core.RestPayload.JwdDTO currJwd)
|
|
{
|
|
// finta attesa/elaborazione
|
|
await Task.Delay(waitDelay);
|
|
// path immagine finto...
|
|
string fakeImagePath = "DemoImg/Window01.jpg";
|
|
var imageBytes = await System.IO.File.ReadAllBytesAsync(fakeImagePath);
|
|
return File(imageBytes, "image/jpeg");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata POST: riceve Json in formato JwdDto, restituisce png file
|
|
/// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000
|
|
/// </summary>
|
|
/// <param name="id">token comunicazione</param>
|
|
/// <returns></returns>
|
|
[HttpPost("pngfile/{id}")]
|
|
public async Task<IActionResult> pngFile(string id, [FromBody] Core.RestPayload.JwdDTO currJwd)
|
|
{
|
|
// finta attesa/elaborazione
|
|
await Task.Delay(waitDelay);
|
|
// path immagine finto...
|
|
string fakeImagePath = "DemoImg/Window01.png";
|
|
var imageBytes = await System.IO.File.ReadAllBytesAsync(fakeImagePath);
|
|
return File(imageBytes, "image/png");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata POST: riceve Json in formato JwdDto, restituisce svg file
|
|
/// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000
|
|
/// </summary>
|
|
/// <param name="id">token comunicazione</param>
|
|
/// <returns></returns>
|
|
[HttpPost("svgfile/{id}")]
|
|
public async Task<IActionResult> svgFile(string id, [FromBody] Core.RestPayload.JwdDTO currJwd)
|
|
{
|
|
// finta attesa/elaborazione
|
|
await Task.Delay(waitDelay);
|
|
// path immagine finto...
|
|
string fakeImagePath = "DemoImg/Window01.svg";
|
|
var svgContent = await System.IO.File.ReadAllTextAsync(fakeImagePath);
|
|
var bytes = System.Text.Encoding.UTF8.GetBytes(svgContent);
|
|
return File(bytes, "image/svg+xml");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata POST: riceve Json in formato JwdDto, restituisce svg come string
|
|
/// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000
|
|
/// </summary>
|
|
/// <param name="id">token comunicazione</param>
|
|
/// <returns></returns>
|
|
[HttpPost("svg/{id}")]
|
|
public async Task<ActionResult<string>> svgString(string id, [FromBody] Core.RestPayload.JwdDTO currJwd)
|
|
{
|
|
// finta attesa/elaborazione
|
|
await Task.Delay(waitDelay);
|
|
// path immagine finto...
|
|
string fakeImagePath = "DemoImg/Window01.svg";
|
|
var svgContent = await System.IO.File.ReadAllTextAsync(fakeImagePath);
|
|
return Ok(svgContent);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiamata POST: riceve Json in formato JwdDto, restituisce una BOM completa
|
|
/// PUT: api/Jwd/svg/00000000-0000-0000-0000-000000000000
|
|
/// </summary>
|
|
/// <param name="id">token comunicazione</param>
|
|
/// <returns></returns>
|
|
[HttpPost("bom/{id}")]
|
|
public async Task<ActionResult<BomDTO>> ProductionBOM(string id, [FromBody] Core.RestPayload.JwdDTO currJwd)
|
|
{
|
|
// finta attesa/elaborazione
|
|
await Task.Delay(waitDelay);
|
|
// path immagine finto...
|
|
List<BomRowDTO> listItems = new List<BomRowDTO>();
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
BomRowDTO item = new BomRowDTO()
|
|
{
|
|
BR_UID = $"ABC_{i:000}",
|
|
index = i,
|
|
ItemID = $"ART-{i:00000}",
|
|
Name = $"Finestra {i}",
|
|
PriceUM = 320,
|
|
Qty = 2
|
|
};
|
|
listItems.Add(item);
|
|
}
|
|
|
|
|
|
BomDTO answ = new BomDTO()
|
|
{
|
|
UID = $"{DateTime.Now:yyyyMMdd-HHmmss}",
|
|
Customer = "Demo Customer",
|
|
ItemList = listItems
|
|
};
|
|
|
|
return Ok(answ);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly ILogger<JwdController> _logger;
|
|
private int waitDelay = 250;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |