From 605f92572538c1b501da9f3a6862e6b4281f1b58 Mon Sep 17 00:00:00 2001 From: Marco Audiffredi Date: Tue, 16 Jul 2024 15:41:25 +0200 Subject: [PATCH] modifica destinazione --- Controllers/DestinazioniController.cs | 153 +++++++++++++++++- .../Destinazioni/ModificaDestinazione.cshtml | 15 +- 2 files changed, 155 insertions(+), 13 deletions(-) diff --git a/Controllers/DestinazioniController.cs b/Controllers/DestinazioniController.cs index af01845..99b4c24 100644 --- a/Controllers/DestinazioniController.cs +++ b/Controllers/DestinazioniController.cs @@ -1,7 +1,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; using Newtonsoft.Json; using SoftwayWeb.Models; +using System.Collections.Generic; using System.Diagnostics; using System.Text; using X.PagedList; @@ -176,10 +178,10 @@ namespace SoftwayWeb.Controllers }); } - public IActionResult ModificaDestinazione(string serial) { SessionHelper helper = new SessionHelper(this); + apiUrl = helper.GetStringValue("apiUrl"); urlBase = apiUrl + "Giri/listaDestinazioneBySerial"; @@ -195,6 +197,17 @@ namespace SoftwayWeb.Controllers { string dato = response.Content.ReadAsStringAsync().Result; model = JsonConvert.DeserializeObject(dato); + + List < SelectListItem > autisti = new List < SelectListItem>(); + autisti = getAutisti(); + autisti.Find(c => c.Value.Trim().Equals(model.CodAutista)).Selected = true; + ViewBag.Autisti = autisti; + + List mezzi = new List(); + mezzi = getMezzi(); + mezzi.Find(c => c.Value.Equals(model.CodAutomezzo)).Selected = true; + ViewBag.CodMezzo = mezzi; + return View(model); } @@ -205,15 +218,139 @@ namespace SoftwayWeb.Controllers return RedirectToAction("Error"); } - //return RedirectToAction("Index", "Destinazioni", new - //{ - // id = model.serialeGiro, - // codAutista = model.CodAutista, - // dataGiro = model.DataCarico, - // codMezzo = model.CodAutomezzo - //}); } + [HttpPost] + public IActionResult ModificaDestinazionePost(Destinazioni_Out model) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + + //qui metodo post per scrivere su pimodgir + Modgir mg = new Modgir(); + mg.Piserial = model.Brserial; + mg.Pidata = model.DataCarico; + mg.Picommit = model.CodCommittente; + mg.Pidesdiv = model.CodSede; + mg.Pitarga = model.CodAutomezzo; + mg.Piautist = model.CodAutista; + mg.Pitiprec = "M"; + + apiUrl = helper.GetStringValue("apiUrl"); + + urlBase = apiUrl + "ModificaGiro/addModgir"; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + string data = JsonConvert.SerializeObject(mg); + StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response2 = client.PostAsync(baseAddress, content).Result; + if (response2.IsSuccessStatusCode) + { + return RedirectToAction("Index", "Destinazioni", new + { + id = model.serialeGiro, + codAutista = model.CodAutista, + dataGiro = model.DataCarico, + codMezzo = model.CodAutomezzo + }); + } + else + { + errMes = response2.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + + } + private List getAutisti() + { + SessionHelper helper = new SessionHelper(this); + + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "Giri/listaAutisti"; + + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + List selectItems = new List(); + List modelList = new List(); + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + + //per gestire primo elemento tendina (deve essere vuoto) + SelectListItem listItemFirt = new SelectListItem(); + + + + foreach (var role in modelList) + { + SelectListItem listItem = new SelectListItem(); + string s = role.Catcodice + " - " + role.Catnome; + listItem.Value = role.Catcodice; + listItem.Text = s; + selectItems.Add(listItem); + } + } + + return selectItems; + } + + private List getMezzi() + { + SessionHelper helper = new SessionHelper(this); + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "Giri/listaAutomezzi"; + + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + List selectItems = new List(); + List listMezzi = new List(); + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + listMezzi = JsonConvert.DeserializeObject>(data); + + listMezzi = listMezzi.OrderBy(x => x.CauTarga).ToList(); + + //per gestire primo elemento tendina (deve essere vuoto) + SelectListItem listItemFirt = new SelectListItem(); + + listItemFirt.Value = string.Empty; + listItemFirt.Text = " - Automezzo"; + selectItems.Add(listItemFirt); + + foreach (var mezzo in listMezzi) + { + SelectListItem listItem = new SelectListItem(); + List listItemOrderby = new List(); + string s = mezzo.CauTarga + " - " + mezzo.CauDesc; + listItem.Value = mezzo.CauTarga; + listItem.Text = s; + + selectItems.Add(listItem); + } + } + + return selectItems; + + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/Views/Destinazioni/ModificaDestinazione.cshtml b/Views/Destinazioni/ModificaDestinazione.cshtml index baece19..0d9d63c 100644 --- a/Views/Destinazioni/ModificaDestinazione.cshtml +++ b/Views/Destinazioni/ModificaDestinazione.cshtml @@ -2,6 +2,7 @@ @{ ViewData["Title"] = "ModificaDestinazione"; + Layout = "~/Views/Shared/_LayoutAreaRis.cshtml"; }

ModificaDestinazione

@@ -10,16 +11,16 @@
-
+
- @Html.HiddenFor(model => model.CodAutomezzo) + @Html.HiddenFor(model => model.DescAutomezzo) @Html.HiddenFor(model => model.Brserial) @Html.HiddenFor(model => model.DataCarico) @Html.HiddenFor(model => model.CodCommittente) @Html.HiddenFor(model => model.Committente) @Html.HiddenFor(model => model.Autista) - @Html.HiddenFor(model => model.CodAutista) + @Html.HiddenFor(model => model.CodSede) @Html.HiddenFor(model => model.Sede) @Html.HiddenFor(model => model.IndirizzoSede) @@ -39,8 +40,9 @@ @Html.HiddenFor(model => model.Note) @Html.HiddenFor(model => model.Seq) @Html.HiddenFor(model => model.Prog) +
- @Html.DisplayNameFor(model => model.DescAutomezzo) @Html.DisplayFor(model => model.CodAutomezzo)-@Html.DisplayFor(model => model.DescAutomezzo) + @Html.DisplayNameFor(model => model.DescAutomezzo) @Html.DropDownList("CodAutomezzo", ViewBag.CodMezzo, null, new { @class = "agy-form-field require" })
@Html.DisplayNameFor(model => model.DataCarico) @Html.DisplayFor(model => model.DataCarico) @@ -51,6 +53,10 @@
@Html.DisplayNameFor(model => model.Autista) @Html.DisplayFor(model => model.CodAutista)-@Html.DisplayFor(model => model.Autista)
+
+ Nuovo Autista @Html.DropDownList("codAutista", ViewBag.Autisti, null, new { @class = "agy-form-field require" }) +
+
@Html.DisplayNameFor(model => model.Sede) @Html.DisplayFor(model => model.CodSede)-@Html.DisplayFor(model => model.Sede)
@@ -85,7 +91,6 @@ @Html.DisplayNameFor(model => model.Prog) @Html.DisplayFor(model => model.Prog)
-