diff --git a/Controllers/ProgressiviController.cs b/Controllers/ProgressiviController.cs new file mode 100644 index 0000000..61aaec1 --- /dev/null +++ b/Controllers/ProgressiviController.cs @@ -0,0 +1,163 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using System.Diagnostics; +using System.Text; +using VirtualTask.Models; +using X.PagedList; + +namespace VirtualTask.Controllers +{ + public class ProgressiviController : Controller + { + + string apiUrl = string.Empty; + string urlBase = string.Empty; + string token = string.Empty; + string tenant = string.Empty; + string errMes = string.Empty; + + HttpClient client; + + public ProgressiviController() + { + 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 + "progressiviList"; + 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.tipo_prog.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.tipo_prog) + .ToPagedList(page ?? 1, pageSize); + + return View(shortLinks); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + + #endregion INDEX + + #region EDTI + + public IActionResult Edit(string id) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "progressiviList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + Progressivo prog = new Progressivo(); + + List modelList = new List(); + + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + prog = modelList.Where(x => x.tipo_prog.Equals(id)).First(); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + + return View(); + } + + [HttpPost] + public IActionResult Edit(Progressivo prog) + { + SessionHelper helper = new SessionHelper(this); + + token = helper.GetStringValue("tok"); + tenant = helper.GetStringValue("tenant"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Index", "Login"); + } + prog.azienda = tenant; + + apiUrl = helper.GetStringValue("apiUrl"); + urlBase = apiUrl + "progressivo/mod"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + string data = JsonConvert.SerializeObject(prog); + StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = client.PostAsync(baseAddress, content).Result; + + if (response.IsSuccessStatusCode) + { + return RedirectToAction("Index"); + } + + return View(prog); + } + + #endregion EDIT + + [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/Progressivi/Edit.cshtml b/Views/Progressivi/Edit.cshtml new file mode 100644 index 0000000..d7fce86 --- /dev/null +++ b/Views/Progressivi/Edit.cshtml @@ -0,0 +1,43 @@ +@model VirtualTask.Models.Progressivo + +@{ + ViewData["Title"] = "Edit"; +} + +

Modifica progressivo

+ +

Progressivo

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

Progressivi

+ +

+ @*Create New*@ +

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

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

+} + + + + + + + + + + +@foreach (var item in Model) { + + + + + + +} + +
+ @*@Html.DisplayNameFor(model => model.azienda)*@ + Azienda + + @*@Html.DisplayNameFor(model => model.tipo_prog)*@ + Tipo progressivo + + @*@Html.DisplayNameFor(model => model.val_prog)*@ + Valore progressivo +
+ @Html.DisplayFor(modelItem => item.azienda) + + @Html.DisplayFor(modelItem => item.tipo_prog) + + @Html.DisplayFor(modelItem => item.val_prog) + + @Html.ActionLink("Modifica", "Edit", new { id=item.tipo_prog }) @*|*@ + @*@Html.ActionLink("Dettaglio", "Details", new { /* id=item.PrimaryKey */ }) |*@ + @*@Html.ActionLink("Elimina", "Delete", new { /* id=item.PrimaryKey */ })*@ +
+
+ diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 243d0c6..984f855 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -40,6 +40,9 @@ + diff --git a/Views/Tecnici/Details.cshtml b/Views/Tecnici/Details.cshtml index 74e5d23..5332263 100644 --- a/Views/Tecnici/Details.cshtml +++ b/Views/Tecnici/Details.cshtml @@ -46,28 +46,28 @@
@Html.DisplayFor(model => model.tcpwd)
-
@Html.DisplayNameFor(model => model.tccoor)
-
@Html.DisplayFor(model => model.tccoor)
-
@Html.DisplayNameFor(model => model.tccono)
-
@Html.DisplayFor(model => model.tccono)
-
@Html.DisplayNameFor(model => model.tccost)
-
@Html.DisplayFor(model => model.tccost)
-
@Html.DisplayNameFor(model => model.tccofe)
-
@Html.DisplayFor(model => model.tccofe)