From 49cfe5dc89fe1fd55d075e665e1247cecd66963e Mon Sep 17 00:00:00 2001 From: Marco Audiffredi Date: Wed, 15 Oct 2025 12:14:43 +0200 Subject: [PATCH] refactor commesse --- Controllers/CommesseVTController.cs | 40 ++++++- Models/CommesseVT_Table.cs | 1 + Views/CommesseVT/Create.cshtml | 73 ++++++++++-- Views/CommesseVT/Delete.cshtml | 102 ++++++++++------- Views/CommesseVT/Edit.cshtml | 166 +++++++++++++++++----------- 5 files changed, 264 insertions(+), 118 deletions(-) diff --git a/Controllers/CommesseVTController.cs b/Controllers/CommesseVTController.cs index d10170c..7f9b783 100644 --- a/Controllers/CommesseVTController.cs +++ b/Controllers/CommesseVTController.cs @@ -233,7 +233,7 @@ namespace VirtualTask.Controllers return RedirectToAction("Error"); } - ViewBag.Impianti = getImpianti(); + ViewBag.Impianti = getImpiantiCliente(commessa.lacodcli); ViewBag.Anag = getClienti(); return View(commessa); } @@ -352,7 +352,45 @@ namespace VirtualTask.Controllers #endregion DELETE #region METODI INTERNI + private List getImpiantiCliente(string codCli) + { + SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + //apiUrl = helper.GetStringValue("") + urlBase = apiUrl + "impiantiListMngr"; + urlBase = urlBase + "?token=" + token; + 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); + modelList = modelList.Where(x => x.imfinatt == null && x.imultcli !=null && x.imultcli.Equals(codCli)).ToList(); + //per gestire primo elemento tendina (deve essere vuoto) + SelectListItem listItemFirst = new SelectListItem(); + + listItemFirst.Value = string.Empty; + listItemFirst.Text = " - Impianto"; + selectItems.Add(listItemFirst); + + foreach (var item in modelList) + { + SelectListItem listItem = new SelectListItem(); + string s = item.imcodimp + " - " + item.imdescri; + listItem.Value = item.imcodimp; + listItem.Text = s; + selectItems.Add(listItem); + } + } + + return selectItems; + } private List getImpianti() { SessionHelper helper = new SessionHelper(this); diff --git a/Models/CommesseVT_Table.cs b/Models/CommesseVT_Table.cs index 9890961..0513e71 100644 --- a/Models/CommesseVT_Table.cs +++ b/Models/CommesseVT_Table.cs @@ -9,6 +9,7 @@ namespace VirtualTask.Models [Display(Name = "Seriale commessa")] public string? laserial { get; set; } + [Display(Name = "Azienda")] public string? lacodazi { get; set; } [Required] diff --git a/Views/CommesseVT/Create.cshtml b/Views/CommesseVT/Create.cshtml index 521016f..98b0160 100644 --- a/Views/CommesseVT/Create.cshtml +++ b/Views/CommesseVT/Create.cshtml @@ -7,16 +7,71 @@
-
+
+
+ @Html.HiddenFor(x => x.laserial) + @Html.HiddenFor(x => x.lacodazi) + @Html.HiddenFor(x => x.ladatchi) + @Html.HiddenFor(x => x.latipcli) + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
  
+ + +
+ + +
+ @Html.DropDownListFor(x => x.lacodcli, (IEnumerable)ViewBag.Anag, "- Seleziona un cliente", new { @id = "ddlClienti", @class = "agy-form-field require" }) + +
+
+ @Html.DropDownListFor(x => x.lacodimp, new List(), "- Seleziona un impianto", new { @id = "ddlImpianti", @class = "agy-form-field require" }) +
+ +
+ + Torna alla lista +
+
+
+ + + + +@*
- @Html.HiddenFor(x => x.laserial) - @Html.HiddenFor(x => x.lacodazi) - @Html.HiddenFor(x => x.ladatchi) - @Html.HiddenFor(x => x.latipcli) +
@@ -31,14 +86,14 @@
 
-@* @Html.DropDownListFor(x => x.lacodcli,(IEnumerable)ViewBag.Anag, new{@class = "form-control"})*@ +
@Html.DropDownListFor(x => x.lacodcli, (IEnumerable)ViewBag.Anag, "- Seleziona un cliente", new { @id = "ddlClienti", @class = "agy-form-field require" })
 
-@* @Html.DropDownListFor(x => x.lacodimp,(IEnumerable)ViewBag.Impianti, new{@class = "form-control"})*@ +
@Html.DropDownListFor(x => x.lacodimp, new List(), "- Seleziona un impianto", new { @id = "ddlImpianti", @class = "agy-form-field require" }) @@ -55,7 +110,7 @@
- @* Torna alla lista *@ +
@section Scripts { @@ -64,7 +119,7 @@ } } -
+
*@

diff --git a/Views/CommesseVT/Delete.cshtml b/Views/CommesseVT/Delete.cshtml index f77dcf6..d1e677a 100644 --- a/Views/CommesseVT/Delete.cshtml +++ b/Views/CommesseVT/Delete.cshtml @@ -8,47 +8,67 @@
-
- -
- @Html.HiddenFor(model => model.ladatchi) - @Html.HiddenFor(model => model.lacodazi) - @Html.HiddenFor(model => model.laserial) - @Html.HiddenFor(model => model.lacodcom) - @Html.HiddenFor(model => model.lacodimp) - @Html.HiddenFor(model => model.ladeslav) - @Html.HiddenFor(model => model.latipcli) - @Html.HiddenFor(model => model.lacodcli) -
- @Html.DisplayNameFor(model => model.laserial)   @Html.DisplayFor(model => model.laserial) -
-
- @Html.DisplayNameFor(model => model.lacodazi)   @Html.DisplayFor(model => model.lacodazi) -
-
- @Html.DisplayNameFor(model => model.lacodcom)   @Html.DisplayFor(model => model.lacodcom) -
-
- @Html.DisplayNameFor(model => model.ladeslav)   @Html.DisplayFor(model => model.ladeslav) -
- - - -
- @Html.DisplayNameFor(model => model.latipcli)   @Html.DisplayFor(model => model.latipcli) -
-
- @Html.DisplayNameFor(model => model.lacodcli)   @Html.DisplayFor(model => model.lacodcli) -
-
- @Html.DisplayNameFor(model => model.lacodimp)   @Html.DisplayFor(model => model.lacodimp) -
- -
-
 
- - Torna alla lista + + @Html.HiddenFor(model => model.ladatchi) + @Html.HiddenFor(model => model.lacodazi) + @Html.HiddenFor(model => model.laserial) + @Html.HiddenFor(model => model.lacodcom) + @Html.HiddenFor(model => model.lacodimp) + @Html.HiddenFor(model => model.ladeslav) + @Html.HiddenFor(model => model.latipcli) + @Html.HiddenFor(model => model.lacodcli) +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  
+ @Html.DisplayFor(x => x.laserial) +
+ @Html.DisplayFor(x => x.lacodazi) +
+ @Html.DisplayFor(x => x.lacodcom) +
+ @Html.DisplayFor(x => x.ladeslav) +
+ @Html.DisplayFor(x => x.lacodcli) +
+ @Html.DisplayFor(x => x.lacodimp) +
+ + Torna alla lista +
+
-
\ No newline at end of file diff --git a/Views/CommesseVT/Edit.cshtml b/Views/CommesseVT/Edit.cshtml index c7f064d..73fa917 100644 --- a/Views/CommesseVT/Edit.cshtml +++ b/Views/CommesseVT/Edit.cshtml @@ -8,81 +8,113 @@
-
-
-
-
-
- -
-
- @* *@ + +
+ @Html.HiddenFor(x => x.ladatchi) + @Html.HiddenFor(x => x.latipcli) +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  
@Html.HiddenFor(x => x.laserial) @Html.DisplayFor(x => x.laserial) - -
 
- @Html.HiddenFor(x => x.lacodazi) - @Html.DisplayFor(x => x.lacodazi) - @*
- - - -
*@ -
-
- +
+ @Html.HiddenFor(x => x.lacodcom) + @Html.DisplayFor(x => x.lacodcom) - -
 
-
-
- +
+ - -
 
- @Html.HiddenFor(x => x.ladatchi) - @*
- - - -
*@ - @Html.HiddenFor(x => x.latipcli) - @*
- - - -
*@ -
-
- @Html.DropDownListFor(x => x.lacodcli, (IEnumerable)ViewBag.Anag, new { @class = "agy-form-field require" }) - @* *@ +
+ @Html.DropDownListFor(x => x.lacodcli, (IEnumerable)ViewBag.Anag, "- Seleziona un cliente", new { @id = "ddlClienti", @class = "agy-form-field require" }) - -
 
-
-
- @Html.DropDownListFor(x => x.lacodimp, (IEnumerable)ViewBag.Impianti, new { @class = "agy-form-field require" }) - @* *@ +
+
+ @Html.DropDownListFor(x => x.lacodimp, (IEnumerable)ViewBag.Impianti, "- Seleziona un impianto", new { @id = "ddlImpianti", @class = "agy-form-field require" }) +
- -
 
-
+
+ @Html.HiddenFor(x => x.lacodazi) + @Html.DisplayFor(x => x.lacodazi) + +
Torna alla lista - - - +
- -
- @* Torna alla lista *@ -
- @section Scripts { - @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); - } - } -
+
-
\ No newline at end of file +
+@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } +} + + + \ No newline at end of file