MICHELE: progressivi controller, model, view
This commit is contained in:
parent
359a9cce96
commit
3a537c8e8e
163
Controllers/ProgressiviController.cs
Normal file
163
Controllers/ProgressiviController.cs
Normal file
@ -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<Progressivo> modelList = new List<Progressivo>();
|
||||
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string data = response.Content.ReadAsStringAsync().Result;
|
||||
modelList = JsonConvert.DeserializeObject<List<Progressivo>>(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<Progressivo> modelList = new List<Progressivo>();
|
||||
|
||||
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string data = response.Content.ReadAsStringAsync().Result;
|
||||
modelList = JsonConvert.DeserializeObject<List<Progressivo>>(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 });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
43
Views/Progressivi/Edit.cshtml
Normal file
43
Views/Progressivi/Edit.cshtml
Normal file
@ -0,0 +1,43 @@
|
||||
@model VirtualTask.Models.Progressivo
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Edit";
|
||||
}
|
||||
|
||||
<h1>Modifica progressivo</h1>
|
||||
|
||||
<h4>Progressivo</h4>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<form asp-action="Edit">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="azienda" class="control-label"></label>
|
||||
<input asp-for="azienda" class="form-control" />
|
||||
<span asp-validation-for="azienda" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="tipo_prog" class="control-label"></label>
|
||||
<input asp-for="tipo_prog" class="form-control" />
|
||||
<span asp-validation-for="tipo_prog" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="val_prog" class="control-label"></label>
|
||||
<input asp-for="val_prog" class="form-control" />
|
||||
<span asp-validation-for="val_prog" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Save" class="btn btn-primary" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a asp-action="Index">Torna indietro</a>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
}
|
||||
76
Views/Progressivi/Index.cshtml
Normal file
76
Views/Progressivi/Index.cshtml
Normal file
@ -0,0 +1,76 @@
|
||||
@model IPagedList<VirtualTask.Models.Progressivo>
|
||||
@using X.PagedList;
|
||||
@using X.PagedList.Mvc.Core;
|
||||
@using X.PagedList.Web.Common;
|
||||
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Index";
|
||||
}
|
||||
|
||||
<h1>Progressivi</h1>
|
||||
|
||||
<p>
|
||||
@*<a asp-action="Create">Create New</a>*@
|
||||
</p>
|
||||
@using (Html.BeginForm())
|
||||
{
|
||||
<p>
|
||||
Cerca per tipo: @Html.TextBox("SearchString")
|
||||
<input type="submit" value="Cerca" />
|
||||
</p>
|
||||
}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@*@Html.DisplayNameFor(model => model.azienda)*@
|
||||
Azienda
|
||||
</th>
|
||||
<th>
|
||||
@*@Html.DisplayNameFor(model => model.tipo_prog)*@
|
||||
Tipo progressivo
|
||||
</th>
|
||||
<th>
|
||||
@*@Html.DisplayNameFor(model => model.val_prog)*@
|
||||
Valore progressivo
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model) {
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.azienda)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.tipo_prog)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.val_prog)
|
||||
</td>
|
||||
<td>
|
||||
@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 */ })*@
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<br />
|
||||
<nav>
|
||||
@Html.PagedListPager(Model, page => Url.Action("index", new { page = page, searchString=@ViewData["CurrentFilter"] }), new PagedListRenderOptions()
|
||||
{
|
||||
ActiveLiElementClass = "active",
|
||||
PageClasses = new[]{ "page-link"},
|
||||
LiElementClasses=new[] { "page-item" },
|
||||
UlElementClasses = new[] { "pagination","justify-content-center", "mt-3" },
|
||||
LinkToNextPageFormat = "Successiva",
|
||||
LinkToPreviousPageFormat = "Precedente",
|
||||
MaximumPageNumbersToDisplay = 5,
|
||||
DisplayLinkToPreviousPage = PagedListDisplayMode.Always,
|
||||
DisplayLinkToNextPage = PagedListDisplayMode.Always
|
||||
})
|
||||
</nav>
|
||||
@ -40,6 +40,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Chiamate" asp-action="Index">CHIAMATE</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Progressivi" asp-action="Index">PROGRESSIVI</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -46,28 +46,28 @@
|
||||
<dd class = "col-sm-10">
|
||||
@Html.DisplayFor(model => model.tcpwd)
|
||||
</dd>
|
||||
<dt class = "col-sm-2" hidden>
|
||||
<dt class = "col-sm-2" >
|
||||
@Html.DisplayNameFor(model => model.tccoor)
|
||||
</dt>
|
||||
<dd class = "col-sm-10" hidden>
|
||||
<dd class = "col-sm-10" >
|
||||
@Html.DisplayFor(model => model.tccoor)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
<dt class="col-sm-2" >
|
||||
@Html.DisplayNameFor(model => model.tccono)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
<dd class="col-sm-10" >
|
||||
@Html.DisplayFor(model => model.tccono)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
<dt class="col-sm-2" >
|
||||
@Html.DisplayNameFor(model => model.tccost)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
<dd class="col-sm-10" >
|
||||
@Html.DisplayFor(model => model.tccost)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
<dt class="col-sm-2" >
|
||||
@Html.DisplayNameFor(model => model.tccofe)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
<dd class="col-sm-10" >
|
||||
@Html.DisplayFor(model => model.tccofe)
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user