298 lines
11 KiB
C#
298 lines
11 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Newtonsoft.Json;
|
|
using SoftwayWeb.Models;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
|
|
|
|
namespace SoftwayWeb.Controllers
|
|
{
|
|
public class AddDestinazioneController : 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 AddDestinazioneController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
client = new HttpClient();
|
|
var key = _configuration["ApplicationInsights:rootUrlApi"];
|
|
apiUrl = key;
|
|
}
|
|
|
|
public IActionResult AddDestinazione(string serialeGiro)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
Modgir model = new Modgir();
|
|
|
|
ViewBag.serialeGiro = serialeGiro;
|
|
model.Pisergir = serialeGiro;
|
|
ViewBag.Commit = getCommittenti();
|
|
ViewBag.CodAutista = getAutisti();
|
|
ViewBag.Mezzi = getMezzi();
|
|
|
|
return View(model);
|
|
}
|
|
|
|
public IActionResult NewDestinazione(Modgir modgir, string? autista, string? mezzo, string id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
|
|
//qui metodo post per scrivere su pimodgir
|
|
Modgir mg = new Modgir();
|
|
|
|
//mg.Piprogre = modgir.Piprogre;
|
|
mg.Piserial = string.Empty;
|
|
mg.Pidata = modgir.Pidata;
|
|
mg.Picommit = modgir.Picommit;
|
|
mg.Pidesdiv = modgir.Pidesdiv;
|
|
mg.Pitarga = mezzo.TrimEnd();
|
|
mg.Piautist = autista.TrimEnd();
|
|
mg.Pitiprec = "A";
|
|
mg.Pirigele = string.Empty;
|
|
mg.Pisergir = id;
|
|
|
|
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 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");
|
|
}
|
|
//return View();
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
#region METODI INTERNI
|
|
|
|
private List<SelectListItem> getCommittenti()
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Clienti/getCommittenti";
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
List<Clienti> listClienti = new List<Clienti>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
listClienti = JsonConvert.DeserializeObject<List<Clienti>>(data);
|
|
|
|
//per gestire primo elemento tendina (deve essere vuoto)
|
|
SelectListItem listItemFirst = new SelectListItem();
|
|
|
|
listItemFirst.Value = string.Empty;
|
|
listItemFirst.Text = " - Seleziona Committente";
|
|
selectItems.Add(listItemFirst);
|
|
|
|
foreach (var item in listClienti)
|
|
{
|
|
SelectListItem listItem = new SelectListItem();
|
|
|
|
string s = item.Ancodice + " - " + item.Andescri;
|
|
listItem.Value = item.Ancodice;
|
|
listItem.Text = s;
|
|
selectItems.Add(listItem);
|
|
}
|
|
}
|
|
|
|
return selectItems;
|
|
}
|
|
|
|
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 = " - Seleziona 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 = " - Seleziona 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;
|
|
|
|
}
|
|
#endregion METODI INTERNI
|
|
|
|
#region CASCADING
|
|
|
|
public IActionResult Cascading()
|
|
{
|
|
Cascading model = new Cascading();
|
|
model.Committenti = getCommittenti();
|
|
return View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Cascading(string Picommit/*ancodice*/)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
Cascading model = new Cascading();
|
|
model.Committenti = getCommittenti();
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
if (!string.IsNullOrEmpty(Picommit))
|
|
{
|
|
token = helper.GetStringValue("tok");
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Clienti/getSediByCommittente"+ "?codCom=" + Picommit;
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<SedeConsegna> sediCons = new List<SedeConsegna>();
|
|
|
|
//List<SedeConsegna> listSedi = new List<SedeConsegna>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
sediCons = JsonConvert.DeserializeObject<List<SedeConsegna>>(data);
|
|
|
|
SelectListItem listItemFirst = new SelectListItem();
|
|
|
|
listItemFirst.Value = string.Empty;
|
|
listItemFirst.Text = " - Seleziona sede";
|
|
selectItems.Add(listItemFirst);
|
|
|
|
foreach (var sede in sediCons)
|
|
{
|
|
|
|
SelectListItem listItem = new SelectListItem();
|
|
string s = sede.Pccodsed + " - " + sede.Pcdescri;
|
|
listItem.Value = sede.Pccodsed;
|
|
listItem.Text = s;
|
|
selectItems.Add(listItem);
|
|
//model.SediCons.Add(listItem);
|
|
model.SediCons.Add(listItem);
|
|
}
|
|
//model.SediCons.AddRange(selectItems);
|
|
// ViewBag.SediCons = sediCons;
|
|
}
|
|
}
|
|
return Json(new SelectList(selectItems, "Value", "Text"));
|
|
|
|
|
|
}
|
|
|
|
#endregion CASCADING
|
|
}
|
|
}
|