Files
mapo-core/MP.SPEC/Controllers/RecipeArchiveController.cs
T
Samuele Locatelli cd90e6871f SPEC:
- Completato modifiche x selezione ricetta
- Controller x download ricetta
2023-04-04 16:17:39 +02:00

70 lines
2.2 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using MP.Data.MgModels;
using MP.SPEC.Data;
using Newtonsoft.Json;
using NLog;
using System.Xml;
namespace MP.SPEC.Controllers
{
[Route("api/[controller]")]
[ApiController]
[AllowAnonymous]
public class RecipeArchiveController : ControllerBase
{
/// <summary>
/// Dataservice x accesso DB
/// </summary>
protected MpDataService DService { get; set; }
public RecipeArchiveController(IConfiguration configuration, MpDataService DataService)
{
Log.Info("Starting RecipeArchiveController");
_configuration = configuration;
DService = DataService;
Log.Info("Avviata classe RecipeArchiveController");
}
private static IConfiguration _configuration = null!;
private static Logger Log = LogManager.GetCurrentClassLogger();
[HttpGet("GetFile")]
public async Task<string> GetFile(string idxMacc, string fileName)
{
string answ = "";
string archPath = await DService.MacchineRecipeArchive(idxMacc);
if (!string.IsNullOrEmpty(archPath))
{
string fullPath = Path.Combine(archPath, fileName);
if (!string.IsNullOrEmpty(fullPath))
{
answ = System.IO.File.ReadAllText(fullPath);
}
}
return answ;
}
[HttpGet("GetByPODL")]
public async Task<string> GetByPODL(string idxMacc, int idxPODL)
{
string answ = "";
string archPath = await DService.MacchineRecipeArchive(idxMacc);
var podlData = await DService.POdlGetByKey(idxPODL);
if (podlData != null)
{
string fileName = podlData?.Recipe ?? "";
string fullPath = Path.Combine(archPath, fileName);
if (!string.IsNullOrEmpty(fullPath))
{
answ = System.IO.File.ReadAllText(fullPath);
}
}
return answ;
}
}
}