From 6ddc1948b62b61328592f6699a4aa528898fbf07 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Sat, 9 Nov 2019 10:08:22 +0100 Subject: [PATCH] Aggiunto metodo POST x salvare i dati sul controller --- NKC_WF/Controllers/BunkController.cs | 47 +++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/NKC_WF/Controllers/BunkController.cs b/NKC_WF/Controllers/BunkController.cs index 4a3a9f8..727931e 100644 --- a/NKC_WF/Controllers/BunkController.cs +++ b/NKC_WF/Controllers/BunkController.cs @@ -1,5 +1,8 @@ using AppData; +using Newtonsoft.Json; using NKC_SDK; +using System; +using System.IO; using System.Web.Http; namespace NKC_WF.Controllers @@ -30,7 +33,7 @@ namespace NKC_WF.Controllers /// /// /// - // GET: api/GetNext/5 + // GET: api/Bunk/2?showNext=true [HttpGet] public ProdBunk Get(int id, bool showNext) { @@ -93,6 +96,48 @@ namespace NKC_WF.Controllers ComLib.resetRedisBunkData(); } + /// + /// Processa una chiamata POST per l'invio di un SET di file "a nome" di un IOB, formato MapoSDK.fileEmbed + /// PUT: api/bunk/updateBunk/2 + /// + /// ID dell'IOB + /// + // POST: api/Bunk + [HttpPost] + public string Post() + { + string answ = ""; + // questa classe è derivata da Controller.Response... x cui recupero lo stream in altro modo... + string content = ""; + System.Web.HttpContext.Current.Request.InputStream.Position = 0; + using (var reader = new StreamReader(System.Web.HttpContext.Current.Request.InputStream, System.Text.Encoding.UTF8, true, 4096, true)) + { + content = reader.ReadToEnd(); + } + //Rest + System.Web.HttpContext.Current.Request.InputStream.Position = 0; + // procedo a deserializzare in blocco l'oggetto... + try + { + // deserializzo. + ProdBunk currBunk = JsonConvert.DeserializeObject(content); + // se non nullo... + if (currBunk != null) + { + foreach (var item in currBunk.SheetList) + { + DataLayer.man.taSHL.updateDate(item.SheetId, item.Printing.DtStart, item.Printing.DtEnd, item.Machining.DtStart, item.Machining.DtEnd, item.Unloading.DtStart, item.Unloading.DtEnd); + } + } + answ = "OK"; + } + catch (Exception exc) + { + answ = "NO"; + } + return answ; + } + #if false // POST: api/Bunk [HttpPost]