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] public class RecipeController : ControllerBase { /// /// Dataservice x accesso DB /// protected MpDataService DService { get; set; } public RecipeController(IConfiguration configuration, MpDataService DataService) { Log.Info("Starting MpDataService INIT"); _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 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 GetRecipeXML(int idxPODL) { string answ = ""; // 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; } } }