Michele: Paginazione destinazioni tramite helper

This commit is contained in:
michele 2024-07-09 17:26:13 +02:00
parent b9ab52911e
commit 1907f4e704
2 changed files with 29 additions and 48 deletions

View File

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json; using Newtonsoft.Json;
using SoftwayWeb.Models; using SoftwayWeb.Models;
using System.Text;
using X.PagedList; using X.PagedList;
namespace SoftwayWeb.Controllers namespace SoftwayWeb.Controllers
@ -28,38 +29,43 @@ namespace SoftwayWeb.Controllers
{ {
helper = new SessionHelper(this); helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
//StringBuilder aut = new StringBuilder();
string autista = string.Empty;
string dataGi = string.Empty;
string mezzo = string.Empty;
if (!string.IsNullOrEmpty(codAutista)) if (!string.IsNullOrEmpty(codAutista))
{ {
helper.SetStringValue("codAutista", codAutista); helper.SetStringValue("codAutista", codAutista);
} }
else else
{ {
string s = helper.GetStringValue("codAutista"); string aut = helper.GetStringValue("codAutista");
codAutista = aut;
} }
ViewBag.CodAutista = codAutista; if (!string.IsNullOrEmpty(codMezzo))
//if (codAutista == null) {
//{ helper.SetStringValue("codMezzo", codMezzo.ToString());
// //ViewBag.CodAutista = "codAutista"; }
// codAutista = ViewBag.CodAutista; else
//} {
string mez = helper.GetStringValue("codMezzo");
codMezzo = mez;
}
if (dataGiro.Date != DateTime.MinValue)
//if (!string.IsNullOrEmpty(codAutista)) {
//{ helper.SetStringValue("dataGiro", dataGiro.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"));
// //modelList = modelList.Where(x => x.CodAutista.Contains(codAutista)).ToList(); dataGi = dataGiro.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'");
}
// ViewData["CurrentFilter"] = codAutista; else
{
// ViewBag.Autista = codAutista; dataGi = helper.GetStringValue("dataGiro");
//} }
//else
//{
// ViewData = ViewBag.CodAutista;
//}
urlBase = apiUrl + "Giri/listaDestinazioniByAutistaDataMezzo"; 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; urlBase = urlBase + "?autista=" + codAutista.TrimEnd() + "&dataGiro=" + dataGi + "&mezzo=" + codMezzo;
Uri baseAddress = new Uri(urlBase); Uri baseAddress = new Uri(urlBase);
client = new HttpClient(); client = new HttpClient();
@ -74,12 +80,6 @@ namespace SoftwayWeb.Controllers
modelList = JsonConvert.DeserializeObject<List<Destinazioni_Out>>(dato); modelList = JsonConvert.DeserializeObject<List<Destinazioni_Out>>(dato);
modelList = modelList.Where(x => x.serialeGiro == id).ToList(); 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) if (page != null && page < 1)
{ {
page = 1; page = 1;
@ -87,7 +87,7 @@ namespace SoftwayWeb.Controllers
var pageSize = 10; var pageSize = 10;
var shortList = modelList.ToPagedList(page ?? 1, pageSize); var shortList = modelList.ToPagedList(page ?? 1, pageSize);
return View(/*modelList*/shortList); return View(shortList);
} }
else else
{ {
@ -96,8 +96,6 @@ namespace SoftwayWeb.Controllers
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
//var shortList = modelList.ToPagedList();
//return View(shortList);
} }
} }
} }

View File

@ -12,11 +12,6 @@
<h1>Lista destinazioni</h1> <h1>Lista destinazioni</h1>
<h2>@ViewBag.CodAutista</h2>
@* <p> @* <p>
<a asp-action="Create">Create New</a> <a asp-action="Create">Create New</a>
</p> </p>
@ -208,18 +203,6 @@
<td hidden> <td hidden>
@Html.HiddenFor(modelItem => item.ItemList) @Html.HiddenFor(modelItem => item.ItemList)
</td> </td>
@* @if (item.ConsFatta != null){
<td>
<img alt="cons" src="@Url.Content("~/images/fatto1.png")" style="width:35px;height:35px;">
</td>
} *@
@* @if (item.ConsFatta == null)
{
<td>
<img alt="nocons" src="@Url.Content("~/images/Yellow.png")" style="width:50px;height:50px;">
</td>
} *@
@* <td> @* <td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |