diff --git a/Controllers/GiriController.cs b/Controllers/GiriController.cs index 1259472..4983a7f 100644 --- a/Controllers/GiriController.cs +++ b/Controllers/GiriController.cs @@ -60,6 +60,15 @@ namespace SoftwayWeb.Controllers { modelList = modelList.Where(x => x.DataGiro.GetValueOrDefault().Date == data.Date).ToList(); } + + //if (aperto) + //{ + // modelList = modelList.Where(x => x.DataChiusura == null).ToList(); + //} + //else + //{ + // modelList = modelList.Where(x => x.DataChiusura != null).ToList(); + //} //var shortList = modelList.ToPagedList(); return View(modelList); } diff --git a/Controllers/GiriEliminaController.cs b/Controllers/GiriEliminaController.cs new file mode 100644 index 0000000..7636673 --- /dev/null +++ b/Controllers/GiriEliminaController.cs @@ -0,0 +1,105 @@ +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using SoftwayWeb.Models; +using System.Collections.Generic; +using System.Configuration; +using System.Diagnostics; +using System.Text; + +namespace SoftwayWeb.Controllers +{ + public class GiriEliminaController : Controller + { + string apiUrl = string.Empty; + string urlBase = string.Empty; + string errMes = string.Empty; + private readonly IConfiguration _configuration; + HttpClient client; + + public GiriEliminaController(IConfiguration configuration) + { + client = new HttpClient(); + _configuration = configuration; + var key = _configuration["ApplicationInsights:rootUrlApi"]; + apiUrl = key; + } + + public IActionResult Index() + { + return RedirectToAction("index", "Giri"); + } + + public IActionResult Elimina(string id) + { + SessionHelper helper = new SessionHelper(this); + GiriConsegnaView model = new GiriConsegnaView(); + List modelList = new List(); + + apiUrl = helper.GetStringValue("apiUrl"); + //urlBase = apiUrl + "Giri/delGiro"; + 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; + modelList = JsonConvert.DeserializeObject>(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, ActionName("Elimina")] + public IActionResult Elimina(GiriConsegnaView model) + { + SessionHelper helper = new SessionHelper(this); + + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "Giri/delGiro?serialeGiro="; + urlBase = urlBase + model.SerialeGiro.TrimEnd(); + urlBase = urlBase + "&autista="; + urlBase = urlBase + model.CodAutista.TrimEnd(); + urlBase = urlBase + "&data="; + urlBase = urlBase + model.DataGiro; + + 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/Views/GiriElimina/Elimina.cshtml b/Views/GiriElimina/Elimina.cshtml new file mode 100644 index 0000000..3cf5fa6 --- /dev/null +++ b/Views/GiriElimina/Elimina.cshtml @@ -0,0 +1,52 @@ +@model SoftwayWeb.Models.GiriConsegnaView +@{ + ViewData["Title"] = "Elimina"; + 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) +
+
+
+
+