diff --git a/Controllers/GiriChiudiController.cs b/Controllers/GiriChiudiController.cs new file mode 100644 index 0000000..6faa2dc --- /dev/null +++ b/Controllers/GiriChiudiController.cs @@ -0,0 +1,102 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using SoftwayWeb.Models; +using System.Diagnostics; +using System.Text; + +namespace SoftwayWeb.Controllers +{ + public class GiriChiudiController : Controller + { + string apiUrl = string.Empty; + string urlBase = string.Empty; + string errMes = string.Empty; + private readonly IConfiguration _configuration; + HttpClient client; + public GiriChiudiController(IConfiguration configuration) + { + client = new HttpClient(); + _configuration = configuration; + var key = _configuration["ApplicationInsights:rootUrlApi"]; + apiUrl = key; + } + + // GET: GiriChiudiController + public ActionResult Index() + { + return View(); + } + public ActionResult Chiudi(string id) + { + SessionHelper helper = new SessionHelper(this); + GiriConsegnaView model = new GiriConsegnaView(); + List lst=new List(); + + //https://api.poloinformatico.it:8000/api/Giri/listaGiri?aperto=true + + + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "Giri/listaGiri?aperto=true"; + 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; + lst = JsonConvert.DeserializeObject>(data); + model = lst.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 ActionResult Chiudi(GiriConsegnaView model) + { + //https://api.poloinformatico.it:8000/api/Giri/closeGiro?serialeGiro=0000000002&bancaliRecuperati=11&importoRecuperato=100 + SessionHelper helper = new SessionHelper(this); + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "Giri/closeGiro?serialeGiro="; + urlBase = urlBase + model.SerialeGiro; + urlBase = urlBase + "&bancaliRecuperati="; + urlBase = urlBase + model.BancaliRecuperati; + urlBase = urlBase + "&importoRecuperato="; + urlBase = urlBase + model.ImportoRecuperato; + 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 }); + } + } +} diff --git a/Models/ErrorViewModel.cs b/Models/ErrorViewModel.cs index 0b38ab4..e94776f 100644 --- a/Models/ErrorViewModel.cs +++ b/Models/ErrorViewModel.cs @@ -5,5 +5,7 @@ namespace SoftwayWeb.Models public string? RequestId { get; set; } public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + public string? ErrMsg { get; set; } } } \ No newline at end of file diff --git a/Models/GiriConsegnaView.cs b/Models/GiriConsegnaView.cs index ff39425..840b13b 100644 --- a/Models/GiriConsegnaView.cs +++ b/Models/GiriConsegnaView.cs @@ -19,13 +19,14 @@ namespace SoftwayWeb.Models [Display(Name = "Bancali caricati")] public int? BancaliCaricati { get; set; } - [Display(Name = "Bancali recuperati")] + + [Display(Name = "Bancali recuperati"), Required(ErrorMessage = "Bancali recuperati obbligatori")] public int? BancaliRecuperati { get; set; } [Display(Name = "Importo da recuperare"), System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")] public decimal? ImportoDaRecuperare { get; set; } - [Display(Name = "Importo recuperato"),System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")] + [Display(Name = "Importo recuperato"),System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)"), Required(ErrorMessage = "Importo recuperato obbligatorio")] public decimal? ImportoRecuperato { get; set; } [Display(Name = "Data chiusura")] diff --git a/Views/GiriChiudi/Chiudi.cshtml b/Views/GiriChiudi/Chiudi.cshtml new file mode 100644 index 0000000..8790a91 --- /dev/null +++ b/Views/GiriChiudi/Chiudi.cshtml @@ -0,0 +1,52 @@ +@model SoftwayWeb.Models.GiriConsegnaView +@{ + ViewData["Title"] = "Area riservata"; + Layout = "~/Views/Shared/_LayoutAreaRis.cshtml"; +} +
+
+
+
+
+
+
+ @Html.DisplayNameFor(model => model.SerialeGiro) @Html.DisplayFor(model => model.SerialeGiro) +
+
+ @Html.DisplayNameFor(model => model.Autista) @Html.DisplayFor(model => model.CodAutista)-@Html.DisplayFor(model => model.Autista) +
+
+ @Html.DisplayNameFor(model => model.DataGiro) @Html.DisplayFor(model => model.DataGiro) +
+
+ @Html.DisplayNameFor(model => model.BancaliCaricati) @Html.DisplayFor(model => model.BancaliCaricati) +
+
+ @Html.DisplayNameFor(model => model.ImportoDaRecuperare) @Html.DisplayFor(model => model.ImportoDaRecuperare) +
+
+
+ + +
+
+
+ + +
+ + + @Html.HiddenFor(x => x.SerialeGiro) + @Html.HiddenFor(x => x.CodAutista) + @Html.HiddenFor(x => x.Autista) + @Html.HiddenFor(x => x.DataGiro) + @Html.HiddenFor(x => x.BancaliCaricati) + @Html.HiddenFor(x => x.ImportoDaRecuperare) +
+
+
+
+