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

63 lines
1.8 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 RecipeController : ControllerBase
{
/// <summary>
/// Dataservice x accesso DB
/// </summary>
protected MpDataService DService { get; set; }
public RecipeController(IConfiguration configuration, MpDataService DataService)
{
Log.Info("Starting RecipeController");
_configuration = configuration;
DService = DataService;
Log.Info("Avviata classe Recipe");
}
private static IConfiguration _configuration = null!;
private static Logger Log = LogManager.GetCurrentClassLogger();
[HttpGet("GetRecipe")]
public async Task<string> GetRecipe(int idxPODL)
{
string answ = "";
var reqRecipe = await DService.RecipeGetByPODL(idxPODL);
if (reqRecipe != null)
{
answ = DService.CalcRecipe(reqRecipe);
}
return answ;
}
[HttpGet("GetRecipeXML")]
public async Task<string> GetRecipeXML(int idxPODL)
{
string answ = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
// recupero versione json
string rawData = await GetRecipe(idxPODL);
if (!string.IsNullOrEmpty(rawData))
{
// aggiungo root node?
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(rawData);
answ += doc.InnerXml;
}
return answ;
}
}
}