From 2e379fcb81194bdb5cd77a40ff222102ae7ecc7a Mon Sep 17 00:00:00 2001 From: Marco Audiffredi Date: Fri, 2 Aug 2024 12:14:20 +0200 Subject: [PATCH] Giri eda creare filtro --- Controllers/GiriDaValidareController.cs | 142 ++++++++++++++++++++++++ Views/Giri/Index.cshtml | 14 ++- Views/GiriDaValidare/Index.cshtml | 98 ++++++++++++++++ 3 files changed, 248 insertions(+), 6 deletions(-) create mode 100644 Controllers/GiriDaValidareController.cs create mode 100644 Views/GiriDaValidare/Index.cshtml diff --git a/Controllers/GiriDaValidareController.cs b/Controllers/GiriDaValidareController.cs new file mode 100644 index 0000000..cabe568 --- /dev/null +++ b/Controllers/GiriDaValidareController.cs @@ -0,0 +1,142 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using NuGet.Common; +using SoftwayWeb.Models; +using System.Diagnostics; +using System.Text; + +namespace SoftwayWeb.Controllers +{ + public class GiriDaValidareController : Controller + { + string apiUrl = string.Empty; + string urlBase = string.Empty; + string token = string.Empty; + string errMes = string.Empty; + private readonly IConfiguration _configuration; + HttpClient client; + public GiriDaValidareController(IConfiguration configuration) + { + client = new HttpClient(); + _configuration = configuration; + var key = _configuration["ApplicationInsights:rootUrlApi"]; + apiUrl = key; + } + public IActionResult Index(DateTime data, bool sel,bool clear) + { + //se la data non è valorizzata, prendo i giri inseriti per ultimi, altrimenti li cerco per data + List modelList = new List(); + SessionHelper helper = new SessionHelper(this); + if(clear) + { + helper.SetStringValue("filterData", string.Empty); + } + + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + + + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "Giri/listaGiriDaCreare"; + + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + if (response.IsSuccessStatusCode) + { + string result = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(result); + } + + + string _filtro= helper.GetStringValue("filterData"); + if (data == DateTime.MinValue && string.IsNullOrEmpty(_filtro)) + { + var last = modelList.OrderByDescending(t => t.DataGiro).Take(1).First(); + modelList = modelList.Where(x => x.DataGiro == last.DataGiro).ToList(); + } + if (data == DateTime.MinValue && !string.IsNullOrEmpty(_filtro)) + { + DateTime dataFiltro=Convert.ToDateTime(_filtro); + ViewBag.Filtro = Convert.ToString(_filtro); + modelList = modelList.Where(x => x.DataGiro == dataFiltro).ToList(); + } + + if (data != DateTime.MinValue ) + { + helper.SetStringValue("filterData", Convert.ToString( data)); + ViewBag.Filtro = data.ToString("dd/MM/yyyy"); + modelList = modelList.Where(x => x.DataGiro==data).ToList(); + } + + foreach (GiriConsegnaDaCreare giro in modelList) + { + giro.IsSelected = sel; + } + + return View(modelList); + } + + [HttpPost] + public IActionResult PostIndex(IList lst) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + + foreach (GiriConsegnaDaCreare g in lst) + { + if (g.IsSelected == true) + { + //ViewBag.Autisti = getAutisti(); + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "Giri/addGiro2"; + + GiriConsegnaView gcv = new GiriConsegnaView(); + gcv.CodAutista = g.CodAutista; + gcv.DataGiro = g.DataGiro; + gcv.CodMezzo = g.CodMezzo; + gcv.DataChiusura = DateTime.MinValue; + + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + string data = JsonConvert.SerializeObject(gcv); + StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = client.PostAsync(baseAddress, content).Result; + if (response.IsSuccessStatusCode) + { + + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + } + return RedirectToAction("Index", "Giri"); + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + SessionHelper helper = new SessionHelper(this); + string e = helper.GetStringValue("errMsg"); + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrMsg = e }); + } + } +} diff --git a/Views/Giri/Index.cshtml b/Views/Giri/Index.cshtml index c7d2a72..d11e2a3 100644 --- a/Views/Giri/Index.cshtml +++ b/Views/Giri/Index.cshtml @@ -12,12 +12,14 @@ - -

- Elenco giri di consegna da validare + Elenco giri di consegna da validare

+@*

+ Elenco giri di consegna da validare +

*@ + @using (Html.BeginForm()) {
@@ -80,10 +82,10 @@ @foreach (var item in Model) { - int totBancaliCaricati = 0; + string totBancaliCaricati = "-"; if (item.BancaliCaricati!=null) { - totBancaliCaricati = item.BancaliCaricati.Value; + totBancaliCaricati = Convert.ToString(item.BancaliCaricati.Value); } @Html.DisplayFor(modelItem => item.DataGiro) @@ -147,7 +149,7 @@ Bancali Bancali caricati /parziale bancali caricati /parziale bancali scaricati / nocons - Bancali non caricati + Giro NON visibile su app (caricare i bancali iniziali) diff --git a/Views/GiriDaValidare/Index.cshtml b/Views/GiriDaValidare/Index.cshtml new file mode 100644 index 0000000..e35f283 --- /dev/null +++ b/Views/GiriDaValidare/Index.cshtml @@ -0,0 +1,98 @@ +@model List +@{ + Layout = "~/Views/Shared/_LayoutAreaRis.cshtml"; + List lst = new List(); + lst = Model; + string lbl = string.Empty; + string filt = ViewBag.Filtro; + if(string.IsNullOrEmpty(filt)) + { + lbl = "Nessun filtro impostato"; + } + else + { + lbl = "Filtro:" +filt; + } +} +@using (Html.BeginForm()) +{ +
+
Ricerca
+
+ + + + + + + + + + + + + + + + + +
Data giro   
@Html.TextBox("data", null, new { type = "date", @class = "agy-form-field require" })@lbl +   + @Html.ActionLink("Annulla filtro", "Index", "GiriDaValidare",new { clear = true }, new { @class = "btn btn-primary" }) +  
+
+
+} +
+
+
+
Giri da validare
+
+
+ + + + + + + + + + + + @for (var i = 0; i < lst.Count(); i++) + { + + + + + + + + } + +
 DataAutistaAutomezzo 
+ @Html.CheckBoxFor(a=>lst[i].IsSelected) + + @Html.DisplayFor(a=>lst[i].DataGiro) + @Html.HiddenFor(a=>lst[i].DataGiro) + + @Html.DisplayFor(a=>lst[i].CodAutista)-@Html.DisplayFor(a=>lst[i].Autista) + @Html.HiddenFor(a=>lst[i].CodAutista) + + @Html.DisplayFor(a=>lst[i].CodMezzo)-@Html.DisplayFor(a=>lst[i].Automezzo) + @Html.HiddenFor(a=>lst[i].CodMezzo) + + + nocons +
+ + @Html.ActionLink("Seleziona tutti", "Index", "GiriDaValidare",new { sel = true }, new { @class = "btn btn-primary" }) + + @Html.ActionLink("Deleziona tutti", "Index", "GiriDaValidare",new { sel = false },new { @class = "btn btn-primary" }) + + @Html.ActionLink("Torna alla lista", "Index", "Giri",null,new { @class = "btn btn-primary" }) +
+
+
+