703 lines
26 KiB
C#
703 lines
26 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Newtonsoft.Json;
|
|
using SoftwayWeb.Models;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
using System.Runtime.Intrinsics.Arm;
|
|
using System.Text;
|
|
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;
|
|
string messAcc = string.Empty;
|
|
string messNew = string.Empty;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly IConfiguration _mess1;
|
|
private readonly IConfiguration _mess2;
|
|
HttpClient client;
|
|
SessionHelper helper;
|
|
|
|
public GiriController(IConfiguration configuration, IConfiguration mess1, IConfiguration mess2)
|
|
{
|
|
_configuration = configuration;
|
|
_mess1 = mess1;
|
|
_mess2 = mess2;
|
|
client = new HttpClient();
|
|
var key = _configuration["ApplicationInsights:rootUrlApi"];
|
|
var messA = _mess1["ApplicationInsights:messDestiAccodo"];
|
|
var messN = _mess2["ApplicationInsights:messDestiNew"];
|
|
apiUrl = key;
|
|
messAcc = messA;
|
|
messNew = messN;
|
|
}
|
|
|
|
public IActionResult Index(string? codAutista, string? codMezzo, DateTime data, bool aperto = true, int? page = 1)
|
|
{
|
|
helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
|
|
urlBase = apiUrl + "Giri/listaGiri?aperto="+ aperto;
|
|
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);
|
|
|
|
ViewBag.CodAutista = getAutisti();
|
|
|
|
if (!string.IsNullOrEmpty(codAutista))
|
|
{
|
|
modelList = modelList.Where(x => x.CodAutista.Contains(codAutista)).ToList();
|
|
|
|
ViewData["CurrentFilter"] = codAutista;
|
|
|
|
ViewBag.Autista = codAutista;
|
|
}
|
|
else
|
|
{
|
|
ViewData["CurrentFilter"] = null;
|
|
}
|
|
|
|
ViewBag.CodMezzo = getMezzi();
|
|
|
|
if (!string.IsNullOrEmpty(codMezzo))
|
|
{
|
|
modelList = modelList.Where(x => x.CodMezzo.Contains(codMezzo)).ToList();
|
|
ViewData["CurrentFilter"] = codMezzo;
|
|
}
|
|
else
|
|
{
|
|
ViewData["CurrentFilter"] = null;
|
|
}
|
|
|
|
if (data.Date != DateTime.MinValue)
|
|
{
|
|
modelList = modelList.Where(x => x.DataGiro.GetValueOrDefault().Date == data.Date).ToList();
|
|
}
|
|
|
|
if (page != null && page < 1)
|
|
{
|
|
page = 1;
|
|
}
|
|
|
|
var pageSize = 10;
|
|
|
|
var shortList = modelList.ToPagedList(page ?? 1, pageSize);
|
|
return View(shortList);
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
|
|
public IActionResult Create(bool sel)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
|
|
List<GiriConsegnaDaCreare> modelList = new List<GiriConsegnaDaCreare>();
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Giri/listaGiriDaCreare";
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<GiriConsegnaDaCreare>>(data);
|
|
}
|
|
|
|
foreach(GiriConsegnaDaCreare giro in modelList)
|
|
{
|
|
giro.IsSelected= sel;
|
|
}
|
|
|
|
return View(modelList);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult PostIndex(IList<GiriConsegnaDaCreare> lst)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
|
|
foreach (GiriConsegnaDaCreare g in lst)
|
|
{
|
|
if(g.IsSelected==true)
|
|
{
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Giri/addGiro2";
|
|
|
|
GiriConsegnaView gcv=new GiriConsegnaView();
|
|
gcv.CodAutista = g.CodAutista;
|
|
gcv.DataGiro=g.DataGiro;
|
|
gcv.CodMezzo = g.CodMezzo;
|
|
gcv.DataChiusura = DateTime.MinValue;
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
string data = JsonConvert.SerializeObject(gcv);
|
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
}
|
|
return RedirectToAction("Index", "Giri");
|
|
}
|
|
|
|
public IActionResult Bancali(string id, bool aperto = true)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Giri/listaGiri?aperto=" + aperto;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
List<GiriConsegnaView> modelList = new List<GiriConsegnaView>();
|
|
GiriConsegnaView model = new GiriConsegnaView();
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<GiriConsegnaView>>(data);
|
|
model = modelList.Where(x => x.SerialeGiro.Equals(id)).First();
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
return View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Bancali(GiriConsegnaView model)
|
|
{
|
|
if (model.BancaliCaricati == null)
|
|
{
|
|
return View(model);
|
|
}
|
|
SessionHelper helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Giri/modGiro";
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
string data = JsonConvert.SerializeObject(model);
|
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
return RedirectToAction("Index", "Giri");
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult ModificaTutteDestinazioni(string id, string? codAutista, string? nomeAutista, string? codMezzo, string? nomeMezzo, DateTime dataGiroCons, int? page = 1)
|
|
{
|
|
helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
|
|
ViewBag.CodAutista = codAutista;
|
|
ViewBag.Autista = nomeAutista;
|
|
ViewBag.CodMezzo = codMezzo;
|
|
ViewBag.Mezzo = nomeMezzo;
|
|
ViewBag.DataGiroCons = dataGiroCons;
|
|
|
|
string dataGiroString = dataGiroCons.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'");
|
|
|
|
urlBase = apiUrl + "Giri/listaDestinazioniByAutistaDataMezzo";
|
|
urlBase = urlBase + "?autista=" + codAutista + "&dataGiro=" + dataGiroString + "&mezzo=" + codMezzo;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<Destinazioni_Out> modelList = new List<Destinazioni_Out>();
|
|
|
|
List<SelectListItem> autisti = new List<SelectListItem>();
|
|
autisti = getAutisti();
|
|
ViewBag.Autisti = autisti;
|
|
|
|
List<SelectListItem> mezzi = new List<SelectListItem>();
|
|
mezzi = getMezzi();
|
|
ViewBag.Mezzi = mezzi;
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string dato = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Destinazioni_Out>>(dato);
|
|
modelList = modelList.Where(x => x.serialeGiro.Equals(id.TrimEnd())).OrderBy(x => x.Seq).ThenBy(x => x.Committente).ToList();
|
|
|
|
//if (page != null && page < 1)
|
|
//{
|
|
// page = 1;
|
|
//}
|
|
|
|
//var pageSize = 10;
|
|
|
|
//var shortList = modelList.ToPagedList(page ?? 1, pageSize);
|
|
|
|
return View(modelList);
|
|
//return View(shortList);
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult ModificaTutteDestinazioniStep1(List<Destinazioni_Out> modelList, string? autisti, string? nomeAutista, string? mezzi, string? nomeMezzo)
|
|
{
|
|
ViewBag.CodMezzo = mezzi;
|
|
ViewBag.CodAutista = autisti;
|
|
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
|
|
foreach (var item in modelList)
|
|
{
|
|
string dataGi = string.Empty;
|
|
dataGi = item.DataCarico.Value.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'");
|
|
urlBase = apiUrl + "Giri/listaDestinazioniByAutistaDataMezzoWeb";
|
|
//urlBase = urlBase + "?autista=" + item.CodAutista + "&dataGiro=" + dataGi + "&mezzo=" + item.CodAutomezzo;
|
|
urlBase = urlBase + "?autista=" + autisti + "&dataGiro=" + dataGi + "&mezzo=" + mezzi;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<Destinazioni_Out> modelList2 = new List<Destinazioni_Out>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string dato = response.Content.ReadAsStringAsync().Result;
|
|
modelList2 = JsonConvert.DeserializeObject<List<Destinazioni_Out>>(dato);
|
|
var presenti = modelList2.OrderByDescending(t => t.Prog);
|
|
|
|
string mex = string.Empty;
|
|
//var nomeA = item.Autista;
|
|
//var nomeM = item.DescAutomezzo;
|
|
|
|
if (presenti != null && presenti.Count() > 0)
|
|
{
|
|
//giro già esistente.. accodo
|
|
mex = messAcc;
|
|
}
|
|
else
|
|
{
|
|
// giro non esistente.. ne creo uno nuovo
|
|
mex = messNew;
|
|
}
|
|
|
|
item.CodAutistaOld = item.CodAutista;
|
|
item.AutistaOld = item.Autista;
|
|
item.CodAutomezzoOld = item.CodAutomezzo;
|
|
item.DescAutomezzoOld = item.DescAutomezzoOld;
|
|
|
|
ViewBag.Messaggio = mex;
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
|
|
return View(modelList);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult ModificaTutteDestinazioniPost(List<Destinazioni_Out> modelList, string? CodAutista, string? CodMezzo/*, string? autisti,*/ /*string? nomeAutista,*/ /*string? mezzi*/)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
|
|
foreach (var model in modelList)
|
|
{
|
|
string dataGi = string.Empty;
|
|
dataGi = model.DataCarico.Value.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'");
|
|
urlBase = apiUrl + "Giri/listaDestinazioniByAutistaDataMezzoWeb";
|
|
urlBase = urlBase + "?autista=" + model.CodAutista + "&dataGiro=" + dataGi + "&mezzo=" + model.CodAutomezzo;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<Destinazioni_Out> modelList2 = new List<Destinazioni_Out>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
Modgir mg = new Modgir();
|
|
|
|
mg.Piserial = model.Brserial;
|
|
mg.Pidata = model.DataCarico;
|
|
mg.Picommit = model.CodCommittente;
|
|
mg.Pidesdiv = model.CodSede;
|
|
mg.Pitarga = CodAutista;
|
|
mg.Piautist = CodMezzo;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string dato = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Destinazioni_Out>>(dato);
|
|
var presenti = modelList.OrderByDescending(t => t.Prog);
|
|
|
|
if (presenti != null && presenti.Count() > 0)
|
|
{
|
|
//giro già esistente.. accodo
|
|
mg.Pitiprec = "M";
|
|
mg.Pisergirold = model.serialeGiro;
|
|
foreach (Destinazioni_Out d in presenti)
|
|
{
|
|
mg.Pisergir = d.serialeGiro;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// giro non esistente.. ne creo uno nuovo
|
|
mg.Pitiprec = "N";
|
|
mg.Pisergir = model.serialeGiro;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
|
|
urlBase = apiUrl + "ModificaGiro/addModgir";
|
|
baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
string data = JsonConvert.SerializeObject(mg);
|
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
HttpResponseMessage response2 = client.PostAsync(baseAddress, content).Result;
|
|
|
|
if (response2.IsSuccessStatusCode)
|
|
{
|
|
return RedirectToAction("IndexValidate", "Destinazioni", new
|
|
{
|
|
id = model.serialeGiro,
|
|
codAutista = model.CodAutistaOld,
|
|
nomeAutista = model.AutistaOld,
|
|
dataGiro = model.DataCarico,
|
|
codMezzo = model.CodAutomezzoOld,
|
|
desMezzo = model.DescAutomezzoOld
|
|
});
|
|
}
|
|
else
|
|
{
|
|
errMes = response2.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
|
|
return RedirectToAction("Index", "Giri");
|
|
}
|
|
|
|
|
|
//[HttpPost]
|
|
//public IActionResult ModificaTutteDestinazioniPost(List<Destinazioni_Out> modelList, string? autisti, /*string? nomeAutista,*/ string? mezzi)
|
|
//{
|
|
// SessionHelper helper = new SessionHelper(this);
|
|
|
|
// token = helper.GetStringValue("tok");
|
|
|
|
// if (string.IsNullOrEmpty(token))
|
|
// {
|
|
// return RedirectToAction("Login", "Login");
|
|
// }
|
|
|
|
// foreach (var destinazione in modelList)
|
|
// {
|
|
// Modgir mg = new Modgir();
|
|
|
|
// mg.Piserial = destinazione.Brserial;
|
|
// mg.Pidata = destinazione.DataCarico;
|
|
// mg.Picommit = destinazione.CodCommittente;
|
|
// mg.Pidesdiv = destinazione.CodSede;
|
|
// mg.Pitarga = mezzi.TrimEnd();
|
|
// mg.Piautist = autisti.TrimEnd();
|
|
// mg.Pitiprec = "M";
|
|
// mg.Pisergir = destinazione.serialeGiro;
|
|
|
|
// apiUrl = helper.GetStringValue("apiUrl");
|
|
|
|
// urlBase = apiUrl + "ModificaGiro/addModgir";
|
|
|
|
// Uri baseAddress = new Uri(urlBase);
|
|
// client = new HttpClient();
|
|
// client.BaseAddress = baseAddress;
|
|
|
|
// string data = JsonConvert.SerializeObject(mg);
|
|
// StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
|
|
// HttpResponseMessage response2 = client.PostAsync(baseAddress, content).Result;
|
|
|
|
// //if (response2.IsSuccessStatusCode)
|
|
// //{
|
|
// // //Destinazioni_Out destMod = new Destinazioni_Out();
|
|
// // //destMod.serialeGiro = destinazione.Brserial;
|
|
// // //destMod.CodAutista = destinazione.CodAutista;
|
|
// // //destMod.CodAutomezzo = destinazione.CodAutomezzo;
|
|
// // //new
|
|
// // //{
|
|
// // // id = destinazione.serialeGiro,
|
|
// // // codAutista = destinazione.CodAutista,
|
|
// // // dataGiro = destinazione.DataCarico,
|
|
// // // codMezzo = destinazione.CodAutomezzo
|
|
// // //},;
|
|
// //}
|
|
// }
|
|
|
|
// return RedirectToAction("Index", "Giri");
|
|
//}
|
|
|
|
//[HttpPost]
|
|
//public IActionResult Create(GiriConsegnaView model)
|
|
//{
|
|
// SessionHelper helper = new SessionHelper(this);
|
|
// ViewBag.Autisti = getAutisti();
|
|
// apiUrl = helper.GetStringValue("apiUrl");
|
|
// urlBase = apiUrl + "Giri/addGiro2";
|
|
|
|
// Uri baseAddress = new Uri(urlBase);
|
|
// client = new HttpClient();
|
|
// client.BaseAddress = baseAddress;
|
|
// string data = JsonConvert.SerializeObject(model);
|
|
// StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
// HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
// if (response.IsSuccessStatusCode)
|
|
// {
|
|
// return RedirectToAction("Index", "Giri");
|
|
// }
|
|
// else
|
|
// {
|
|
// errMes = response.Content.ReadAsStringAsync().Result;
|
|
// helper.SetStringValue("errMsg", errMes);
|
|
// return RedirectToAction("Error");
|
|
// }
|
|
//}
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
string e = helper.GetStringValue("errMsg");
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrMsg = e });
|
|
}
|
|
|
|
#region METODI PRIVATI
|
|
|
|
private List<SelectListItem> getAutisti()
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Giri/listaAutisti";
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
List<Personale> modelList = new List<Personale>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Personale>>(data);
|
|
|
|
//per gestire primo elemento tendina (deve essere vuoto)
|
|
SelectListItem listItemFirt = new SelectListItem();
|
|
|
|
listItemFirt.Value = string.Empty;
|
|
listItemFirt.Text = " - Autista";
|
|
selectItems.Add(listItemFirt);
|
|
|
|
foreach (var role in modelList)
|
|
{
|
|
SelectListItem listItem = new SelectListItem();
|
|
//string s = role.Catcodice + " - " + role.Catnome;
|
|
string s = role.Catnome + " - " + role.Catcodice; // 25/07/2024 invertito nome autista con codice autista
|
|
listItem.Value = role.Catcodice;
|
|
listItem.Text = s;
|
|
selectItems.Add(listItem);
|
|
}
|
|
}
|
|
|
|
return selectItems;
|
|
}
|
|
|
|
private List<SelectListItem> getMezzi()
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Giri/listaAutomezzi";
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
List<Automezzi> listMezzi = new List<Automezzi>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
listMezzi = JsonConvert.DeserializeObject<List<Automezzi>>(data);
|
|
|
|
listMezzi = listMezzi.OrderBy(x => x.CauTarga).ToList();
|
|
|
|
//per gestire primo elemento tendina (deve essere vuoto)
|
|
SelectListItem listItemFirt = new SelectListItem();
|
|
|
|
listItemFirt.Value = string.Empty;
|
|
listItemFirt.Text = " - Automezzo";
|
|
selectItems.Add(listItemFirt);
|
|
|
|
foreach (var mezzo in listMezzi)
|
|
{
|
|
SelectListItem listItem = new SelectListItem();
|
|
List<SelectListItem> listItemOrderby = new List<SelectListItem>();
|
|
string s = mezzo.CauTarga + " - " + mezzo.CauDesc;
|
|
listItem.Value = mezzo.CauTarga;
|
|
listItem.Text = s;
|
|
|
|
selectItems.Add(listItem);
|
|
}
|
|
}
|
|
|
|
return selectItems;
|
|
|
|
}
|
|
|
|
private List<GiriConsegnaDaCreare> getNuoviGiri()
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
List<GiriConsegnaDaCreare> modelList = new List<GiriConsegnaDaCreare> ();
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Giri/listaGiriDaCreare";
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<GiriConsegnaDaCreare>>(data);
|
|
}
|
|
return modelList;
|
|
}
|
|
|
|
#endregion METODI PRIVATI
|
|
}
|
|
}
|