From ed7d3b177cf85010fbd2cd028b55bd75bea5793c Mon Sep 17 00:00:00 2001 From: Marco Audiffredi Date: Fri, 15 Dec 2023 17:15:29 +0100 Subject: [PATCH] Dati azienda modifica --- Controllers/ChiamateController.cs | 1 - Controllers/DatiAziendaController.cs | 127 +++++++++++++++++++---- Models/DatiAziendaTable.cs | 4 + Views/Chiamate/Index.cshtml | 4 +- Views/DatiAzienda/Create.cshtml | 3 +- Views/DatiAzienda/Edit.cshtml | 66 ++++++++++++ Views/DatiAzienda/Index.cshtml | 123 +++++++++++++--------- Views/Shared/_LayoutAreaRiservata.cshtml | 4 +- 8 files changed, 256 insertions(+), 76 deletions(-) create mode 100644 Views/DatiAzienda/Edit.cshtml diff --git a/Controllers/ChiamateController.cs b/Controllers/ChiamateController.cs index 6ccaab1..e55bd42 100644 --- a/Controllers/ChiamateController.cs +++ b/Controllers/ChiamateController.cs @@ -294,7 +294,6 @@ namespace VirtualTask.Controllers return RedirectToAction("Error"); } - return View(model); } #endregion EDIT diff --git a/Controllers/DatiAziendaController.cs b/Controllers/DatiAziendaController.cs index 22ac5a5..f4872aa 100644 --- a/Controllers/DatiAziendaController.cs +++ b/Controllers/DatiAziendaController.cs @@ -4,7 +4,9 @@ using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.DotNet.Scaffolding.Shared.CodeModifier.CodeChange; using Microsoft.Extensions.Hosting.Internal; using Newtonsoft.Json; +using System; using System.Diagnostics; +using System.Reflection; using System.Text; using System.Web; using VirtualTask.Models; @@ -64,27 +66,6 @@ namespace VirtualTask.Controllers string data = response.Content.ReadAsStringAsync().Result; modelList = JsonConvert.DeserializeObject>(data); - //if (!string.IsNullOrEmpty(searchString)) - //{ - // modelList = modelList.Where(s => s.andescri.ToUpper().Contains(searchString.ToUpper())).ToList(); - - // ViewData["CurrentFilter"] = searchString; - //} - //else - //{ - // ViewData["CurrentFilter"] = null; - //} - - //if (page != null && page < 1) - //{ - // page = 1; - //} - - //var pageSize = 10; - //var shortLinks = modelList - // .OrderByDescending(s => s.ancodice) - // .ToPagedList(page ?? 1, pageSize); - return View(modelList); } else @@ -174,7 +155,109 @@ namespace VirtualTask.Controllers #endregion CREATE - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + #region EDIT + public IActionResult Edit(string azienda,string tecnico) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + apiUrl = helper.GetStringValue("apiUrl"); + admin = helper.GetStringValue("admin"); + ViewBag.Admin = admin; + urlBase = apiUrl + "datiaziendaList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + DatiAziendaTable dat = new DatiAziendaTable(); + List modelList = new List(); + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + dat = modelList.Where(t => t.azienda.Equals(azienda) && t.tecnico.Equals(tecnico)).First(); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + + + + ViewBag.AllTecnici = getTecnici(); + return View(dat); + } + + [HttpPost] + public IActionResult Edit(DatiAziendaTable model) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + tenant = helper.GetStringValue("tenant"); + tenant2 = helper.GetStringValue("tenant2"); + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login2", "Login"); + } + //model.azienda = tenant; + if(model.logo2!=null) + { + string pic = System.IO.Path.GetFileName(model.logo2.FileName); + string path = string.Format("{0}{1}\\{2}", _pathLoghi, tenant2, pic); + //string projectRootPath = _hostingEnvironment.ContentRootPath; + + //// file is uploaded + using (Stream fileStream = new FileStream(path, FileMode.Create)) + { + model.logo2.CopyToAsync(fileStream); + } + + //// save the image path path to the database or you can send image + //// directly to database + //// in-case if you want to store byte[] ie. for DB + using (MemoryStream ms = new MemoryStream()) + { + model.logo2.CopyTo(ms); + byte[] array = ms.GetBuffer(); + model.logo = array; + } + model.logo2 = null; + } + + + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "datiazienda/mod"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + string data = JsonConvert.SerializeObject(model); + StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = client.PostAsync(baseAddress, content).Result; + + if (response.IsSuccessStatusCode) + { + return RedirectToAction("Index"); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + #endregion + + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { SessionHelper helper = new SessionHelper(this); diff --git a/Models/DatiAziendaTable.cs b/Models/DatiAziendaTable.cs index 8c809d7..8334fa8 100644 --- a/Models/DatiAziendaTable.cs +++ b/Models/DatiAziendaTable.cs @@ -29,5 +29,9 @@ namespace VirtualTask.Models [Display(Name = "Testo Rapportino")] /// testo azienda rapportino public string? testo_buono { get; set; } + + /// logo + public IFormFile? logo2 { get; set; } + } } diff --git a/Views/Chiamate/Index.cshtml b/Views/Chiamate/Index.cshtml index 78edaeb..15fc27c 100644 --- a/Views/Chiamate/Index.cshtml +++ b/Views/Chiamate/Index.cshtml @@ -96,11 +96,11 @@ Modifica | - + Dettaglio | - + Elimina diff --git a/Views/DatiAzienda/Create.cshtml b/Views/DatiAzienda/Create.cshtml index e5691de..f4023a4 100644 --- a/Views/DatiAzienda/Create.cshtml +++ b/Views/DatiAzienda/Create.cshtml @@ -1,7 +1,8 @@ @model VirtualTask.Models.DatiAzienda @{ - ViewData["Title"] = "Create"; + ViewData["Title"] = "Nuovo"; + Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml"; }

Create

diff --git a/Views/DatiAzienda/Edit.cshtml b/Views/DatiAzienda/Edit.cshtml new file mode 100644 index 0000000..1264339 --- /dev/null +++ b/Views/DatiAzienda/Edit.cshtml @@ -0,0 +1,66 @@ +@model VirtualTask.Models.DatiAziendaTable + +@{ + ViewData["Title"] = "Edit"; + Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml"; +} + +
+
+
+
+
+
+
+ @Html.HiddenFor(x => x.azienda) + @Html.HiddenFor(x => x.url_logo) + @Html.HiddenFor(x => x.logo) + +
+ + @Html.DropDownListFor(x => x.tecnico,(IEnumerable)ViewBag.AllTecnici, new {@class = "form-control"}) + +
+
+ + + +
+
+ + @{ + byte[] appo = Model.logo; + var base64 = Convert.ToBase64String(appo); + var imgSrc = String.Format("data:image/gif;base64,{0}", base64); + } + + + +
+
+ + + +
+
+ +
+
+
+
+
+ +
+
+ + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} + +} diff --git a/Views/DatiAzienda/Index.cshtml b/Views/DatiAzienda/Index.cshtml index bd8423c..e2ef06e 100644 --- a/Views/DatiAzienda/Index.cshtml +++ b/Views/DatiAzienda/Index.cshtml @@ -1,61 +1,88 @@ @model IEnumerable @{ - ViewData["Title"] = "Index"; + ViewData["Title"] = "Dati Azienda"; + Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml"; } -

Index

+

Create New

- - - +
+
+
+
+ + - - + + - - - - - - -@foreach (var item in Model) { - + + - + + + + + + @foreach (var item in Model) { + - - - - -} - -
- @Html.DisplayNameFor(model => model.tecnico) - - @Html.DisplayNameFor(model => model.ragsoc) - + @Html.DisplayNameFor(model => model.tecnico) + + @Html.DisplayNameFor(model => model.ragsoc) + - @Html.DisplayNameFor(model => model.logo) - - @Html.DisplayNameFor(model => model.testo_buono) -
+ @Html.DisplayNameFor(model => model.logo) + + @Html.DisplayNameFor(model => model.testo_buono) - - @Html.DisplayFor(modelItem => item.tecnico) - - @Html.DisplayFor(modelItem => item.ragsoc) -
- @{ - var base64 = Convert.ToBase64String(item.logo); - var imgSrc = String.Format("data:image/gif;base64,{0}", base64); - } - - - @Html.DisplayFor(modelItem => item.testo_buono) - - @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | - @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | - @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) -
+ + @Html.DisplayFor(modelItem => item.tecnico) + + + @Html.DisplayFor(modelItem => item.ragsoc) + + + + @{ + var base64 = Convert.ToBase64String(item.logo); + var imgSrc = String.Format("data:image/gif;base64,{0}", base64); + } + + + + @{ + string testo = string.Empty; + testo = item.testo_buono; + } + @Html.Raw(@testo) + + + +@* @Html.ActionLink("Edit", "Edit", new { azienda=item.azienda,tecnico=item.tecnico }) | + @Html.ActionLink("Details", "Details", new { azienda=item.azienda,tecnico=item.tecnico }) | + @Html.ActionLink("Delete", "Delete", new { azienda=item.azienda,tecnico=item.tecnico })*@ + + + Modifica + + | + + | + + + + + + } + + + + + \ No newline at end of file diff --git a/Views/Shared/_LayoutAreaRiservata.cshtml b/Views/Shared/_LayoutAreaRiservata.cshtml index dba691f..f5d0b8c 100644 --- a/Views/Shared/_LayoutAreaRiservata.cshtml +++ b/Views/Shared/_LayoutAreaRiservata.cshtml @@ -157,8 +157,8 @@ Purchase:
  • Buono intervento
  • Chiamate
  • Progressivi
  • -
  • Dati Azienda
  • -
  • Dati Azienda2
  • + @*
  • Dati Azienda
  • *@ +
  • Dati Azienda
  • Commesse
  • Logout