209 lines
6.9 KiB
C#
209 lines
6.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Newtonsoft.Json;
|
|
using SoftwayWeb.Models;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
|
|
|
|
namespace SoftwayWeb.Controllers
|
|
{
|
|
public class AddDestinazioneController : 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 AddDestinazioneController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
client = new HttpClient();
|
|
var key = _configuration["ApplicationInsights:rootUrlApi"];
|
|
apiUrl = key;
|
|
}
|
|
|
|
public IActionResult AddDestinazione(string serialeGiro)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login", "Login");
|
|
}
|
|
|
|
ViewBag.Commit = getCommittenti();
|
|
|
|
return View();
|
|
}
|
|
|
|
public IActionResult NewDestinazione(Modgir modgir)
|
|
{
|
|
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.Piprogre = modgir.Piprogre;
|
|
mg.Piserial = modgir.Piserial;
|
|
mg.Pidata = modgir.Pidata;
|
|
mg.Picommit = modgir.Picommit;
|
|
mg.Pidesdiv = modgir.Pidesdiv;
|
|
mg.Pitarga = modgir.Pitarga;
|
|
mg.Piautist = modgir.Piautist;
|
|
mg.Pitiprec = "M";
|
|
mg.Pirigele = modgir.Pirigele;
|
|
mg.Pisergir = modgir.Pisergir;
|
|
|
|
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 response = client.PostAsync(baseAddress, content).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
return RedirectToAction("Index","Giri");
|
|
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
//return View();
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
#region METODI INTERNI
|
|
|
|
private List<SelectListItem> getCommittenti()
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Clienti/getCommittenti";
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
List<Clienti> listClienti = new List<Clienti>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
listClienti = JsonConvert.DeserializeObject<List<Clienti>>(data);
|
|
|
|
//per gestire primo elemento tendina (deve essere vuoto)
|
|
SelectListItem listItemFirst = new SelectListItem();
|
|
|
|
listItemFirst.Value = string.Empty;
|
|
listItemFirst.Text = " - Seleziona Committente";
|
|
selectItems.Add(listItemFirst);
|
|
|
|
foreach (var item in listClienti)
|
|
{
|
|
SelectListItem listItem = new SelectListItem();
|
|
|
|
string s = item.Ancodice + " - " + item.Andescri;
|
|
listItem.Value = item.Ancodice;
|
|
listItem.Text = s;
|
|
selectItems.Add(listItem);
|
|
}
|
|
}
|
|
|
|
return selectItems;
|
|
}
|
|
|
|
|
|
#endregion METODI INTERNI
|
|
|
|
#region CASCADING
|
|
|
|
public IActionResult Cascading()
|
|
{
|
|
Cascading model = new Cascading();
|
|
model.Committenti = getCommittenti();
|
|
return View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Cascading(string Picommit/*ancodice*/)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
Cascading model = new Cascading();
|
|
model.Committenti = getCommittenti();
|
|
|
|
if (!string.IsNullOrEmpty(Picommit))
|
|
{
|
|
token = helper.GetStringValue("tok");
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "Clienti/getSediByCommittente"+ "?codCom=" + Picommit;
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<SedeConsegna> sediCons = new List<SedeConsegna>();
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
//List<SedeConsegna> listSedi = new List<SedeConsegna>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
sediCons = JsonConvert.DeserializeObject<List<SedeConsegna>>(data);
|
|
|
|
SelectListItem listItemFirst = new SelectListItem();
|
|
|
|
listItemFirst.Value = string.Empty;
|
|
listItemFirst.Text = " - Seleziona sede";
|
|
selectItems.Add(listItemFirst);
|
|
|
|
foreach (var sede in sediCons)
|
|
{
|
|
SelectListItem listItem = new SelectListItem();
|
|
|
|
string s = sede.Pccodsed + " - " + sede.Pcdescri;
|
|
listItem.Value = sede.Pccodsed;
|
|
listItem.Text = s;
|
|
selectItems.Add(listItem);
|
|
//model.SediCons.Add(listItem);
|
|
model.SediCons.Add(listItem);
|
|
}
|
|
//model.SediCons.AddRange(selectItems);
|
|
ViewBag.SediCons = sediCons;
|
|
}
|
|
}
|
|
return Json(new SelectList(model.SediCons, "Value", "Text"));
|
|
}
|
|
|
|
#endregion CASCADING
|
|
}
|
|
}
|