71 lines
2.4 KiB
C#
71 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using SoftwayWeb.Models;
|
|
using X.PagedList;
|
|
|
|
namespace SoftwayWeb.Controllers
|
|
{
|
|
public class GiriController : 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 GiriController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
client = new HttpClient();
|
|
var key = _configuration["ApplicationInsights:rootUrlApi"];
|
|
apiUrl = key;
|
|
}
|
|
|
|
public IActionResult Index(string? codAutista, DateTime data, bool aperto = true)
|
|
{
|
|
helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
string url = apiUrl + "Giri/listaGiri";
|
|
urlBase = url + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<GiriConsegnaView> modelList = new List<GiriConsegnaView>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string dato = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<GiriConsegnaView>>(dato);
|
|
|
|
if (!string.IsNullOrEmpty(codAutista))
|
|
{
|
|
modelList = modelList.Where(x => x.CodAutista.Contains(codAutista)).ToList();
|
|
|
|
ViewData["CurrentFilter"] = codAutista;
|
|
}
|
|
else
|
|
{
|
|
ViewData["CurrentFilter"] = null;
|
|
}
|
|
|
|
if (data.Date != DateTime.MinValue)
|
|
{
|
|
modelList = modelList.Where(x => x.DataGiro.GetValueOrDefault().Date == data.Date).ToList();
|
|
}
|
|
//var shortList = modelList.ToPagedList();
|
|
return View(modelList);
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
}
|
|
}
|