From 62f27ce021793494d4833d8cdeb5f0f832d96027 Mon Sep 17 00:00:00 2001 From: michele Date: Wed, 4 Sep 2024 09:59:21 +0200 Subject: [PATCH] Michele: Creazione nuove destinazioni --- Controllers/AddDestinazioneController.cs | 115 ++++++++++++++++--- Views/AddDestinazione/AddDestinazione.cshtml | 68 +++++++---- Views/AddDestinazione/Cascading.cshtml | 2 +- 3 files changed, 146 insertions(+), 39 deletions(-) diff --git a/Controllers/AddDestinazioneController.cs b/Controllers/AddDestinazioneController.cs index bdfd5db..0210be3 100644 --- a/Controllers/AddDestinazioneController.cs +++ b/Controllers/AddDestinazioneController.cs @@ -37,13 +37,18 @@ namespace SoftwayWeb.Controllers { return RedirectToAction("Login", "Login"); } - + Modgir model = new Modgir(); + + ViewBag.serialeGiro = serialeGiro; + model.Pisergir = serialeGiro; ViewBag.Commit = getCommittenti(); + ViewBag.CodAutista = getAutisti(); + ViewBag.Mezzi = getMezzi(); - return View(); + return View(model); } - public IActionResult NewDestinazione(Modgir modgir) + public IActionResult NewDestinazione(Modgir modgir, string? autista, string? mezzo, string id) { SessionHelper helper = new SessionHelper(this); @@ -56,17 +61,17 @@ namespace SoftwayWeb.Controllers //qui metodo post per scrivere su pimodgir Modgir mg = new Modgir(); - - mg.Piprogre = modgir.Piprogre; - mg.Piserial = modgir.Piserial; + + //mg.Piprogre = modgir.Piprogre; + mg.Piserial = string.Empty; mg.Pidata = modgir.Pidata; mg.Picommit = modgir.Picommit; mg.Pidesdiv = modgir.Pidesdiv; - mg.Pitarga = modgir.Pitarga; - mg.Piautist = modgir.Piautist; - mg.Pitiprec = "M"; - mg.Pirigele = modgir.Pirigele; - mg.Pisergir = modgir.Pisergir; + mg.Pitarga = mezzo.TrimEnd(); + mg.Piautist = autista.TrimEnd(); + mg.Pitiprec = "A"; + mg.Pirigele = string.Empty; + mg.Pisergir = id; apiUrl = helper.GetStringValue("apiUrl"); @@ -81,7 +86,6 @@ namespace SoftwayWeb.Controllers if (response.IsSuccessStatusCode) { return RedirectToAction("Index","Giri"); - } else { @@ -140,7 +144,90 @@ namespace SoftwayWeb.Controllers return selectItems; } + private List getAutisti() + { + SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + 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(); + + listItemFirt.Value = string.Empty; + listItemFirt.Text = " - Seleziona autista"; + selectItems.Add(listItemFirt); + + foreach (var role in modelList) + { + SelectListItem listItem = new SelectListItem(); + //string s = role.Catcodice + " - " + role.Catnome; + string s = role.Catnome + " - " + role.Catcodice; // 25/07/2024 invertito nome autista con codice autista + listItem.Value = role.Catcodice; + listItem.Text = s; + selectItems.Add(listItem); + } + } + + return selectItems; + } + + private List getMezzi() + { + SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + + 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 = " - Seleziona 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; + + } #endregion METODI INTERNI #region CASCADING @@ -153,7 +240,7 @@ namespace SoftwayWeb.Controllers } [HttpPost] - public ActionResult Cascading(string Picommit/*ancodice*/) + public IActionResult Cascading(string Picommit/*ancodice*/) { SessionHelper helper = new SessionHelper(this); Cascading model = new Cascading(); @@ -201,6 +288,8 @@ namespace SoftwayWeb.Controllers } } return Json(new SelectList(model.SediCons, "Value", "Text")); + + } #endregion CASCADING diff --git a/Views/AddDestinazione/AddDestinazione.cshtml b/Views/AddDestinazione/AddDestinazione.cshtml index 23efbde..8a449f4 100644 --- a/Views/AddDestinazione/AddDestinazione.cshtml +++ b/Views/AddDestinazione/AddDestinazione.cshtml @@ -3,20 +3,26 @@ @{ ViewData["Title"] = "AddDestinazione"; Layout = "~/Views/Shared/_LayoutAreaRis.cshtml"; - @ViewBag.SediCons + List listItems = new List(); + listItems = ViewBag.Commit; + List listItems2 = new List(); + listItems2 = ViewBag.SediCons; + + }

Aggiungi una nuova destinazione

+
Nuova destinazione
- @* @using (Html.BeginForm("AddDestinazione", "AddDestinazione", FormMethod.Post)) - { *@ + @using (Html.BeginForm("NewDestinazione", "AddDestinazione", FormMethod.Post)) + { @*
Seleziona il Committente: @Html.DropDownListFor(x => x.Picommit, (IEnumerable)ViewBag.Commit, new { @id = "ddlCommittenti", @class = "agy-form-field require" }) *@ @* @Html.DropDownList("Committente", ViewBag.Committente, null, new { @class = "agy-form-field require" }) *@ @@ -27,7 +33,7 @@ @*
*@
-
+
@@ -35,39 +41,45 @@ @Html.DropDownListFor(x => x.Picommit, (IEnumerable)ViewBag.Commit, new { @id = "ddlCommittenti", @class = "agy-form-field require" })
-
+
-
+
@Html.DropDownListFor(x => x.Pidesdiv, new List(), "- Seleziona sede", new { @id = "ddlSediCons", @class = "agy-form-field require" })
-
+ @*
-
-
+
*@ + @*
-
+
*@
-
- - - -
- + @* *@ +
+ @Html.DropDownList("autista",ViewBag.CodAutista, null, new { @class = "agy-form-field require" }) +
+ + @* *@ +
+ @Html.DropDownList("mezzo",ViewBag.Mezzi, null, new { @class = "agy-form-field require" }) +
+ +
+ @*
@@ -76,23 +88,29 @@ -
+
*@ @*
- -
@Html.DisplayFor(model => model.Pirigele)
-
*@ -
- +
+ @Html.DisplayFor(x => x.Pisergir) +
-
+
*@
- + @Html.HiddenFor(x => x.Piautist) + @Html.HiddenFor(x => x.Pitarga) + @Html.HiddenFor(x => x.Piprogre) + @Html.HiddenFor(x => x.Piserial) + @Html.HiddenFor(x => x.Pitiprec) + @Html.HiddenFor(x => x.Pisergir) + + Torna alla lista
+
- @* } *@ + }
diff --git a/Views/AddDestinazione/Cascading.cshtml b/Views/AddDestinazione/Cascading.cshtml index 6a23782..f88bd84 100644 --- a/Views/AddDestinazione/Cascading.cshtml +++ b/Views/AddDestinazione/Cascading.cshtml @@ -27,7 +27,7 @@ - @Html.DropDownListFor(x => x.pccodsed, new List(), "--Select--", new {@id = "ddlSediCons"}) + @Html.DropDownListFor(x => x.pccodsed, Model.SediCons/* new List() */, "--Select--", new {@id = "ddlSediCons"})