Michele: Filtro automezzo Giri

This commit is contained in:
michele 2024-07-15 16:45:45 +02:00
parent b8e26a3c0a
commit fd060b1b09
3 changed files with 68 additions and 2 deletions

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc.Rendering;
using Newtonsoft.Json;
using SoftwayWeb.Models;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.Intrinsics.Arm;
using System.Text;
@ -29,7 +30,7 @@ namespace SoftwayWeb.Controllers
apiUrl = key;
}
public IActionResult Index(string? codAutista, DateTime data, bool aperto = true, int? page = 1)
public IActionResult Index(string? codAutista, string? codMezzo, DateTime data, bool aperto = true, int? page = 1)
{
helper = new SessionHelper(this);
token = helper.GetStringValue("tok");
@ -63,6 +64,18 @@ namespace SoftwayWeb.Controllers
ViewData["CurrentFilter"] = null;
}
ViewBag.CodMezzo = getMezzi();
if (!string.IsNullOrEmpty(codMezzo))
{
modelList = modelList.Where(x => x.CodMezzo.Contains(codMezzo)).ToList();
ViewData["CurrentFilter"] = codMezzo;
}
else
{
ViewData["CurrentFilter"] = null;
}
if (data.Date != DateTime.MinValue)
{
modelList = modelList.Where(x => x.DataGiro.GetValueOrDefault().Date == data.Date).ToList();
@ -76,7 +89,7 @@ namespace SoftwayWeb.Controllers
var pageSize = 10;
var shortList = modelList.ToPagedList(page ?? 1, pageSize);
return View(shortList/*modelList*/);
return View(shortList);
}
else
{
@ -276,6 +289,45 @@ namespace SoftwayWeb.Controllers
return selectItems;
}
private List<SelectListItem> getMezzi()
{
apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "Giri/listaAutomezzi";
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
client.BaseAddress = baseAddress;
List<SelectListItem> selectItems = new List<SelectListItem>();
List<Automezzi> listMezzi = new List<Automezzi>();
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
if (response.IsSuccessStatusCode)
{
string data = response.Content.ReadAsStringAsync().Result;
listMezzi = JsonConvert.DeserializeObject<List<Automezzi>>(data);
//per gestire primo elemento tendina (deve essere vuoto)
SelectListItem listItemFirt = new SelectListItem();
listItemFirt.Value = string.Empty;
listItemFirt.Text = " - Automezzo";
selectItems.Add(listItemFirt);
foreach (var mezzo in listMezzi)
{
SelectListItem listItem = new SelectListItem();
List<SelectListItem> listItemOrderby = new List<SelectListItem>();
string s = mezzo.CauTarga + " - " + mezzo.CauDesc;
listItem.Value = mezzo.CauTarga;
listItem.Text = s;
selectItems.Add(listItem);
}
}
return selectItems;
}
private List<GiriConsegnaDaCreare> getNuoviGiri()
{
SessionHelper helper = new SessionHelper(this);

12
Models/Automezzi.cs Normal file
View File

@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace SoftwayWeb.Models
{
public class Automezzi
{
[Display(Name = "Cod. Automezzo")]
public string? CauTarga { get; set; }
[Display(Name = "Desc. Automezzo")]
public string? CauDesc { get; set; }
}
}

View File

@ -29,6 +29,8 @@
@* <div>@Html.TextBox("codAutista", null, new { placeholder = "Codice autista", @class = "agy-form-field require" })</div> *@
<div>@Html.DropDownList("codAutista", ViewBag.Autisti, null, new { @class = "agy-form-field require" })</div>
<br />
<div>@Html.DropDownList("codMezzo", ViewBag.CodMezzo, null, new { @class = "agy-form-field require" })</div>
<br />
<div>@Html.TextBox("data", null, new { type = "date", @class = "agy-form-field require" })</div>
<br />
<div>