From 1907f4e704b4be43886381aaa4e10c10aaa7c496 Mon Sep 17 00:00:00 2001 From: michele Date: Tue, 9 Jul 2024 17:26:13 +0200 Subject: [PATCH] Michele: Paginazione destinazioni tramite helper --- Controllers/DestinazioniController.cs | 60 +++++++++++++-------------- Views/Destinazioni/Index.cshtml | 17 -------- 2 files changed, 29 insertions(+), 48 deletions(-) diff --git a/Controllers/DestinazioniController.cs b/Controllers/DestinazioniController.cs index 169e424..b028a86 100644 --- a/Controllers/DestinazioniController.cs +++ b/Controllers/DestinazioniController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Newtonsoft.Json; using SoftwayWeb.Models; +using System.Text; using X.PagedList; namespace SoftwayWeb.Controllers @@ -28,38 +29,43 @@ namespace SoftwayWeb.Controllers { helper = new SessionHelper(this); token = helper.GetStringValue("tok"); + + //StringBuilder aut = new StringBuilder(); + string autista = string.Empty; + string dataGi = string.Empty; + string mezzo = string.Empty; + if (!string.IsNullOrEmpty(codAutista)) { helper.SetStringValue("codAutista", codAutista); } else { - string s = helper.GetStringValue("codAutista"); + string aut = helper.GetStringValue("codAutista"); + codAutista = aut; } - ViewBag.CodAutista = codAutista; - //if (codAutista == null) - //{ - // //ViewBag.CodAutista = "codAutista"; - // codAutista = ViewBag.CodAutista; - //} - - - //if (!string.IsNullOrEmpty(codAutista)) - //{ - // //modelList = modelList.Where(x => x.CodAutista.Contains(codAutista)).ToList(); - - // ViewData["CurrentFilter"] = codAutista; - - // ViewBag.Autista = codAutista; - //} - //else - //{ - // ViewData = ViewBag.CodAutista; - //} + if (!string.IsNullOrEmpty(codMezzo)) + { + helper.SetStringValue("codMezzo", codMezzo.ToString()); + } + else + { + string mez = helper.GetStringValue("codMezzo"); + codMezzo = mez; + } + if (dataGiro.Date != DateTime.MinValue) + { + helper.SetStringValue("dataGiro", dataGiro.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'")); + dataGi = dataGiro.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"); + } + else + { + dataGi = helper.GetStringValue("dataGiro"); + } + urlBase = apiUrl + "Giri/listaDestinazioniByAutistaDataMezzo"; - string dataGi = dataGiro.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"); urlBase = urlBase + "?autista=" + codAutista.TrimEnd() + "&dataGiro=" + dataGi + "&mezzo=" + codMezzo; Uri baseAddress = new Uri(urlBase); client = new HttpClient(); @@ -74,12 +80,6 @@ namespace SoftwayWeb.Controllers modelList = JsonConvert.DeserializeObject>(dato); modelList = modelList.Where(x => x.serialeGiro == id).ToList(); - //ViewData["codAutista"] = codAutista; - //ViewBag.CodAutista = "codAutista"; - //ViewBag.DataGiro = dataGiro; - //ViewBag.CodMezzo = codMezzo; - - if (page != null && page < 1) { page = 1; @@ -87,7 +87,7 @@ namespace SoftwayWeb.Controllers var pageSize = 10; var shortList = modelList.ToPagedList(page ?? 1, pageSize); - return View(/*modelList*/shortList); + return View(shortList); } else { @@ -96,8 +96,6 @@ namespace SoftwayWeb.Controllers return RedirectToAction("Error"); } - //var shortList = modelList.ToPagedList(); - //return View(shortList); } } } diff --git a/Views/Destinazioni/Index.cshtml b/Views/Destinazioni/Index.cshtml index 0497947..3490272 100644 --- a/Views/Destinazioni/Index.cshtml +++ b/Views/Destinazioni/Index.cshtml @@ -12,11 +12,6 @@

Lista destinazioni

- -

@ViewBag.CodAutista

- - - @*

Create New

@@ -208,18 +203,6 @@ @Html.HiddenFor(modelItem => item.ItemList) - - @* @if (item.ConsFatta != null){ - - cons - - } *@ - @* @if (item.ConsFatta == null) - { - - nocons - - } *@ @* @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |