using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using SoftwayWeb.Models; using X.PagedList; namespace SoftwayWeb.Controllers { public class DestinazioniController : Controller { string apiUrl = string.Empty; string urlBase = string.Empty; string token = string.Empty; string errMes = string.Empty; private readonly IConfiguration _configuration; HttpClient client; SessionHelper helper; public DestinazioniController(IConfiguration configuration) { _configuration = configuration; client = new HttpClient(); var key = _configuration["ApplicationInsights:rootUrlApi"]; apiUrl = key; } public IActionResult Index(string id, string? codAutista, DateTime dataGiro, string? codMezzo) { helper = new SessionHelper(this); token = helper.GetStringValue("tok"); urlBase = apiUrl + "Giri/listaDestinazioniByAutistaDataMezzo"; //dataGiro = dataGiro.ToUniversalTime(); //urlBase = urlBase + "autista=" + giro.CodAutista + "datGiro=" + giro.DataGiro; urlBase = urlBase + "?autista=" + codAutista.Trim() + "&dataGiro=2023-05-30T00%3A00%3A00.000Z" + "&mezzo=" + codMezzo /*+ dataGiro*/; Uri baseAddress = new Uri(urlBase); client = new HttpClient(); client.BaseAddress = baseAddress; List modelList = new List(); HttpResponseMessage response = client.GetAsync(baseAddress).Result; if (response.IsSuccessStatusCode) { string dato = response.Content.ReadAsStringAsync().Result; modelList = JsonConvert.DeserializeObject>(dato); modelList = modelList.Where(x => x.serialeGiro == id).ToList(); var shortList = modelList.ToPagedList(); return View(modelList/*shortList*/); } else { errMes = response.Content.ReadAsStringAsync().Result; helper.SetStringValue("errMsg", errMes); return RedirectToAction("Error"); } //var shortList = modelList.ToPagedList(); //return View(shortList); } } }