Giri eda creare filtro
This commit is contained in:
parent
7345b44198
commit
2e379fcb81
142
Controllers/GiriDaValidareController.cs
Normal file
142
Controllers/GiriDaValidareController.cs
Normal file
@ -0,0 +1,142 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using NuGet.Common;
|
||||
using SoftwayWeb.Models;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace SoftwayWeb.Controllers
|
||||
{
|
||||
public class GiriDaValidareController : Controller
|
||||
{
|
||||
string apiUrl = string.Empty;
|
||||
string urlBase = string.Empty;
|
||||
string token = string.Empty;
|
||||
string errMes = string.Empty;
|
||||
private readonly IConfiguration _configuration;
|
||||
HttpClient client;
|
||||
public GiriDaValidareController(IConfiguration configuration)
|
||||
{
|
||||
client = new HttpClient();
|
||||
_configuration = configuration;
|
||||
var key = _configuration["ApplicationInsights:rootUrlApi"];
|
||||
apiUrl = key;
|
||||
}
|
||||
public IActionResult Index(DateTime data, bool sel,bool clear)
|
||||
{
|
||||
//se la data non è valorizzata, prendo i giri inseriti per ultimi, altrimenti li cerco per data
|
||||
List<GiriConsegnaDaCreare> modelList = new List<GiriConsegnaDaCreare>();
|
||||
SessionHelper helper = new SessionHelper(this);
|
||||
if(clear)
|
||||
{
|
||||
helper.SetStringValue("filterData", string.Empty);
|
||||
}
|
||||
|
||||
token = helper.GetStringValue("tok");
|
||||
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
return RedirectToAction("Login", "Login");
|
||||
}
|
||||
|
||||
|
||||
apiUrl = helper.GetStringValue("apiUrl");
|
||||
urlBase = apiUrl + "Giri/listaGiriDaCreare";
|
||||
|
||||
Uri baseAddress = new Uri(urlBase);
|
||||
client = new HttpClient();
|
||||
client.BaseAddress = baseAddress;
|
||||
|
||||
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string result = response.Content.ReadAsStringAsync().Result;
|
||||
modelList = JsonConvert.DeserializeObject<List<GiriConsegnaDaCreare>>(result);
|
||||
}
|
||||
|
||||
|
||||
string _filtro= helper.GetStringValue("filterData");
|
||||
if (data == DateTime.MinValue && string.IsNullOrEmpty(_filtro))
|
||||
{
|
||||
var last = modelList.OrderByDescending(t => t.DataGiro).Take(1).First();
|
||||
modelList = modelList.Where(x => x.DataGiro == last.DataGiro).ToList();
|
||||
}
|
||||
if (data == DateTime.MinValue && !string.IsNullOrEmpty(_filtro))
|
||||
{
|
||||
DateTime dataFiltro=Convert.ToDateTime(_filtro);
|
||||
ViewBag.Filtro = Convert.ToString(_filtro);
|
||||
modelList = modelList.Where(x => x.DataGiro == dataFiltro).ToList();
|
||||
}
|
||||
|
||||
if (data != DateTime.MinValue )
|
||||
{
|
||||
helper.SetStringValue("filterData", Convert.ToString( data));
|
||||
ViewBag.Filtro = data.ToString("dd/MM/yyyy");
|
||||
modelList = modelList.Where(x => x.DataGiro==data).ToList();
|
||||
}
|
||||
|
||||
foreach (GiriConsegnaDaCreare giro in modelList)
|
||||
{
|
||||
giro.IsSelected = sel;
|
||||
}
|
||||
|
||||
return View(modelList);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult PostIndex(IList<GiriConsegnaDaCreare> lst)
|
||||
{
|
||||
SessionHelper helper = new SessionHelper(this);
|
||||
|
||||
token = helper.GetStringValue("tok");
|
||||
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
return RedirectToAction("Login", "Login");
|
||||
}
|
||||
|
||||
foreach (GiriConsegnaDaCreare g in lst)
|
||||
{
|
||||
if (g.IsSelected == true)
|
||||
{
|
||||
//ViewBag.Autisti = getAutisti();
|
||||
apiUrl = helper.GetStringValue("apiUrl");
|
||||
urlBase = apiUrl + "Giri/addGiro2";
|
||||
|
||||
GiriConsegnaView gcv = new GiriConsegnaView();
|
||||
gcv.CodAutista = g.CodAutista;
|
||||
gcv.DataGiro = g.DataGiro;
|
||||
gcv.CodMezzo = g.CodMezzo;
|
||||
gcv.DataChiusura = DateTime.MinValue;
|
||||
|
||||
Uri baseAddress = new Uri(urlBase);
|
||||
client = new HttpClient();
|
||||
client.BaseAddress = baseAddress;
|
||||
string data = JsonConvert.SerializeObject(gcv);
|
||||
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
errMes = response.Content.ReadAsStringAsync().Result;
|
||||
helper.SetStringValue("errMsg", errMes);
|
||||
return RedirectToAction("Error");
|
||||
}
|
||||
}
|
||||
}
|
||||
return RedirectToAction("Index", "Giri");
|
||||
}
|
||||
|
||||
[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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,12 +12,14 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<p>
|
||||
<a asp-action="Create">Elenco giri di consegna da validare</a>
|
||||
<a href="@Url.ActionLink("Index", "GiriDaValidare")" title="Bancali" class="links">Elenco giri di consegna da validare</a>
|
||||
</p>
|
||||
|
||||
@*<p>
|
||||
<a asp-action="Create">Elenco giri di consegna da validare</a>
|
||||
</p>*@
|
||||
|
||||
@using (Html.BeginForm())
|
||||
{
|
||||
<div class="card">
|
||||
@ -80,10 +82,10 @@
|
||||
<tbody class="table-border-bottom-0">
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
int totBancaliCaricati = 0;
|
||||
string totBancaliCaricati = "-";
|
||||
if (item.BancaliCaricati!=null)
|
||||
{
|
||||
totBancaliCaricati = item.BancaliCaricati.Value;
|
||||
totBancaliCaricati = Convert.ToString(item.BancaliCaricati.Value);
|
||||
}
|
||||
<tr>
|
||||
<td style="border-right-width:2px"><i class="bx bxl-angular bx-sm text-danger me-3"></i> <span class="fw-medium">@Html.DisplayFor(modelItem => item.DataGiro)</span></td>
|
||||
@ -147,7 +149,7 @@
|
||||
<span><img alt="Bancali" src="@Url.Content("~/images/pallet.png")" style="width:24px;height:24px;"></span>
|
||||
<span style="color:blue;">Bancali caricati</span> /<span style="color:green;">parziale bancali caricati</span> /<span style="color:brown;">parziale bancali scaricati</span> /
|
||||
<span><img alt="nocons" src="@Url.Content("~/images/alert.png")" style="width:16px;height:16px;"></span>
|
||||
<span> Bancali non caricati</span>
|
||||
<span> Giro NON visibile su app (caricare i bancali iniziali)</span>
|
||||
|
||||
<!--/ Striped Rows -->
|
||||
|
||||
|
||||
98
Views/GiriDaValidare/Index.cshtml
Normal file
98
Views/GiriDaValidare/Index.cshtml
Normal file
@ -0,0 +1,98 @@
|
||||
@model List<SoftwayWeb.Models.GiriConsegnaDaCreare>
|
||||
@{
|
||||
Layout = "~/Views/Shared/_LayoutAreaRis.cshtml";
|
||||
List<GiriConsegnaDaCreare> lst = new List<GiriConsegnaDaCreare>();
|
||||
lst = Model;
|
||||
string lbl = string.Empty;
|
||||
string filt = ViewBag.Filtro;
|
||||
if(string.IsNullOrEmpty(filt))
|
||||
{
|
||||
lbl = "Nessun filtro impostato";
|
||||
}
|
||||
else
|
||||
{
|
||||
lbl = "Filtro:" +filt;
|
||||
}
|
||||
}
|
||||
@using (Html.BeginForm())
|
||||
{
|
||||
<div class="card">
|
||||
<h5 class="card-header">Ricerca</h5>
|
||||
<div class="table-responsive text-nowrap">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:15%">Data giro</th>
|
||||
<th style="width:15%"> </th>
|
||||
<th style="width:20%"> </th>
|
||||
<th style="width:50%"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-border-bottom-0">
|
||||
<tr>
|
||||
<td><i class="bx bxl-angular bx-sm text-danger me-3"></i> <span class="fw-medium">@Html.TextBox("data", null, new { type = "date", @class = "agy-form-field require" })</span></td>
|
||||
<td>@lbl</td>
|
||||
<td>
|
||||
<input type="submit" value="Cerca" class="btn btn-primary" />
|
||||
@Html.ActionLink("Annulla filtro", "Index", "GiriDaValidare",new { clear = true }, new { @class = "btn btn-primary" })
|
||||
</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<br />
|
||||
<br />
|
||||
<div class="card">
|
||||
<h5 class="card-header">Giri da validare</h5>
|
||||
<div class="table-responsive text-nowrap">
|
||||
<form asp-action="PostIndex">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th>Data</th>
|
||||
<th>Autista</th>
|
||||
<th>Automezzo</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-border-bottom-0">
|
||||
@for (var i = 0; i < lst.Count(); i++)
|
||||
{
|
||||
<tr>
|
||||
<td style="border-right-width:2px">
|
||||
@Html.CheckBoxFor(a=>lst[i].IsSelected)
|
||||
</td>
|
||||
<td Style="border-right-width:2px">
|
||||
@Html.DisplayFor(a=>lst[i].DataGiro)
|
||||
@Html.HiddenFor(a=>lst[i].DataGiro)
|
||||
</td>
|
||||
<td style="border-right-width:2px">
|
||||
@Html.DisplayFor(a=>lst[i].CodAutista)-@Html.DisplayFor(a=>lst[i].Autista)
|
||||
@Html.HiddenFor(a=>lst[i].CodAutista)
|
||||
</td>
|
||||
<td style="border-right-width:2px">
|
||||
@Html.DisplayFor(a=>lst[i].CodMezzo)-@Html.DisplayFor(a=>lst[i].Automezzo)
|
||||
@Html.HiddenFor(a=>lst[i].CodMezzo)
|
||||
</td>
|
||||
<td style="border-right-width:2px">
|
||||
|
||||
<a href="@Url.ActionLink("Index", "Destinazioni", new { id="", codAutista=lst[i].CodAutista, nomeAutista=lst[i].Autista, dataGiro=lst[i].DataGiro, codMezzo=lst[i].CodMezzo, desMezzo=lst[i].Automezzo})" title="Destinazioni" class="links"><img alt="nocons" src="@Url.Content("~/images/icons8-oggetti-puntiforme-30.png")" style="width:24px;height:24px;"></a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<button type="submit" class="btn btn-primary">Valida</button>
|
||||
@Html.ActionLink("Seleziona tutti", "Index", "GiriDaValidare",new { sel = true }, new { @class = "btn btn-primary" })
|
||||
|
||||
@Html.ActionLink("Deleziona tutti", "Index", "GiriDaValidare",new { sel = false },new { @class = "btn btn-primary" })
|
||||
|
||||
@Html.ActionLink("Torna alla lista", "Index", "Giri",null,new { @class = "btn btn-primary" })
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!--/ Striped Rows -->
|
||||
Loading…
Reference in New Issue
Block a user