From 1219ed236c571d2dc5ba7df529ef7fbd5876c33b Mon Sep 17 00:00:00 2001 From: michele Date: Tue, 25 Jun 2024 08:58:24 +0200 Subject: [PATCH] Michele: Lista giri --- Controllers/GiriController.cs | 65 +++++++++++++++++ Controllers/LoginController.cs | 15 ++-- Controllers/PortaleController.cs | 29 +++++++- Models/GiriConsegnaView.cs | 34 +++++++++ Program.cs | 52 +++++++++++++- SoftwayWeb.csproj | 1 + Views/Giri/Index.cshtml | 115 +++++++++++++++++++++++++++++++ Views/Portale/Index.cshtml | 21 +++++- 8 files changed, 322 insertions(+), 10 deletions(-) create mode 100644 Controllers/GiriController.cs create mode 100644 Models/GiriConsegnaView.cs create mode 100644 Views/Giri/Index.cshtml diff --git a/Controllers/GiriController.cs b/Controllers/GiriController.cs new file mode 100644 index 0000000..b342eaa --- /dev/null +++ b/Controllers/GiriController.cs @@ -0,0 +1,65 @@ +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using SoftwayWeb.Models; +using X.PagedList; + +namespace SoftwayWeb.Controllers +{ + public class GiriController : Controller + { + string apiUrl = string.Empty; + string urlBase = string.Empty; + string token = string.Empty; + string errMes = string.Empty; + private readonly IConfiguration _configuration; + HttpClient client; + SessionHelper helper; + + public GiriController(IConfiguration configuration) + { + _configuration = configuration; + client = new HttpClient(); + var key = _configuration["ApplicationInsights:rootUrlApi"]; + apiUrl = key; + } + + public IActionResult Index(string? codAutista, DateTime? data, bool aperto = true) + { + helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + string url = apiUrl + "Giri/listaGiri"; + urlBase = url + "?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 dato = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(dato); + + if (!string.IsNullOrEmpty(codAutista)) + { + modelList = modelList.Where(x => x.CodAutista.Contains(codAutista)).ToList(); + + ViewData["CurrentFilter"] = codAutista; + } + else + { + ViewData["CurrentFilter"] = null; + } + //var shortList = modelList.ToPagedList(); + return View(modelList); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + } +} diff --git a/Controllers/LoginController.cs b/Controllers/LoginController.cs index 35465d2..5bedcbe 100644 --- a/Controllers/LoginController.cs +++ b/Controllers/LoginController.cs @@ -36,14 +36,14 @@ namespace SoftwayWeb.Controllers { if (ModelState.IsValid) { - helper = new SessionHelper(this); + SessionHelper helper = new SessionHelper(this); string url = apiUrl + "Login/loginMagazzino"; Uri baseAddress = new Uri(url); client.BaseAddress = baseAddress; //ViewBag.Error = string.Empty; //ViewBag.Admin = string.Empty; - Login_Out loginOutput = new Login_Out(); + Login_Out loginOut = new Login_Out(); string data = JsonConvert.SerializeObject(model); StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(baseAddress, content).Result; @@ -51,14 +51,17 @@ namespace SoftwayWeb.Controllers if (response.IsSuccessStatusCode) { string risultato = response.Content.ReadAsStringAsync().Result; - loginOutput = JsonConvert.DeserializeObject(risultato); - - return RedirectToAction("Index", "Portale"); + loginOut = JsonConvert.DeserializeObject(risultato); + + helper.SetStringValue("tok", loginOut.Tok); + helper.SetStringValue("apiUrl", apiUrl); + + return RedirectToAction("Index", "Portale"); } else { errMes = response.Content.ReadAsStringAsync().Result; - loginOutput = JsonConvert.DeserializeObject(errMes); + loginOut = JsonConvert.DeserializeObject(errMes); return View(); } //return View(model); diff --git a/Controllers/PortaleController.cs b/Controllers/PortaleController.cs index 8d04d40..8100bcd 100644 --- a/Controllers/PortaleController.cs +++ b/Controllers/PortaleController.cs @@ -1,12 +1,39 @@ using Microsoft.AspNetCore.Mvc; +using NuGet.Common; namespace SoftwayWeb.Controllers { public class PortaleController : Controller { + string apiUrl = string.Empty; + string token = string.Empty; + string errMes = string.Empty; + private readonly IConfiguration _configuration; + HttpClient client; + SessionHelper helper; + + public PortaleController(IConfiguration configuration) + { + _configuration = configuration; + client = new HttpClient(); + var key = _configuration["ApplicationInsights:rootUrlApi"]; + apiUrl = key; + } + public IActionResult Index() { - return View(); + helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login", "Login"); + } + else + { + return View(); + } + } } } diff --git a/Models/GiriConsegnaView.cs b/Models/GiriConsegnaView.cs new file mode 100644 index 0000000..ff39425 --- /dev/null +++ b/Models/GiriConsegnaView.cs @@ -0,0 +1,34 @@ +using System.ComponentModel.DataAnnotations; + +namespace SoftwayWeb.Models +{ + public class GiriConsegnaView + { + [Display(Name = "Seriale Giro")] + public string? SerialeGiro { get; set; } + + [Display(Name = "Data")] + public DateTime? DataGiro { get; set; } + + [Display(Name = "Cod. Autista")] + public string? CodAutista { get; set; } + + [Display(Name = "Autista")] + public string? Autista { get; set; } + + [Display(Name = "Bancali caricati")] + public int? BancaliCaricati { get; set; } + + [Display(Name = "Bancali recuperati")] + 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)")] + public decimal? ImportoRecuperato { get; set; } + + [Display(Name = "Data chiusura")] + public DateTime? DataChiusura { get; set; } + } +} diff --git a/Program.cs b/Program.cs index 0727468..def0a4f 100644 --- a/Program.cs +++ b/Program.cs @@ -2,7 +2,7 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); - +builder.Services.AddSession(); var app = builder.Build(); // Configure the HTTP request pipeline. @@ -20,8 +20,56 @@ app.UseRouting(); app.UseAuthorization(); +app.UseSession(); + app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); - +//app.UseSession(); app.Run(); + + + +/////////// +//var builder = WebApplication.CreateBuilder(args); + +//// Add services to the container. +//builder.Services.AddControllersWithViews(); + +//builder.Services.AddDistributedMemoryCache(); + +//builder.Services.AddSession(options => +//{ + +// options.Cookie.HttpOnly = true; +// options.Cookie.IsEssential = true; +//}); +//builder.Services.AddHttpContextAccessor(); + +//var app = builder.Build(); + +//// Configure the HTTP request pipeline. +//if (!app.Environment.IsDevelopment()) +//{ +// app.UseExceptionHandler("/Home/Error"); +// // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. +// app.UseHsts(); +//} + +//app.UseHttpsRedirection(); +//app.UseStaticFiles(); + +//app.UseRouting(); + +//app.UseAuthorization(); + +////app.MapControllerRoute( +//// name: "default", +//// pattern: "{controller=Home}/{action=Index}/{id?}"); + +//app.MapControllerRoute( +// name: "default", +// pattern: "{controller=Portale}/{action=Index}"); +//app.UseSession(); +//app.Run(); + diff --git a/SoftwayWeb.csproj b/SoftwayWeb.csproj index a189285..7f6cc1f 100644 --- a/SoftwayWeb.csproj +++ b/SoftwayWeb.csproj @@ -8,6 +8,7 @@ + diff --git a/Views/Giri/Index.cshtml b/Views/Giri/Index.cshtml new file mode 100644 index 0000000..286544b --- /dev/null +++ b/Views/Giri/Index.cshtml @@ -0,0 +1,115 @@ +@model IEnumerable +@* @model IPagedList *@ +@using X.PagedList; +@using X.PagedList.Mvc.Core; +@using X.PagedList; + + +@* @using X.PagedList.Web.Common; *@ + + +@{ + ViewData["Title"] = "Index"; +} + +

Giri di consegna

+ +

+ Aggiungi nuovo giro di consegna +

+ +@using (Html.BeginForm(@* "Index", "Giri" *@)) +{ + @*
@Html.TextBox("codAuti", null, new { placeholder = "Codice autista", @class = "agy-form-field require" })
+
@Html.TextBox("dataCons", null, new { placeholder = "Data consegna", @class = "agy-form-field require" })
+
*@ +
@Html.TextBox("codAutista", null, new { placeholder = "Codice autista", @class = "agy-form-field require" })
+
+
@Html.TextBox("data", null, new { type = "date", @class = "agy-form-field require" })
+
+
+} + + + + + + + + + + + + + + + @* + + + + + + + + + *@ + + + + @foreach (var item in Model) + { + + + + + + + + + + + + + } + +
Seriale giroDataCod. AutistaAutistaBancali caricatiBancali recuperatiImporto da recuperareImporto recuperatoData chiusura + @Html.DisplayNameFor(model => model.DataGiro) + + @Html.DisplayNameFor(model => model.CodAutista) + + @Html.DisplayNameFor(model => model.Autista) + + @Html.DisplayNameFor(model => model.BancaliCaricati) + + @Html.DisplayNameFor(model => model.BancaliRecuperati) + + @Html.DisplayNameFor(model => model.ImportoDaRecuperare) + + @Html.DisplayNameFor(model => model.ImportoRecuperato) + + @Html.DisplayNameFor(model => model.DataChiusura) +
+ @Html.DisplayFor(modelItem => item.SerialeGiro) + + @Html.DisplayFor(modelItem => item.DataGiro) + + @Html.DisplayFor(modelItem => item.CodAutista) + + @Html.DisplayFor(modelItem => item.Autista) + + @Html.DisplayFor(modelItem => item.BancaliCaricati) + + @Html.DisplayFor(modelItem => item.BancaliRecuperati) + + @Html.DisplayFor(modelItem => item.ImportoDaRecuperare) + + @Html.DisplayFor(modelItem => item.ImportoRecuperato) + + @Html.DisplayFor(modelItem => item.DataChiusura) + + @* @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | + @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | + @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) *@ +
diff --git a/Views/Portale/Index.cshtml b/Views/Portale/Index.cshtml index 4e5f359..275cb7b 100644 --- a/Views/Portale/Index.cshtml +++ b/Views/Portale/Index.cshtml @@ -3,6 +3,25 @@ *@ @{ + ViewData["Title"] = "Area riservata"; Layout = "~/Views/Shared/_LayoutAreaRis.cshtml"; } -Area riservata dopo login \ No newline at end of file + + + + + + + @ViewData["Title"] - SoftwayWeb + + + + + + @*
+ +
+
*@ + + Giri Consegna + \ No newline at end of file