diff --git a/Controllers/CommesseVTController.cs b/Controllers/CommesseVTController.cs index 92d2a3d..c146795 100644 --- a/Controllers/CommesseVTController.cs +++ b/Controllers/CommesseVTController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc.Rendering; using Newtonsoft.Json; using System.Diagnostics; +using System.Reflection; using System.Text; using VirtualTask.Models; using X.PagedList; @@ -104,7 +105,7 @@ namespace VirtualTask.Controllers ViewBag.Admin = admin; - ViewBag.Impianti = getImpianti(); + //ViewBag.Impianti = getImpianti(); ViewBag.Anag = getClienti(); return View(); } @@ -390,7 +391,28 @@ namespace VirtualTask.Controllers return selectItems; } + private List getImpiantiALL() + { + 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); + } + return modelList; + } private List getClienti() { SessionHelper helper = new SessionHelper(this); @@ -492,33 +514,63 @@ namespace VirtualTask.Controllers return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrMsg = e }); } - //private bool checkAziendaPresente(string azienda) + + + #endregion + + #region CASCADING + + public IActionResult Cascading() + { + Cascading model = new Cascading(); + model.Clienti = getClienti(); + return View(model); + } + + + [HttpPost] + public ActionResult Cascading(string lacodcli) + { + Cascading model = new Cascading(); + model.Clienti = getClienti(); + + if (!string.IsNullOrEmpty(lacodcli)) + { + List impianti = new List(); + impianti = getImpiantiALL(); + var impiaCli = impianti.Where(x => x.imultcli.Equals(lacodcli)).ToList(); + foreach (Impianto i in impiaCli) + { + SelectListItem listItem = new SelectListItem(); + string s = i.imcodimp + " - " + i.imdescri; + listItem.Value = i.imcodimp; + listItem.Text = s; + model.Impianti.Add(listItem); + //model.Impianti.Add(new SelectListItem { Text = i.imcodimp, Value = i.imcodimp }); + + } + } + //string data = JsonConvert.SerializeObject(model.Impianti); + //return Json(data); + return Json(new SelectList(model.Impianti, "Value", "Text")); + } + //[HttpPost] + //public ActionResult GetDistrict(string ancodice) //{ - // bool trovato = false; - // bool bAziPres = false; - - // //urlBase = "http://10.0.0.187:8000/api/Polo/AziendePresentiList"; - // urlBase = apiUrl + "AziendePresentiList"; - // Uri baseAddress = new Uri(urlBase); - // client = new HttpClient(); - // client.BaseAddress = baseAddress; - - // List modelList = new List(); - // HttpResponseMessage response = client.GetAsync(baseAddress).Result; - // if (response.IsSuccessStatusCode) + // int statId; + // List districtNames = new List(); + // if (!string.IsNullOrEmpty(stateId)) // { - // string data = response.Content.ReadAsStringAsync().Result; - // modelList = JsonConvert.DeserializeObject>(data); - // foreach (AziendaPres a in modelList) + // statId = Convert.ToInt32(stateId); + // List districts = schoolEntity.DistrictMasters.Where(x => x.StateId == statId).ToList(); + // districts.ForEach(x => // { - // if (!string.IsNullOrEmpty(a.tccodazi) && a.tccodazi.Trim().Equals(azienda)) - // trovato = true; - // } - // bAziPres = trovato; + // districtNames.Add(new SelectListItem { Text = x.DistrictName, Value = x.DistrictId.ToString() }); + // }); // } - // return bAziPres; + // return Json(districtNames, JsonRequestBehavior.AllowGet); //} + #endregion - #endregion ALTRI METODI } } diff --git a/Models/Cascading.cs b/Models/Cascading.cs new file mode 100644 index 0000000..64a9105 --- /dev/null +++ b/Models/Cascading.cs @@ -0,0 +1,21 @@ +using Microsoft.AspNetCore.Mvc.Rendering; + +namespace VirtualTask.Models +{ + public class Cascading + { + public Cascading() + { + this.Clienti = new List(); + this.Impianti = new List(); + } + + public List Clienti { get; set; } + public List Impianti { get; set; } + + public string? lacodcli { get; set; } + public string? ancodice { get; set; } + public string? imcodimp { get; set; } + + } +} diff --git a/Views/CommesseVT/Cascading.cshtml b/Views/CommesseVT/Cascading.cshtml new file mode 100644 index 0000000..7fa2b66 --- /dev/null +++ b/Views/CommesseVT/Cascading.cshtml @@ -0,0 +1,61 @@ +@model VirtualTask.Models.Cascading + +@{ + Layout = null; +} + + + +

Cascading Dropdownlist

+ + + + + + + + + +
+ + + @Html.DropDownListFor(x => x.ancodice, Model.Clienti, "--Select--", new { @id="ddlClienti"}); +
+ + + @Html.DropDownListFor(x => x.imcodimp, new List(), "--Select--", new { @id="ddlImpianti"}); +
+ + + + diff --git a/Views/CommesseVT/Create.cshtml b/Views/CommesseVT/Create.cshtml index a1c5d70..0a03365 100644 --- a/Views/CommesseVT/Create.cshtml +++ b/Views/CommesseVT/Create.cshtml @@ -29,12 +29,16 @@
 
- @Html.DropDownListFor(x => x.lacodcli,(IEnumerable)ViewBag.Anag, new{@class = "form-control"}) +@* @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 = "form-control"})
 
- @Html.DropDownListFor(x => x.lacodimp,(IEnumerable)ViewBag.Impianti, new{@class = "form-control"}) +@* @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 = "form-control"}) +
 
@@ -59,7 +63,35 @@
+ + @*