using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using SoftwayWeb.Models; using X.PagedList; namespace SoftwayWeb.Controllers { public class ConsegneController : 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 ConsegneController(IConfiguration configuration) { _configuration = configuration; client = new HttpClient(); var key = _configuration["ApplicationInsights:rootUrlApi"]; apiUrl = key; } public IActionResult Dettaglio(string id, string? codAutista, DateTime dataGiro, string? codMezzo) { helper = new SessionHelper(this); token = helper.GetStringValue("tok"); urlBase = apiUrl + "Giri/listaDestinazioniByAutistaDataMezzo"; var dataGiroFormattata = dataGiro.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"); urlBase = urlBase + "?autista=" + codAutista + "&dataGiro=" + dataGiroFormattata + "&mezzo=" + codMezzo; Uri baseAddress = new Uri(urlBase); client = new HttpClient(); client.BaseAddress = baseAddress; List modelList = new List(); Destinazioni_Out model = new Destinazioni_Out(); Destinazioni_Out.ConsegnaFatta modelCons = new Destinazioni_Out.ConsegnaFatta(); HttpResponseMessage response = client.GetAsync(baseAddress).Result; if (response.IsSuccessStatusCode) { string dato = response.Content.ReadAsStringAsync().Result; modelList = JsonConvert.DeserializeObject>(dato); model = modelList.Where(x => x.Brserial == id).First(); modelCons = model.ConsFatta; return View("Dettaglio",model); } else { errMes = response.Content.ReadAsStringAsync().Result; helper.SetStringValue("errMsg", errMes); return RedirectToAction("Error"); } } //public IActionResult Index(string id, string? codAutista, DateTime dataGiro, string? codMezzo) //{ // helper = new SessionHelper(this); // token = helper.GetStringValue("tok"); // urlBase = apiUrl + "Giri/listaDestinazioniByAutistaDataMezzo"; // var dataGiroFormattata = dataGiro.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"); // urlBase = urlBase + "?autista=" + codAutista + "&dataGiro="+ dataGiroFormattata + "&mezzo=" + codMezzo; // Uri baseAddress = new Uri(urlBase); // client = new HttpClient(); // client.BaseAddress = baseAddress; // List modelList = new List(); // Destinazioni_Out model = new Destinazioni_Out(); // Destinazioni_Out.ConsegnaFatta modelCons = new Destinazioni_Out.ConsegnaFatta(); // HttpResponseMessage response = client.GetAsync(baseAddress).Result; // if (response.IsSuccessStatusCode) // { // string dato = response.Content.ReadAsStringAsync().Result; // modelList = JsonConvert.DeserializeObject>(dato); // model = modelList.Where(x => x.Brserial == id).First(); // modelCons = model.ConsFatta; // return View(modelCons); // } // else // { // errMes = response.Content.ReadAsStringAsync().Result; // helper.SetStringValue("errMsg", errMes); // return RedirectToAction("Error"); // } //} } }