From c0154565eefd272d947056a3d0152c073965d1c0 Mon Sep 17 00:00:00 2001 From: michele Date: Thu, 26 Oct 2023 10:50:02 +0200 Subject: [PATCH] Michele: DATI AZIENDA controller + model + view --- Controllers/AziendaRifController.cs | 317 ++++++++++++++++++++++++++++ Views/Anag/Index.cshtml | 19 +- Views/AziendaRif/Create.cshtml | 58 +++++ Views/AziendaRif/Delete.cshtml | 56 +++++ Views/AziendaRif/Details.cshtml | 54 +++++ Views/AziendaRif/Edit.cshtml | 58 +++++ Views/AziendaRif/Index.cshtml | 93 ++++++++ Views/Shared/_Layout.cshtml | 3 + 8 files changed, 648 insertions(+), 10 deletions(-) create mode 100644 Controllers/AziendaRifController.cs create mode 100644 Views/AziendaRif/Create.cshtml create mode 100644 Views/AziendaRif/Delete.cshtml create mode 100644 Views/AziendaRif/Details.cshtml create mode 100644 Views/AziendaRif/Edit.cshtml create mode 100644 Views/AziendaRif/Index.cshtml diff --git a/Controllers/AziendaRifController.cs b/Controllers/AziendaRifController.cs new file mode 100644 index 0000000..34626d4 --- /dev/null +++ b/Controllers/AziendaRifController.cs @@ -0,0 +1,317 @@ +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.Diagnostics; +using System.Text; +using VirtualTask.Models; +using X.PagedList; + +namespace VirtualTask.Controllers +{ + public class AziendaRifController : Controller + { + string apiUrl = string.Empty; + string urlBase = string.Empty; + string token = string.Empty; + string tenant = string.Empty; + string errMes = string.Empty; + + HttpClient client; + + public AziendaRifController() + { + client = new HttpClient(); + } + + #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("Index", "Login"); + + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "aziendeList"; + 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); + + if (!string.IsNullOrEmpty(searchString)) + { + modelList = modelList.Where(s => s.picodtec.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.picodtec) + .ToPagedList(page ?? 1, pageSize); + + return View(shortLinks); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMes", errMes); + return RedirectToAction("Error"); + } + } + + #endregion INDEX + + #region CREATE + + public IActionResult Create() + { + return View(); + } + + [HttpPost] + public IActionResult Create(AziendaRif model) + { + SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + tenant = helper.GetStringValue("tenant"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Index", "Login"); + } + + model.pirifazi = tenant; + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "azienda/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 CREATE + + #region DETAILS + + public IActionResult Details(string id) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "aziendeList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + AziendaRif aziRif = new AziendaRif(); + + List modelList = new List(); + + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + aziRif = modelList.Where(x => x.picodtec.Equals(id)).First(); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + + return View(modelList); + } + + #endregion DETAILS + + #region EDIT + + public IActionResult Edit(string id) + { + SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "aziendeList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + AziendaRif aziRif = new AziendaRif(); + + List modelList = new List(); + + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + aziRif = modelList.Where(x => x.picodtec.Equals(id)).First(); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + + return View(aziRif); + } + + [HttpPost] + public IActionResult Edit(AziendaRif model) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + tenant = helper.GetStringValue("tenant"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Index", "Login"); + } + + model.pirifazi = token; + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "azienda/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 EDIT + + #region DELETE + + [HttpGet] + public IActionResult Delete(string id) + { + SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "azienda/del"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + AziendaRif aziRif = new AziendaRif(); + List modelList = new List(); + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + aziRif = modelList.Where(x => x.picodtec.Equals(id)).First(); + + return View(aziRif); + } + 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"); + urlBase = apiUrl + "azienda/del" + "codice=" + 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 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/Views/Anag/Index.cshtml b/Views/Anag/Index.cshtml index 5f55c18..d60d064 100644 --- a/Views/Anag/Index.cshtml +++ b/Views/Anag/Index.cshtml @@ -118,15 +118,14 @@ \ No newline at end of file diff --git a/Views/AziendaRif/Create.cshtml b/Views/AziendaRif/Create.cshtml new file mode 100644 index 0000000..18ef6ae --- /dev/null +++ b/Views/AziendaRif/Create.cshtml @@ -0,0 +1,58 @@ +@model VirtualTask.Models.AziendaRif + +@{ + ViewData["Title"] = "Create"; +} + +

Nuovo

+ + +
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/Views/AziendaRif/Delete.cshtml b/Views/AziendaRif/Delete.cshtml new file mode 100644 index 0000000..c2b31e4 --- /dev/null +++ b/Views/AziendaRif/Delete.cshtml @@ -0,0 +1,56 @@ +@model VirtualTask.Models.AziendaRif + +@{ + ViewData["Title"] = "Delete"; +} + +

Elimina

+ +

Vuoi eliminare l'elemento?

+
+ +
+
+
+ @Html.DisplayNameFor(model => model.piazihoc) +
+
+ @Html.DisplayFor(model => model.piazihoc) +
+
+ @Html.DisplayNameFor(model => model.picodtec) +
+
+ @Html.DisplayFor(model => model.picodtec) +
+
+ @Html.DisplayNameFor(model => model.pirifazi) +
+
+ @Html.DisplayFor(model => model.pirifazi) +
+
+ @Html.DisplayNameFor(model => model.pinomede) +
+
+ @Html.DisplayFor(model => model.pinomede) +
+
+ @Html.DisplayNameFor(model => model.pilogurl) +
+
+ @Html.DisplayFor(model => model.pilogurl) +
+
+ @Html.DisplayNameFor(model => model.pitextin) +
+
+ @Html.DisplayFor(model => model.pitextin) +
+
+ +
+ | + Torna indietro +
+
diff --git a/Views/AziendaRif/Details.cshtml b/Views/AziendaRif/Details.cshtml new file mode 100644 index 0000000..1bc1c79 --- /dev/null +++ b/Views/AziendaRif/Details.cshtml @@ -0,0 +1,54 @@ +@model VirtualTask.Models.AziendaRif + +@{ + ViewData["Title"] = "Details"; +} + +

Dettaglio

+ +
+ +
+
+
+ @Html.DisplayNameFor(model => model.piazihoc) +
+
+ @Html.DisplayFor(model => model.piazihoc) +
+
+ @Html.DisplayNameFor(model => model.picodtec) +
+
+ @Html.DisplayFor(model => model.picodtec) +
+
+ @Html.DisplayNameFor(model => model.pirifazi) +
+
+ @Html.DisplayFor(model => model.pirifazi) +
+
+ @Html.DisplayNameFor(model => model.pinomede) +
+
+ @Html.DisplayFor(model => model.pinomede) +
+
+ @Html.DisplayNameFor(model => model.pilogurl) +
+
+ @Html.DisplayFor(model => model.pilogurl) +
+
+ @Html.DisplayNameFor(model => model.pitextin) +
+
+ @Html.DisplayFor(model => model.pitextin) +
+
+
+
+ @*@Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) |*@ + Torna indietro +
diff --git a/Views/AziendaRif/Edit.cshtml b/Views/AziendaRif/Edit.cshtml new file mode 100644 index 0000000..2dd4504 --- /dev/null +++ b/Views/AziendaRif/Edit.cshtml @@ -0,0 +1,58 @@ +@model VirtualTask.Models.AziendaRif + +@{ + ViewData["Title"] = "Edit"; +} + +

Modifica

+ + +
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/Views/AziendaRif/Index.cshtml b/Views/AziendaRif/Index.cshtml new file mode 100644 index 0000000..a69a82e --- /dev/null +++ b/Views/AziendaRif/Index.cshtml @@ -0,0 +1,93 @@ +@model IPagedList +@using X.PagedList; +@using X.PagedList.Mvc.Core; +@using X.PagedList.Web.Common; + +@{ + ViewData["Title"] = "Index"; +} + +

Dati azienda

+ +@using (Html.BeginForm()) +{ +

+ Cerca per tecnico: @Html.TextBox("SearchString") + +

+} + + + + + + + + + + + + + + @foreach (var item in Model) { + + + + + + + + + + } + +
+ @*@Html.DisplayNameFor(model => model.piazihoc)*@ + Azienda + + @*@Html.DisplayNameFor(model => model.picodtec)*@ + Codice tecnico + + @*@Html.DisplayNameFor(model => model.pirifazi)*@ + Azienda riferimento + + @*@Html.DisplayNameFor(model => model.pinomede)*@ + Azienda collegata + + @*@Html.DisplayNameFor(model => model.pilogurl)*@ + Url logo + + @*@Html.DisplayNameFor(model => model.pitextin)*@ + Testo rapportino +
+ @Html.DisplayFor(modelItem => item.piazihoc) + + @Html.DisplayFor(modelItem => item.picodtec) + + @Html.DisplayFor(modelItem => item.pirifazi) + + @Html.DisplayFor(modelItem => item.pinomede) + + @Html.DisplayFor(modelItem => item.pilogurl) + + @Html.DisplayFor(modelItem => item.pitextin) + + @Html.ActionLink("Modifica", "Edit", new { id=item.picodtec }) | + @Html.ActionLink("Dettaglio", "Details", new { id=item.picodtec }) | + @Html.ActionLink("Elimina", "Delete", new { id=item.picodtec }) +
+
+ diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 984f855..5f9c82b 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -43,6 +43,9 @@ +