diff --git a/Controllers/ChiamateController.cs b/Controllers/ChiamateController.cs index e5de08f..b82938c 100644 --- a/Controllers/ChiamateController.cs +++ b/Controllers/ChiamateController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using System.Diagnostics; using System.Text; using VirtualTask.Models; using X.PagedList; @@ -12,6 +13,7 @@ namespace VirtualTask.Controllers string urlBase = string.Empty; string token = string.Empty; string tenant = string.Empty; + string errMes = string.Empty; HttpClient client; @@ -43,28 +45,35 @@ namespace VirtualTask.Controllers { string data = response.Content.ReadAsStringAsync().Result; modelList = JsonConvert.DeserializeObject>(data); - } - if (!string.IsNullOrEmpty(searchString)) - { - modelList = modelList.Where(s => s.chcodimp.ToUpper().Contains(searchString.ToUpper())).ToList(); + + if (!string.IsNullOrEmpty(searchString)) + { + modelList = modelList.Where(s => s.chcodimp.ToUpper().Contains(searchString.ToUpper())).ToList(); - ViewData["CurrentFilter"] = searchString; + ViewData["CurrentFilter"] = searchString; + } + else + ViewData["CurrentFilter"] = null; + + if (page != null && page < 1) + { + page = 1; + } + + var pageSize = 10; + + var shortLinks = modelList + .OrderByDescending(s => s.chcodimp) + .ToPagedList(page ?? 1, pageSize); + + return View(shortLinks); } else - ViewData["CurrentFilter"] = null; - - if (page != null && page < 1) { - page = 1; + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); } - - var pageSize = 10; - - var shortLinks = modelList - .OrderByDescending(s => s.chcodimp) - .ToPagedList(page ?? 1, pageSize); - - return View(shortLinks); } #endregion INDEX @@ -99,6 +108,12 @@ namespace VirtualTask.Controllers { return RedirectToAction("Index"); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(); } @@ -132,6 +147,12 @@ namespace VirtualTask.Controllers modelList = JsonConvert.DeserializeObject>(data); chiamata = modelList.Where(x => x.chserial.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(chiamata); } @@ -165,6 +186,12 @@ namespace VirtualTask.Controllers modelList = JsonConvert.DeserializeObject>(data); chiamata = modelList.Where(t => t.chserial.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(chiamata); } @@ -191,10 +218,17 @@ namespace VirtualTask.Controllers 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"); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(model); } @@ -226,6 +260,12 @@ namespace VirtualTask.Controllers modelList = JsonConvert.DeserializeObject>(data); chiamata = modelList.Where(x => x.chserial.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(chiamata); } @@ -251,9 +291,23 @@ namespace VirtualTask.Controllers { return RedirectToAction("Index"); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(); } #endregion DELETE + + [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 }); + } } } diff --git a/Controllers/ChiusureController.cs b/Controllers/ChiusureController.cs index 2e604fd..96a1b49 100644 --- a/Controllers/ChiusureController.cs +++ b/Controllers/ChiusureController.cs @@ -78,7 +78,6 @@ namespace VirtualTask.Controllers helper.SetStringValue("errMsg", errMes); return RedirectToAction("Error"); } - } #endregion INDEX @@ -125,8 +124,6 @@ namespace VirtualTask.Controllers helper.SetStringValue("errMsg", errMes); return RedirectToAction("Error"); } - - } #endregion CREATE diff --git a/Controllers/ImpiantiController.cs b/Controllers/ImpiantiController.cs index 05b135c..6975cc5 100644 --- a/Controllers/ImpiantiController.cs +++ b/Controllers/ImpiantiController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using Newtonsoft.Json; +using System.Diagnostics; using System.Drawing.Printing; using System.Text; using VirtualTask.Models; @@ -16,6 +17,7 @@ namespace VirtualTask.Controllers string token = string.Empty; string tenant = string.Empty; string errMes = string.Empty; + HttpClient client; public ImpiantiController() { @@ -46,6 +48,7 @@ namespace VirtualTask.Controllers string data = response.Content.ReadAsStringAsync().Result; modelList = JsonConvert.DeserializeObject>(data); modelList = modelList.Where(s => !string.IsNullOrEmpty(s.imcodimp)).ToList(); + if (!string.IsNullOrEmpty(searchString)) { modelList = modelList.Where(s => s.indirizzo.ToUpper().Contains(searchString.ToUpper())).ToList(); @@ -58,6 +61,7 @@ namespace VirtualTask.Controllers { page = 1; } + var pageSize = 10; var shortLinks = modelList @@ -72,9 +76,6 @@ namespace VirtualTask.Controllers helper.SetStringValue("errMsg", errMes); return RedirectToAction("Error"); } - - - } #endregion INDEX @@ -105,12 +106,17 @@ namespace VirtualTask.Controllers 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"); } - - return View(); + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } } #endregion CREATE @@ -140,6 +146,12 @@ namespace VirtualTask.Controllers modelList = JsonConvert.DeserializeObject>(data); impianto = modelList.Where(x => x.imcodimp.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(impianto); @@ -174,6 +186,13 @@ namespace VirtualTask.Controllers modelList = JsonConvert.DeserializeObject>(data); impianto = modelList.Where(x => x.imcodimp.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + ViewBag.AllStockList = LoadStockitems(); return View(impianto); } @@ -204,7 +223,14 @@ namespace VirtualTask.Controllers { return RedirectToAction("Index"); } - return View(model); + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + + //return View(model); } #endregion EDIT @@ -233,6 +259,12 @@ namespace VirtualTask.Controllers modelList = JsonConvert.DeserializeObject>(data); impianto = modelList.Where(t => t.imcodimp.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(impianto); @@ -258,8 +290,14 @@ namespace VirtualTask.Controllers { return RedirectToAction("Index"); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } - return View(); + //return View(); } @@ -292,5 +330,13 @@ namespace VirtualTask.Controllers } return selectItems; } + + [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 }); + } } } diff --git a/Controllers/Rapp_NewController.cs b/Controllers/Rapp_NewController.cs index a2e9feb..3585b0f 100644 --- a/Controllers/Rapp_NewController.cs +++ b/Controllers/Rapp_NewController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Newtonsoft.Json; +using System.Diagnostics; using System.Text; using VirtualTask.Models; using X.PagedList; @@ -12,6 +13,7 @@ namespace VirtualTask.Controllers string apiUrl = string.Empty; string urlBase = string.Empty; string token = string.Empty; + string errMes = string.Empty; HttpClient client; @@ -43,28 +45,35 @@ namespace VirtualTask.Controllers { string data = response.Content.ReadAsStringAsync().Result; modelList = JsonConvert.DeserializeObject>(data); - } - if (!string.IsNullOrEmpty(searchString)) - { - modelList = modelList.Where(s => s.descrizione_intervento.ToUpper().Contains(searchString.ToUpper())).ToList(); - ViewData["CurrentFilter"] = searchString; + if (!string.IsNullOrEmpty(searchString)) + { + modelList = modelList.Where(s => s.descrizione_intervento.ToUpper().Contains(searchString.ToUpper())).ToList(); + + ViewData["CurrentFilter"] = searchString; + } + else + ViewData["CurrentFilter"] = null; + + if (page != null && page < 1) + { + page = 1; + } + + var pageSize = 10; + + var shortLinks = modelList + .OrderByDescending(s => s.seriale_rapportino) + .ToPagedList(page ?? 1, pageSize); + + return View(shortLinks); } else - ViewData["CurrentFilter"] = null; - - if (page != null && page < 1) { - page = 1; + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); } - - var pageSize = 10; - - var shortLinks = modelList - .OrderByDescending(s => s.seriale_rapportino) - .ToPagedList(page ?? 1, pageSize); - - return View(shortLinks); } #endregion INDEX @@ -98,6 +107,12 @@ namespace VirtualTask.Controllers { return RedirectToAction("Index"); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(); } @@ -131,6 +146,12 @@ namespace VirtualTask.Controllers modelList = JsonConvert.DeserializeObject>(data); rapp = modelList.Where(x => x.seriale_rapportino.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(rapp); } @@ -163,7 +184,12 @@ namespace VirtualTask.Controllers string data = response.Content.ReadAsStringAsync().Result; modelList = JsonConvert.DeserializeObject>(data); rapp = modelList.Where(x => x.seriale_rapportino.Equals(id)).First(); - + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); } return View(rapp); @@ -193,6 +219,12 @@ namespace VirtualTask.Controllers { return RedirectToAction("Index"); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(rapp); } @@ -227,6 +259,12 @@ namespace VirtualTask.Controllers modelList = JsonConvert.DeserializeObject>(data); rapp = modelList.Where(x => x.seriale_rapportino.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(rapp); } @@ -255,6 +293,12 @@ namespace VirtualTask.Controllers { return RedirectToAction("Index"); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(); } @@ -290,5 +334,13 @@ namespace VirtualTask.Controllers return selectItems; } + + [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 }); + } } } diff --git a/Controllers/TecniciController.cs b/Controllers/TecniciController.cs index ad5bff6..41d03d2 100644 --- a/Controllers/TecniciController.cs +++ b/Controllers/TecniciController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using System.Diagnostics; using System.Text; using VirtualTask.Models; using X.PagedList; @@ -14,6 +15,7 @@ namespace VirtualTask.Controllers string urlBase = string.Empty; string token = string.Empty; string tenant = string.Empty; + string errMes = string.Empty; //MF commentati perchè L'Uri viene costruito //Uri baseAddress = new Uri("http://10.0.0.187:8000/api/Polo/tecniciList?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVEVTVCIsImp0aSI6IjA2MzA5MzlmLTBhZDgtNDhkMi04ZTI5LWI3Mjk3N2IyOWM1YiIsInRlbmFudCI6Ik1BUlJPIiwidGNjb2RpY2UiOiJaWlogICAgICAgICAgICAiLCJleHAiOjE3MDE3Njk0NTUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjE5NTUiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CDt3wR6ube4zzNscVG9Qv6bzOnNF6A9-bIZxxjbKmKI"); @@ -56,28 +58,35 @@ namespace VirtualTask.Controllers { string data = response.Content.ReadAsStringAsync().Result; modelList = JsonConvert.DeserializeObject>(data); - } - if (!string.IsNullOrEmpty(searchString)) - { - modelList = modelList.Where(s => s.tcdescri.ToUpper().Contains(searchString.ToUpper())).ToList(); - ViewData["CurrentFilter"] = searchString; + if (!string.IsNullOrEmpty(searchString)) + { + modelList = modelList.Where(s => s.tcdescri.ToUpper().Contains(searchString.ToUpper())).ToList(); + + ViewData["CurrentFilter"] = searchString; + } + else + ViewData["CurrentFilter"] = null; + + if (page != null && page < 1) + { + page = 1; + } + + var pageSize = 10; + + var shortLinks = modelList + .OrderByDescending(s => s.tccodice) + .ToPagedList(page ?? 1, pageSize); + + return View(shortLinks); } else - ViewData["CurrentFilter"] = null; - - if (page != null && page < 1) { - page = 1; + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); } - - var pageSize = 10; - - var shortLinks = modelList - .OrderByDescending(s => s.tccodice) - .ToPagedList(page ?? 1, pageSize); - - return View(shortLinks); } #endregion INDEX @@ -86,7 +95,6 @@ namespace VirtualTask.Controllers public IActionResult Create() { - return View(); } @@ -113,12 +121,17 @@ namespace VirtualTask.Controllers 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"); } - - return View(); + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("ErrMsg", errMes); + return RedirectToAction("Index"); + } } #endregion CREATE @@ -150,6 +163,12 @@ namespace VirtualTask.Controllers modelList = JsonConvert.DeserializeObject>(data); tecnico = modelList.Where(x => x.tccodice.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(tecnico); } @@ -184,6 +203,12 @@ namespace VirtualTask.Controllers tecnico = modelList.Where(x => x.tccodice.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(tecnico); } @@ -252,6 +277,12 @@ namespace VirtualTask.Controllers modelList = JsonConvert.DeserializeObject>(data); tecnico = modelList.Where(x => x.tccodice.Equals(id)).First(); } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } return View(tecnico); } @@ -280,10 +311,22 @@ namespace VirtualTask.Controllers { return RedirectToAction("Index"); } - - return View(); + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } } #endregion DELETE + + [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 }); + } } } diff --git a/Models/Chiamate.cs b/Models/Chiamate.cs index 6348b8c..3b4910e 100644 --- a/Models/Chiamate.cs +++ b/Models/Chiamate.cs @@ -9,16 +9,22 @@ namespace VirtualTask.Models { [Display (Name= "AZIENDA")] public string? chcodazi { get; set; } + [Display(Name = "SERIALE")] public string? chserial { get; set; } + [Display(Name = "CODICE ESERCIZIO")] public string? chcodese { get; set; } + [Display(Name = "TIPO")] public string? chtipo { get; set; } + [Display(Name = "NUMERO")] public double? chnumero { get; set; } + [Display(Name = "DATA")] public DateTime? chdata { get; set; } + public int? chora { get; set; } public int? chmin { get; set; } public int? chopins { get; set; } diff --git a/Models/Chiusure.cs b/Models/Chiusure.cs index 1f96e16..f93825f 100644 --- a/Models/Chiusure.cs +++ b/Models/Chiusure.cs @@ -9,12 +9,13 @@ namespace VirtualTask.Models [Display(Name = "AZIENDA")] public string? cccodazi { get; set; } - [Display(Name = "CODICE")] + [Display(Name = "CODICE"), Required(ErrorMessage = "Inserire codice chiamata")] public string? cccodice { get; set; } - [Display(Name = "DESCRIZIONE")] + [Display(Name = "DESCRIZIONE"), Required(ErrorMessage = "Inserire descrizione")] public string? ccdescr { get; set; } - [Display(Name = "DESC. SUPPLEMENTARE")] + + [Display(Name = "DESC. SUPPLEMENTARE"), Required(ErrorMessage = "Inserire Desc. Supplementare")] public string? ccdessup { get; set; } diff --git a/Models/Impianto.cs b/Models/Impianto.cs index e043852..4cc3af5 100644 --- a/Models/Impianto.cs +++ b/Models/Impianto.cs @@ -5,7 +5,7 @@ namespace VirtualTask.Models { public class Impianto { - [Display(Name = "Codice Impianto")] + [Display(Name = "Codice Impianto"), Required(ErrorMessage = "Inserire codice impianto")] /// Codice Impianto public string? imcodimp { get; set; } @@ -13,7 +13,7 @@ namespace VirtualTask.Models /// Azienda public string? imcodazi { get; set; } - [Display(Name = "Descrizione")] + [Display(Name = "Descrizione"), Required(ErrorMessage = "Inserire descrizione")] /// Descrizione Impianto public string? imdescri { get; set; } diff --git a/Models/Rapp_New.cs b/Models/Rapp_New.cs index 3a264a1..4f04445 100644 --- a/Models/Rapp_New.cs +++ b/Models/Rapp_New.cs @@ -7,7 +7,7 @@ namespace VirtualTask.Models { public class Rapp_New { - [Display(Name = "SERIALE RAPPORTINO")] + [Display(Name = "SERIALE RAPPORTINO"), Required(ErrorMessage = "Inserisci il seriale rapportino")] public string? seriale_rapportino { get; set; } [Display(Name = "TIPO RAPPORTINI")] @@ -16,7 +16,7 @@ namespace VirtualTask.Models [Display(Name = "AZIENDA")] public string? azienda_impianto { get; set; } - [Display(Name = "CODICE IMPIANTO")] + [Display(Name = "CODICE IMPIANTO"), Required(ErrorMessage = "Inserisci codice impianto")] public string? codice_impianto { get; set; } [Display(Name = "AZ. CHIAMATA")] diff --git a/Models/Tecnici.cs b/Models/Tecnici.cs index 62216ff..fc5166d 100644 --- a/Models/Tecnici.cs +++ b/Models/Tecnici.cs @@ -9,16 +9,16 @@ namespace VirtualTask.Models [Display(Name = "AZIENDA")] public string? tccodazi { get; set; } - [Display(Name = "CODICE")] + [Display(Name = "CODICE"), Required(ErrorMessage = "Inserire codice tecnico")] public string? tccodice { get; set; } - [Display(Name = "DESCRIZIONE")] + [Display(Name = "DESCRIZIONE"), Required(ErrorMessage = "Inserire descrizione")] public string? tcdescri { get; set;} [Display(Name = "TELEFONO")] public string? tctelef1 { get; set;} - [Display(Name = "UTENTE")] + [Display(Name = "UTENTE"), Required(ErrorMessage = "Inserire Utente")] public string? tcuser { get; set;} [Display(Name = "PASSWORD")] diff --git a/Views/Chiusure/Create.cshtml b/Views/Chiusure/Create.cshtml index b60cb04..dc8b9ca 100644 --- a/Views/Chiusure/Create.cshtml +++ b/Views/Chiusure/Create.cshtml @@ -21,12 +21,12 @@
- +
-
- +
+