From b0ddd70db6063ecc9984749b76911655728930ed Mon Sep 17 00:00:00 2001 From: michele Date: Thu, 27 Feb 2025 15:10:29 +0100 Subject: [PATCH] Michele: Magazzini. model, controller con crud, pagine web --- Controllers/ArticoliController.cs | 6 +- Controllers/MagazziniVTController.cs | 338 +++++++++++++++++++++++ Models/MagazziniVT.cs | 15 + Views/Articoli/Index.cshtml | 263 ++++-------------- Views/MagazziniVT/Create.cshtml | 95 +++++++ Views/MagazziniVT/Delete.cshtml | 33 +++ Views/MagazziniVT/Details.cshtml | 34 +++ Views/MagazziniVT/Edit.cshtml | 37 +++ Views/MagazziniVT/Index.cshtml | 103 +++++++ Views/Shared/_LayoutAreaRiservata.cshtml | 1 + 10 files changed, 718 insertions(+), 207 deletions(-) create mode 100644 Controllers/MagazziniVTController.cs create mode 100644 Models/MagazziniVT.cs create mode 100644 Views/MagazziniVT/Create.cshtml create mode 100644 Views/MagazziniVT/Delete.cshtml create mode 100644 Views/MagazziniVT/Details.cshtml create mode 100644 Views/MagazziniVT/Edit.cshtml create mode 100644 Views/MagazziniVT/Index.cshtml diff --git a/Controllers/ArticoliController.cs b/Controllers/ArticoliController.cs index 729ebd6..45f07b0 100644 --- a/Controllers/ArticoliController.cs +++ b/Controllers/ArticoliController.cs @@ -161,7 +161,7 @@ namespace VirtualTask.Controllers client = new HttpClient(); client.BaseAddress = baseAddress; - Articoli chiusura = new Articoli(); + Articoli articolo = new Articoli(); List modelList = new List(); @@ -171,7 +171,7 @@ namespace VirtualTask.Controllers { string data = response.Content.ReadAsStringAsync().Result; modelList = JsonConvert.DeserializeObject>(data); - chiusura = modelList.Where(x => x.SlCodice.Equals(id)).First(); + articolo = modelList.Where(x => x.SlCodice.Equals(id)).First(); } else { @@ -180,7 +180,7 @@ namespace VirtualTask.Controllers return RedirectToAction("Error"); } - return View(chiusura); + return View(articolo); } #endregion DETAIL diff --git a/Controllers/MagazziniVTController.cs b/Controllers/MagazziniVTController.cs new file mode 100644 index 0000000..f94c205 --- /dev/null +++ b/Controllers/MagazziniVTController.cs @@ -0,0 +1,338 @@ +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.Diagnostics; +using System.Text; +using VirtualTask.Models; +using X.PagedList; + +namespace VirtualTask.Controllers +{ + public class MagazziniVTController : Controller + { + string apiUrl = string.Empty; + string urlBase = string.Empty; + string token = string.Empty; + string tenant = string.Empty; + string errMes = string.Empty; + string admin = string.Empty; + string time_sheet = string.Empty; + HttpClient client; + + private readonly IConfiguration _configuration; + + public MagazziniVTController(IConfiguration configuration) + { + client = new HttpClient(); + _configuration = configuration; + var key = _configuration["ApplicationInsights:rootUrlApi"]; + apiUrl = key; + } + + #region INDEX + + public IActionResult Index(string searchString, int? page = 1) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login2", "Login"); + } + + apiUrl = helper.GetStringValue("apiUrl"); + admin = helper.GetStringValue("admin"); + ViewBag.Admin = admin; + + urlBase = apiUrl + "MagazziniVTList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + List modelList = new List(); + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + modelList = modelList.Where(x => x.DataObso == null).ToList(); + + if (!string.IsNullOrEmpty(searchString)) + { + modelList = modelList.Where(s => s.Mgdesmag.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.Mgcodmag) + .ToPagedList(page ?? 1, pageSize); + + return View(shortLinks); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + #endregion + + #region CREATE + + public IActionResult Create() + { + SessionHelper helper = new SessionHelper(this); + admin = helper.GetStringValue("admin"); + ViewBag.Admin = admin; + + return View(); + } + + [HttpPost] + public IActionResult Create(MagazziniVT model) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + tenant = helper.GetStringValue("tenant"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login2", "Login"); + } + + model.Azienda = tenant; + apiUrl = helper.GetStringValue("apiUrl"); + admin = helper.GetStringValue("admin"); + ViewBag.Admin = admin; + urlBase = apiUrl + "magazziniVT/add"; + urlBase = urlBase + "?token=" + token; + 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"); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + + #endregion + + #region DETAILS + public IActionResult Details(string id) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + apiUrl = helper.GetStringValue("apiUrl"); + admin = helper.GetStringValue("admin"); + ViewBag.Admin = admin; + urlBase = apiUrl + "magazziniVTList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + MagazziniVT magazzino = new MagazziniVT(); + + List modelList = new List(); + + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + magazzino = modelList.Where(x => x.Mgcodmag.Equals(id)).First(); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + + return View(magazzino); + } + #endregion + + #region EDIT + public IActionResult Edit(string id) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + apiUrl = helper.GetStringValue("apiUrl"); + admin = helper.GetStringValue("admin"); + ViewBag.Admin = admin; + urlBase = apiUrl + "magazziniVTList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + MagazziniVT ele = new MagazziniVT(); + + List modelList = new List(); + + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + var el = modelList.Where(t => t.Mgcodmag.Equals(id)).First(); + ele = el; + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + + return View(ele); + } + + [HttpPost] + public IActionResult Edit(MagazziniVT model) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + tenant = helper.GetStringValue("tenant"); + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Index", "Login"); + } + model.Azienda = tenant; + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "magazziniVT/mod"; + urlBase = urlBase + "?token=" + token; + 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"); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + #endregion + + #region DELETE + [HttpGet] + public IActionResult Delete(string id) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + apiUrl = helper.GetStringValue("apiUrl"); + admin = helper.GetStringValue("admin"); + ViewBag.Admin = admin; + urlBase = apiUrl + "magazziniVTList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + MagazziniVT elem = new MagazziniVT(); + List modelList = new List(); + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + elem = modelList.Where(t => t.Mgcodmag.Equals(id)).First(); + return View(elem); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + + [HttpPost, ActionName("DeleteConfirmed")] + public IActionResult DeleteConfirmed(string id) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + + apiUrl = helper.GetStringValue("apiUrl"); + admin = helper.GetStringValue("admin"); + ViewBag.Admin = admin; + urlBase = apiUrl + "magazziniVT/del?" + "magCodice=" + id + "&"; + urlBase = urlBase + "token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + string data = JsonConvert.SerializeObject(id); + 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"); + } + } + #endregion + + [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/MagazziniVT.cs b/Models/MagazziniVT.cs new file mode 100644 index 0000000..f31509b --- /dev/null +++ b/Models/MagazziniVT.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace VirtualTask.Models +{ + public class MagazziniVT + { + [Display(Name = "Azienda")] + public string? Azienda { get; set; } + [Display(Name = "Cod. Magazzino")] + public string? Mgcodmag { get; set; } + [Display(Name = "Descrizone")] + public string? Mgdesmag { get; set; } + public DateTime? DataObso { get; set; } + } +} diff --git a/Views/Articoli/Index.cshtml b/Views/Articoli/Index.cshtml index cbf3296..e5462be 100644 --- a/Views/Articoli/Index.cshtml +++ b/Views/Articoli/Index.cshtml @@ -55,55 +55,54 @@ - @foreach (var item in Model) - { - - - @Html.DisplayFor(modelItem => item.SlCodice) - - - @Html.DisplayFor(modelItem => item.ArDesArt) - - - @Html.DisplayFor(modelItem => item.SlCodMag) - - - @Html.DisplayFor(modelItem => item.SlQtAper) - - - @Html.DisplayFor(modelItem => item.LiPrezzo) - - @Html.HiddenFor(modelItem => item.Azienda) - @Html.HiddenFor(modelItem => item.AmCodice) - @Html.HiddenFor(modelItem => item.LoCodice) - @Html.HiddenFor(modelItem => item.LiCodLis) - @Html.HiddenFor(modelItem => item.LiCodArt) - @Html.HiddenFor(modelItem => item.LiDatAtt) - @Html.HiddenFor(modelItem => item.LiQuanti) - @Html.HiddenFor(modelItem => item.LiScont1) - @Html.HiddenFor(modelItem => item.LiScont2) - @Html.HiddenFor(modelItem => item.LiScont3) - @Html.HiddenFor(modelItem => item.LiScont4) - @Html.HiddenFor(modelItem => item.Gest_Matr) - @Html.HiddenFor(modelItem => item.Gest_Lotti) - @Html.HiddenFor(modelItem => item.Desc_sup) + @foreach (var item in Model) + { + + + @Html.DisplayFor(modelItem => item.SlCodice) + + + @Html.DisplayFor(modelItem => item.ArDesArt) + + + @Html.DisplayFor(modelItem => item.SlCodMag) + + + @Html.DisplayFor(modelItem => item.SlQtAper) + + + @Html.DisplayFor(modelItem => item.LiPrezzo) + + @Html.HiddenFor(modelItem => item.Azienda) + @Html.HiddenFor(modelItem => item.AmCodice) + @Html.HiddenFor(modelItem => item.LoCodice) + @Html.HiddenFor(modelItem => item.LiCodLis) + @Html.HiddenFor(modelItem => item.LiCodArt) + @Html.HiddenFor(modelItem => item.LiDatAtt) + @Html.HiddenFor(modelItem => item.LiQuanti) + @Html.HiddenFor(modelItem => item.LiScont1) + @Html.HiddenFor(modelItem => item.LiScont2) + @Html.HiddenFor(modelItem => item.LiScont3) + @Html.HiddenFor(modelItem => item.LiScont4) + @Html.HiddenFor(modelItem => item.Gest_Matr) + @Html.HiddenFor(modelItem => item.Gest_Lotti) + @Html.HiddenFor(modelItem => item.Desc_sup) - - - Modifica - - | - - Dettaglio - - | - - Elimina - - - - - } + + + Modifica + + | + + Dettaglio + + | + + Elimina + + + + } @@ -112,162 +111,18 @@
- -@* @model IEnumerable - -@{ - ViewData["Title"] = "Index"; -} - -

Index

- -

- Create New -

- - - - - - - - - - - - - - - - - - - - - - - - - - -@foreach (var item in Model) { - - - - - - - - - - - - - - - - - - - - - - -} - -
- @Html.DisplayNameFor(model => model.Azienda) - - @Html.DisplayNameFor(model => model.SlCodice) - - @Html.DisplayNameFor(model => model.ArDesArt) - - @Html.DisplayNameFor(model => model.SlCodMag) - - @Html.DisplayNameFor(model => model.SlQtAper) - - @Html.DisplayNameFor(model => model.AmCodice) - - @Html.DisplayNameFor(model => model.LoCodice) - - @Html.DisplayNameFor(model => model.LiCodLis) - - @Html.DisplayNameFor(model => model.LiCodArt) - - @Html.DisplayNameFor(model => model.LiDatAtt) - - @Html.DisplayNameFor(model => model.LiQuanti) - - @Html.DisplayNameFor(model => model.LiPrezzo) - - @Html.DisplayNameFor(model => model.LiScont1) - - @Html.DisplayNameFor(model => model.LiScont2) - - @Html.DisplayNameFor(model => model.LiScont3) - - @Html.DisplayNameFor(model => model.LiScont4) - - @Html.DisplayNameFor(model => model.Gest_Matr) - - @Html.DisplayNameFor(model => model.Gest_Lotti) - - @Html.DisplayNameFor(model => model.Desc_sup) -
- @Html.DisplayFor(modelItem => item.Azienda) - - @Html.DisplayFor(modelItem => item.SlCodice) - - @Html.DisplayFor(modelItem => item.ArDesArt) - - @Html.DisplayFor(modelItem => item.SlCodMag) - - @Html.DisplayFor(modelItem => item.SlQtAper) - - @Html.DisplayFor(modelItem => item.AmCodice) - - @Html.DisplayFor(modelItem => item.LoCodice) - - @Html.DisplayFor(modelItem => item.LiCodLis) - - @Html.DisplayFor(modelItem => item.LiCodArt) - - @Html.DisplayFor(modelItem => item.LiDatAtt) - - @Html.DisplayFor(modelItem => item.LiQuanti) - - @Html.DisplayFor(modelItem => item.LiPrezzo) - - @Html.DisplayFor(modelItem => item.LiScont1) - - @Html.DisplayFor(modelItem => item.LiScont2) - - @Html.DisplayFor(modelItem => item.LiScont3) - - @Html.DisplayFor(modelItem => item.LiScont4) - - @Html.DisplayFor(modelItem => item.Gest_Matr) - - @Html.DisplayFor(modelItem => item.Gest_Lotti) - - @Html.DisplayFor(modelItem => item.Desc_sup) - - @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | - @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | - @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) -
- *@ \ No newline at end of file + \ No newline at end of file diff --git a/Views/MagazziniVT/Create.cshtml b/Views/MagazziniVT/Create.cshtml new file mode 100644 index 0000000..0c66aee --- /dev/null +++ b/Views/MagazziniVT/Create.cshtml @@ -0,0 +1,95 @@ +@model VirtualTask.Models.MagazziniVT + +@{ + ViewData["Title"] = "Nuovo magazzino"; + Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml"; +} + +
+
+
+
+
+
+
+ +
 
+
+
+ + +
+
 
+
+
+ + +
+ +
 
+ + @Html.HiddenFor(x => x.Azienda) + @Html.HiddenFor(x => x.DataObso) +
+
+
+ @section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } + } +
+
+
+@* @model VirtualTask.Models.MagazziniVT + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

MagazziniVT

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} + *@ \ No newline at end of file diff --git a/Views/MagazziniVT/Delete.cshtml b/Views/MagazziniVT/Delete.cshtml new file mode 100644 index 0000000..5b3fd34 --- /dev/null +++ b/Views/MagazziniVT/Delete.cshtml @@ -0,0 +1,33 @@ +@model VirtualTask.Models.MagazziniVT + +@{ + ViewData["Title"] = "Elimina"; + Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml"; +} + +
+
+
+
+
+
+ @Html.DisplayNameFor(model => model.Mgcodmag)   @Html.DisplayFor(model => model.Mgcodmag) +
+
+ @Html.DisplayNameFor(model => model.Mgdesmag)   @Html.DisplayFor(model => model.Mgdesmag) +
+ @Html.HiddenFor(x => x.Azienda) + @Html.HiddenFor(model => model.DataObso) +
+
 
+
+
+ + model.Mgcodmag) name="id" /> + Torna alla lista +
+
+
+
+
+
\ No newline at end of file diff --git a/Views/MagazziniVT/Details.cshtml b/Views/MagazziniVT/Details.cshtml new file mode 100644 index 0000000..7df89b4 --- /dev/null +++ b/Views/MagazziniVT/Details.cshtml @@ -0,0 +1,34 @@ +@model VirtualTask.Models.MagazziniVT + +@{ + ViewData["Title"] = "Dettaglio"; + Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml"; +} + +
+
+
+
+
+
+ @Html.DisplayNameFor(model => model.Mgcodmag)   @Html.DisplayFor(model => model.Mgcodmag) +
+
+ @Html.DisplayNameFor(model => model.Mgdesmag)   @Html.DisplayFor(model => model.Mgdesmag) +
+ @Html.HiddenFor(x => x.Azienda) + @Html.HiddenFor(model => model.DataObso) +
+
 
+
+
+ + model.Mgcodmag) name="id" /> + Torna alla lista +
+
+
+
+
+
+ diff --git a/Views/MagazziniVT/Edit.cshtml b/Views/MagazziniVT/Edit.cshtml new file mode 100644 index 0000000..ef91b00 --- /dev/null +++ b/Views/MagazziniVT/Edit.cshtml @@ -0,0 +1,37 @@ +@model VirtualTask.Models.MagazziniVT + +@{ + ViewData["Title"] = "Modifica magazzino"; + Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml"; +} + +
+
+
+
+
+
+
 
+
+
+ + +
+
 
+
+
+ + +
+
 
+ + @Html.HiddenFor(x => x.Azienda) + @Html.HiddenFor(model => model.DataObso) +
+
+
+
+
diff --git a/Views/MagazziniVT/Index.cshtml b/Views/MagazziniVT/Index.cshtml new file mode 100644 index 0000000..dee3b5f --- /dev/null +++ b/Views/MagazziniVT/Index.cshtml @@ -0,0 +1,103 @@ +@using X.PagedList.Mvc.Core; +@using X.PagedList.Web.Common; +@using X.PagedList; +@model IPagedList + + +@{ + ViewData["Title"] = "Magazzini"; + Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml"; +} + +
+
+
+

+ Crea un nuovo elemento +

+ + @using (Html.BeginForm()) + { +
+
Ricerca
+ + + + + + + +
+ @Html.TextBox("SearchString", null, new { placeholder = "Cerca per descrizione", @class = "agy-form-field require" }) + +   + +
+
+ } + +
+   +
+
+
Articoli
+
+ + + + + + + + + + @foreach (var item in Model) + { + + + + @Html.HiddenFor(modelItem => item.Azienda) + @Html.HiddenFor(modelItem => item.DataObso) + + + + } + +
Cod. MagazzinoDescrizione
+ @Html.DisplayFor(modelItem => item.Mgcodmag) + + @Html.DisplayFor(modelItem => item.Mgdesmag) + + + Modifica + + | + + Dettaglio + + | + + Elimina + +
+
+
+ +
+ +
+
+
\ No newline at end of file diff --git a/Views/Shared/_LayoutAreaRiservata.cshtml b/Views/Shared/_LayoutAreaRiservata.cshtml index 8eae6a6..4888282 100644 --- a/Views/Shared/_LayoutAreaRiservata.cshtml +++ b/Views/Shared/_LayoutAreaRiservata.cshtml @@ -172,6 +172,7 @@ Purchase:
  • Clienti
  • Impianti
  • Articoli
  • +
  • Magazzini
  • Buono intervento
  • Chiamate
  • Progressivi