diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index 9bb8d6e2..1a98d457 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -9,6 +9,7 @@ using System.Security.Claims; using System.Threading.Tasks; using System.Web; using System.Web.Http; +using System.Windows.Media.Animation; using Thermo.Active.Config; using Thermo.Active.Database.Controllers; using Thermo.Active.Model.DTOModels.ThRecipe; @@ -456,6 +457,60 @@ namespace Thermo.Active.Controllers.WebApi } + [Route("saveAll"), HttpPost] + public async Task SaveAll(string newName, double estimTimeSec) + { + bool imageUploaded = false; + + if (!Request.Content.IsMimeMultipartContent()) + { + throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); + } + + List formItems = await MultipartHandler.ManageMultiPartFileAsync(Request); + + foreach (FormItem item in formItems) + { + if (item.IsAFile) + { + if (item.ParameterName == "image" || item.MediaType.StartsWith("image/")) + { + string filePath = item.FileName; + imageUploaded = NcFileAdapter.SaveRecipeImage(item.FileName, item.Data); + } + } + } + if (!string.IsNullOrEmpty(newName)) + { + // recupero i dati LIVE dei parametri HMI della ricetta... + CmsError libraryError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"SaveAll error | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + + var currParams = new Dictionary(); + foreach (var item in currRecipe) + { + currParams.Add(item.Key, item.Value.SetpointPLC); + } + // salvo parametri + NcFileAdapter.RecipeLiveData.RecipeParameters = currParams; + + // ora salvo il dato del TC stimato se presente + if (estimTimeSec > 0) + { + NcFileAdapter.RecipeLiveData.TC_last = estimTimeSec; + } + // e salvo su disco + NcFileAdapter.SaveRecipe(newName, NcFileAdapter.RecipeLiveData); + } + + return Ok(); + } + + /// /// Do actual recipe parameters FileSave ///