66 lines
2.3 KiB
C#
66 lines
2.3 KiB
C#
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);
|
|
helper.ClearFormatedKey("errMsg");
|
|
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<Destinazioni_Out> modelList = new List<Destinazioni_Out>();
|
|
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<List<Destinazioni_Out>>(dato);
|
|
model = modelList.Where(x => x.Brserial == id).First();
|
|
modelCons = model.ConsFatta;
|
|
|
|
return View("Dettaglio",model);
|
|
}
|
|
else
|
|
{
|
|
errMes = helper.getErrMsgFromResponse(response);
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|