gestione errore

This commit is contained in:
Marco Audiffredi 2025-04-02 15:48:42 +02:00
parent 40499c11fb
commit 0ab412b6cf
9 changed files with 52 additions and 78 deletions

View File

@ -31,7 +31,7 @@ namespace SoftwayWeb.Controllers
public IActionResult AddDestinazione(string serialeGiro, string? codAutista, string? nomeAutista, string? codMezzo, string? desMezzo, DateTime dataGiro) public IActionResult AddDestinazione(string serialeGiro, string? codAutista, string? nomeAutista, string? codMezzo, string? desMezzo, DateTime dataGiro)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -69,7 +69,7 @@ namespace SoftwayWeb.Controllers
public IActionResult NewDestinazioneStep1(Modgir modgir, string nomeAutista, string automezzo, DateTime dataGiro) public IActionResult NewDestinazioneStep1(Modgir modgir, string nomeAutista, string automezzo, DateTime dataGiro)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -112,7 +112,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
@ -127,7 +127,7 @@ namespace SoftwayWeb.Controllers
public IActionResult NewDestinazione(Modgir modgir /*,string? codAutista, string? codMezzo, DateTime dataGiro, string serGiro*/) public IActionResult NewDestinazione(Modgir modgir /*,string? codAutista, string? codMezzo, DateTime dataGiro, string serGiro*/)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -182,7 +182,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }

View File

@ -27,6 +27,7 @@ namespace SoftwayWeb.Controllers
public IActionResult Dettaglio(string id, string? codAutista, DateTime dataGiro, string? codMezzo) public IActionResult Dettaglio(string id, string? codAutista, DateTime dataGiro, string? codMezzo)
{ {
helper = new SessionHelper(this); helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
urlBase = apiUrl + "Giri/listaDestinazioniByAutistaDataMezzo"; urlBase = apiUrl + "Giri/listaDestinazioniByAutistaDataMezzo";
var dataGiroFormattata = dataGiro.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"); var dataGiroFormattata = dataGiro.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'");
@ -52,46 +53,13 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); 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<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(modelCons);
// }
// else
// {
// errMes = response.Content.ReadAsStringAsync().Result;
// helper.SetStringValue("errMsg", errMes);
// return RedirectToAction("Error");
// }
//}
} }
} }

View File

@ -41,7 +41,7 @@ namespace SoftwayWeb.Controllers
public IActionResult Index(string id, string? codAutista, string? nomeAutista, DateTime dataGiro, string? codMezzo, string? desMezzo, int? page = 1) public IActionResult Index(string id, string? codAutista, string? nomeAutista, DateTime dataGiro, string? codMezzo, string? desMezzo, int? page = 1)
{ {
helper = new SessionHelper(this); helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -139,7 +139,7 @@ namespace SoftwayWeb.Controllers
public IActionResult IndexValidate(string id, string? codAutista, string? nomeAutista, DateTime dataGiro, string? codMezzo, string? desMezzo, int? page = 1) public IActionResult IndexValidate(string id, string? codAutista, string? nomeAutista, DateTime dataGiro, string? codMezzo, string? desMezzo, int? page = 1)
{ {
helper = new SessionHelper(this); helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -237,7 +237,7 @@ namespace SoftwayWeb.Controllers
public IActionResult EliminaDestinazione(string serial) public IActionResult EliminaDestinazione(string serial)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -328,7 +328,7 @@ namespace SoftwayWeb.Controllers
public IActionResult ModificaDestinazione(string serial) public IActionResult ModificaDestinazione(string serial)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
var requestUrl = $"{Request.Scheme}://{Request.Host.Value}/"; var requestUrl = $"{Request.Scheme}://{Request.Host.Value}/";
@ -395,7 +395,7 @@ namespace SoftwayWeb.Controllers
public IActionResult ModificaDestinazioneStep1(Destinazioni_Out model) public IActionResult ModificaDestinazioneStep1(Destinazioni_Out model)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -462,7 +462,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
@ -475,7 +475,7 @@ namespace SoftwayWeb.Controllers
public IActionResult ModificaDestinazionePost(Destinazioni_Out model) public IActionResult ModificaDestinazionePost(Destinazioni_Out model)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -530,7 +530,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
@ -560,7 +560,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response2.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response2);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }

View File

@ -27,7 +27,7 @@ namespace SoftwayWeb.Controllers
public ActionResult Index() public ActionResult Index()
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -40,7 +40,7 @@ namespace SoftwayWeb.Controllers
public ActionResult Chiudi(string id, int nbanc,decimal imp) public ActionResult Chiudi(string id, int nbanc,decimal imp)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -71,7 +71,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
@ -84,7 +84,7 @@ namespace SoftwayWeb.Controllers
{ {
//https://api.poloinformatico.it:8000/api/Giri/closeGiro?serialeGiro=0000000002&bancaliRecuperati=11&importoRecuperato=100 //https://api.poloinformatico.it:8000/api/Giri/closeGiro?serialeGiro=0000000002&bancaliRecuperati=11&importoRecuperato=100
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -112,7 +112,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }

View File

@ -110,7 +110,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
@ -187,7 +187,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
@ -225,7 +225,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
@ -241,6 +241,7 @@ namespace SoftwayWeb.Controllers
return View(model); return View(model);
} }
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -265,7 +266,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
@ -275,7 +276,7 @@ namespace SoftwayWeb.Controllers
public IActionResult ModificaTutteDestinazioni(string id, string? codAutista, string? nomeAutista, string? codMezzo, string? nomeMezzo, DateTime dataGiroCons/*, int? page = 1*/) public IActionResult ModificaTutteDestinazioni(string id, string? codAutista, string? nomeAutista, string? codMezzo, string? nomeMezzo, DateTime dataGiroCons/*, int? page = 1*/)
{ {
helper = new SessionHelper(this); helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -321,7 +322,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
@ -331,7 +332,7 @@ namespace SoftwayWeb.Controllers
public IActionResult ModificaTutteDestinazioniStep1(string SerialeGiro, string? CodAutista, string? NomeAutista, string? CodMezzo, string? NomeMezzo, DateTime DataGiroCons,string CodAutistaOld,string CodMezzoOld) public IActionResult ModificaTutteDestinazioniStep1(string SerialeGiro, string? CodAutista, string? NomeAutista, string? CodMezzo, string? NomeMezzo, DateTime DataGiroCons,string CodAutistaOld,string CodMezzoOld)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -406,7 +407,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
@ -424,7 +425,7 @@ namespace SoftwayWeb.Controllers
public IActionResult ModificaTutteDestinazioniPost(List<Destinazioni_Out> modelList, string? CodAutista, string? CodMezzo, DateTime DataGiroCons,string SerialeGiro,string TipoOperazione,string SerialeGiroDestinazione) public IActionResult ModificaTutteDestinazioniPost(List<Destinazioni_Out> modelList, string? CodAutista, string? CodMezzo, DateTime DataGiroCons,string SerialeGiro,string TipoOperazione,string SerialeGiroDestinazione)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -469,21 +470,12 @@ namespace SoftwayWeb.Controllers
if (!response2.IsSuccessStatusCode) if (!response2.IsSuccessStatusCode)
{ {
errMes = response2.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response2);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }
} }
//return RedirectToAction("IndexValidate", "Destinazioni", new
//{
// id = model.serialeGiro,
// codAutista = model.CodAutistaOld,
// nomeAutista = model.AutistaOld,
// dataGiro = model.DataCarico,
// codMezzo = model.CodAutomezzoOld,
// desMezzo = model.DescAutomezzoOld
//});
return RedirectToAction("Index", "Giri"); return RedirectToAction("Index", "Giri");
} }

View File

@ -28,7 +28,8 @@ namespace SoftwayWeb.Controllers
//se la data non è valorizzata, prendo i giri inseriti per ultimi, altrimenti li cerco per data //se la data non è valorizzata, prendo i giri inseriti per ultimi, altrimenti li cerco per data
List<GiriConsegnaDaCreare> modelList = new List<GiriConsegnaDaCreare>(); List<GiriConsegnaDaCreare> modelList = new List<GiriConsegnaDaCreare>();
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
if(clear) helper.ClearFormatedKey("errMsg");
if (clear)
{ {
helper.SetStringValue("filterData", string.Empty); helper.SetStringValue("filterData", string.Empty);
} }
@ -54,7 +55,12 @@ namespace SoftwayWeb.Controllers
string result = response.Content.ReadAsStringAsync().Result; string result = response.Content.ReadAsStringAsync().Result;
modelList = JsonConvert.DeserializeObject<List<GiriConsegnaDaCreare>>(result); modelList = JsonConvert.DeserializeObject<List<GiriConsegnaDaCreare>>(result);
} }
else
{
errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error");
}
string _filtro= helper.GetStringValue("filterData"); string _filtro= helper.GetStringValue("filterData");
if (data == DateTime.MinValue && string.IsNullOrEmpty(_filtro) && modelList.Count()>0) if (data == DateTime.MinValue && string.IsNullOrEmpty(_filtro) && modelList.Count()>0)
@ -88,7 +94,7 @@ namespace SoftwayWeb.Controllers
public IActionResult PostIndex(IList<GiriConsegnaDaCreare> lst, string valida, string valida0) public IActionResult PostIndex(IList<GiriConsegnaDaCreare> lst, string valida, string valida0)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -127,7 +133,7 @@ namespace SoftwayWeb.Controllers
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; errMes = helper.getErrMsgFromResponse(response);
helper.SetStringValue("errMsg", errMes); helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error"); return RedirectToAction("Error");
} }

View File

@ -34,6 +34,7 @@ namespace SoftwayWeb.Controllers
public IActionResult Elimina(string id) public IActionResult Elimina(string id)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
@ -74,7 +75,7 @@ namespace SoftwayWeb.Controllers
public IActionResult Elimina(GiriConsegnaView model) public IActionResult Elimina(GiriConsegnaView model)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))

View File

@ -38,6 +38,7 @@ namespace SoftwayWeb.Controllers
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
helper.ClearFormatedKey("errMsg");
string url = apiUrl + "Login/loginMagazzino"; string url = apiUrl + "Login/loginMagazzino";
Uri baseAddress = new Uri(url); Uri baseAddress = new Uri(url);
client.BaseAddress = baseAddress; client.BaseAddress = baseAddress;
@ -90,7 +91,7 @@ namespace SoftwayWeb.Controllers
{ {
helper = new SessionHelper(this); helper = new SessionHelper(this);
helper.ClearFormatedKey("tok"); helper.ClearFormatedKey("tok");
helper.ClearFormatedKey("errMsg");
return RedirectToAction("Login","Login"); return RedirectToAction("Login","Login");
} }

View File

@ -60,5 +60,11 @@ namespace SoftwayWeb
{ {
_controller.HttpContext.Session.Remove(formatedKey); _controller.HttpContext.Session.Remove(formatedKey);
} }
public string getErrMsgFromResponse(HttpResponseMessage response)
{
string msg=string.Empty;
msg = response.ToString();
return msg;
}
} }
} }