Added saveAll method for recipe
This commit is contained in:
@@ -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<IHttpActionResult> SaveAll(string newName, double estimTimeSec)
|
||||
{
|
||||
bool imageUploaded = false;
|
||||
|
||||
if (!Request.Content.IsMimeMultipartContent())
|
||||
{
|
||||
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
|
||||
}
|
||||
|
||||
List<FormItem> 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<string, DTORecipeParam> currRecipe);
|
||||
if (libraryError.IsError())
|
||||
{
|
||||
ThermoActiveLogger.LogError($"SaveAll error | {libraryError.exception}");
|
||||
return BadRequest(libraryError.localizationKey);
|
||||
}
|
||||
|
||||
var currParams = new Dictionary<string, double>();
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Do actual recipe parameters FileSave
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user