modifica destinazione
This commit is contained in:
parent
c11b665501
commit
605f925725
@ -1,7 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Newtonsoft.Json;
|
||||
using SoftwayWeb.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using X.PagedList;
|
||||
@ -176,10 +178,10 @@ namespace SoftwayWeb.Controllers
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public IActionResult ModificaDestinazione(string serial)
|
||||
{
|
||||
SessionHelper helper = new SessionHelper(this);
|
||||
|
||||
|
||||
apiUrl = helper.GetStringValue("apiUrl");
|
||||
urlBase = apiUrl + "Giri/listaDestinazioneBySerial";
|
||||
@ -195,6 +197,17 @@ namespace SoftwayWeb.Controllers
|
||||
{
|
||||
string dato = response.Content.ReadAsStringAsync().Result;
|
||||
model = JsonConvert.DeserializeObject<Destinazioni_Out>(dato);
|
||||
|
||||
List < SelectListItem > autisti = new List < SelectListItem>();
|
||||
autisti = getAutisti();
|
||||
autisti.Find(c => c.Value.Trim().Equals(model.CodAutista)).Selected = true;
|
||||
ViewBag.Autisti = autisti;
|
||||
|
||||
List<SelectListItem> mezzi = new List<SelectListItem>();
|
||||
mezzi = getMezzi();
|
||||
mezzi.Find(c => c.Value.Equals(model.CodAutomezzo)).Selected = true;
|
||||
ViewBag.CodMezzo = mezzi;
|
||||
|
||||
return View(model);
|
||||
|
||||
}
|
||||
@ -205,15 +218,139 @@ namespace SoftwayWeb.Controllers
|
||||
return RedirectToAction("Error");
|
||||
}
|
||||
|
||||
//return RedirectToAction("Index", "Destinazioni", new
|
||||
//{
|
||||
// id = model.serialeGiro,
|
||||
// codAutista = model.CodAutista,
|
||||
// dataGiro = model.DataCarico,
|
||||
// codMezzo = model.CodAutomezzo
|
||||
//});
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult ModificaDestinazionePost(Destinazioni_Out model)
|
||||
{
|
||||
SessionHelper helper = new SessionHelper(this);
|
||||
|
||||
token = helper.GetStringValue("tok");
|
||||
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
return RedirectToAction("Login", "Login");
|
||||
}
|
||||
|
||||
//qui metodo post per scrivere su pimodgir
|
||||
Modgir mg = new Modgir();
|
||||
mg.Piserial = model.Brserial;
|
||||
mg.Pidata = model.DataCarico;
|
||||
mg.Picommit = model.CodCommittente;
|
||||
mg.Pidesdiv = model.CodSede;
|
||||
mg.Pitarga = model.CodAutomezzo;
|
||||
mg.Piautist = model.CodAutista;
|
||||
mg.Pitiprec = "M";
|
||||
|
||||
apiUrl = helper.GetStringValue("apiUrl");
|
||||
|
||||
urlBase = apiUrl + "ModificaGiro/addModgir";
|
||||
Uri baseAddress = new Uri(urlBase);
|
||||
client = new HttpClient();
|
||||
client.BaseAddress = baseAddress;
|
||||
|
||||
string data = JsonConvert.SerializeObject(mg);
|
||||
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response2 = client.PostAsync(baseAddress, content).Result;
|
||||
if (response2.IsSuccessStatusCode)
|
||||
{
|
||||
return RedirectToAction("Index", "Destinazioni", new
|
||||
{
|
||||
id = model.serialeGiro,
|
||||
codAutista = model.CodAutista,
|
||||
dataGiro = model.DataCarico,
|
||||
codMezzo = model.CodAutomezzo
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
errMes = response2.Content.ReadAsStringAsync().Result;
|
||||
helper.SetStringValue("errMsg", errMes);
|
||||
return RedirectToAction("Error");
|
||||
}
|
||||
|
||||
}
|
||||
private List<SelectListItem> getAutisti()
|
||||
{
|
||||
SessionHelper helper = new SessionHelper(this);
|
||||
|
||||
apiUrl = helper.GetStringValue("apiUrl");
|
||||
urlBase = apiUrl + "Giri/listaAutisti";
|
||||
|
||||
Uri baseAddress = new Uri(urlBase);
|
||||
client = new HttpClient();
|
||||
client.BaseAddress = baseAddress;
|
||||
List<SelectListItem> selectItems = new List<SelectListItem>();
|
||||
List<Personale> modelList = new List<Personale>();
|
||||
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string data = response.Content.ReadAsStringAsync().Result;
|
||||
modelList = JsonConvert.DeserializeObject<List<Personale>>(data);
|
||||
|
||||
//per gestire primo elemento tendina (deve essere vuoto)
|
||||
SelectListItem listItemFirt = new SelectListItem();
|
||||
|
||||
|
||||
|
||||
foreach (var role in modelList)
|
||||
{
|
||||
SelectListItem listItem = new SelectListItem();
|
||||
string s = role.Catcodice + " - " + role.Catnome;
|
||||
listItem.Value = role.Catcodice;
|
||||
listItem.Text = s;
|
||||
selectItems.Add(listItem);
|
||||
}
|
||||
}
|
||||
|
||||
return selectItems;
|
||||
}
|
||||
|
||||
private List<SelectListItem> getMezzi()
|
||||
{
|
||||
SessionHelper helper = new SessionHelper(this);
|
||||
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);
|
||||
|
||||
listMezzi = listMezzi.OrderBy(x => x.CauTarga).ToList();
|
||||
|
||||
//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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "ModificaDestinazione";
|
||||
Layout = "~/Views/Shared/_LayoutAreaRis.cshtml";
|
||||
}
|
||||
|
||||
<h1>ModificaDestinazione</h1>
|
||||
@ -10,16 +11,16 @@
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<form asp-action="ModificaDestinazione">
|
||||
<form asp-action="ModificaDestinazionePost">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
@Html.HiddenFor(model => model.CodAutomezzo)
|
||||
|
||||
@Html.HiddenFor(model => model.DescAutomezzo)
|
||||
@Html.HiddenFor(model => model.Brserial)
|
||||
@Html.HiddenFor(model => model.DataCarico)
|
||||
@Html.HiddenFor(model => model.CodCommittente)
|
||||
@Html.HiddenFor(model => model.Committente)
|
||||
@Html.HiddenFor(model => model.Autista)
|
||||
@Html.HiddenFor(model => model.CodAutista)
|
||||
|
||||
@Html.HiddenFor(model => model.CodSede)
|
||||
@Html.HiddenFor(model => model.Sede)
|
||||
@Html.HiddenFor(model => model.IndirizzoSede)
|
||||
@ -39,8 +40,9 @@
|
||||
@Html.HiddenFor(model => model.Note)
|
||||
@Html.HiddenFor(model => model.Seq)
|
||||
@Html.HiddenFor(model => model.Prog)
|
||||
|
||||
<div class="form-group">
|
||||
<b>@Html.DisplayNameFor(model => model.DescAutomezzo)</b> @Html.DisplayFor(model => model.CodAutomezzo)-@Html.DisplayFor(model => model.DescAutomezzo)
|
||||
<b>@Html.DisplayNameFor(model => model.DescAutomezzo)</b> @Html.DropDownList("CodAutomezzo", ViewBag.CodMezzo, null, new { @class = "agy-form-field require" })
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<b>@Html.DisplayNameFor(model => model.DataCarico)</b> @Html.DisplayFor(model => model.DataCarico)
|
||||
@ -51,6 +53,10 @@
|
||||
<div class="form-group">
|
||||
<b>@Html.DisplayNameFor(model => model.Autista)</b> @Html.DisplayFor(model => model.CodAutista)-@Html.DisplayFor(model => model.Autista)
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<b>Nuovo Autista</b> @Html.DropDownList("codAutista", ViewBag.Autisti, null, new { @class = "agy-form-field require" })
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<b>@Html.DisplayNameFor(model => model.Sede)</b> @Html.DisplayFor(model => model.CodSede)-@Html.DisplayFor(model => model.Sede)
|
||||
</div>
|
||||
@ -85,7 +91,6 @@
|
||||
<b>@Html.DisplayNameFor(model => model.Prog)</b> @Html.DisplayFor(model => model.Prog)
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Save" class="btn btn-primary" />
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user