769 lines
28 KiB
C#
769 lines
28 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Newtonsoft.Json;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
using VirtualTask.Models;
|
|
using X.PagedList;
|
|
|
|
namespace VirtualTask.Controllers
|
|
{
|
|
public class ChiamateController : Controller
|
|
{
|
|
string apiUrl = string.Empty;
|
|
string urlBase = string.Empty;
|
|
string token = string.Empty;
|
|
string tenant = string.Empty;
|
|
string errMes = string.Empty;
|
|
string _serchiam = "SER_CHIAMA";
|
|
string _numchiam = "NUM_CHIAMA";
|
|
string admin = string.Empty;
|
|
string time_sheet=string.Empty;
|
|
|
|
HttpClient client;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
|
public ChiamateController(IConfiguration configuration)
|
|
{
|
|
client = new HttpClient();
|
|
_configuration = configuration;
|
|
var key = _configuration["ApplicationInsights:rootUrlApi"];
|
|
apiUrl = key;
|
|
}
|
|
|
|
#region INDEX
|
|
|
|
public IActionResult Index(string impianto, string tecnico, DateTime dataIni, DateTime dataFin, string stato, string indirizzo, int? page = 1)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login2", "Login");
|
|
}
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
time_sheet = helper.GetStringValue("time_sheet");
|
|
ViewBag.TimeSheet = time_sheet;
|
|
|
|
urlBase = apiUrl + "chiamateListMngr";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<Chiamate> modelList = new List<Chiamate>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Chiamate>>(data);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(impianto))
|
|
{
|
|
modelList = modelList.Where(s => s.chcodimp!=null && s.chcodimp.Contains(impianto)).ToList();
|
|
|
|
ViewData["CurrentFilter"] = impianto;
|
|
|
|
ViewBag.Impianto = impianto;
|
|
}
|
|
else
|
|
ViewData["CurrentFilter"] = null;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(tecnico))
|
|
{
|
|
modelList = modelList.Where(s => s.chtchiam != null && s.chtchiam.Contains(tecnico)).ToList();
|
|
|
|
ViewData["CurrentFilterTec"] = tecnico;
|
|
|
|
ViewBag.Impianto = tecnico;
|
|
}
|
|
else
|
|
ViewData["CurrentFilterTec"] = null;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(indirizzo))
|
|
{
|
|
modelList = modelList.Where(s => s.indirizzoBreve.ToUpper().Contains(indirizzo.ToUpper())).ToList();
|
|
|
|
ViewData["CurrentFilterIndiri"] = indirizzo;
|
|
|
|
}
|
|
else
|
|
ViewData["CurrentFilterIndiri"] = null;
|
|
|
|
|
|
|
|
|
|
if (dataIni.Date != DateTime.MinValue)
|
|
{
|
|
modelList = modelList.Where(x => x.chdata.GetValueOrDefault().Date >= dataIni.Date).ToList();
|
|
ViewData["CurrentFilterDataDa"] = dataIni.Date;
|
|
ViewBag.Da = dataIni.Date.ToString("yyyy-MM-dd");
|
|
}
|
|
else
|
|
ViewData["CurrentFilterDataDa"] = DateTime.MinValue;
|
|
|
|
if (dataFin.Date != DateTime.MinValue)
|
|
{
|
|
modelList = modelList.Where(x => x.chdata.GetValueOrDefault().Date <= dataFin.Date).ToList();
|
|
ViewData["CurrentFilterDataA"] = dataFin.Date;
|
|
ViewBag.A = dataFin.Date.ToString("yyyy-MM-dd");
|
|
}
|
|
else
|
|
ViewData["CurrentFilterDataA"] = DateTime.MinValue;
|
|
|
|
if (!string.IsNullOrEmpty(stato))
|
|
{
|
|
modelList = modelList.Where(x => x.chstato.Contains(stato)).ToList();
|
|
|
|
ViewData["CurrentFilterStato"] = stato;
|
|
|
|
}
|
|
else
|
|
ViewData["CurrentFilterStato"] = null;
|
|
|
|
|
|
|
|
if (page != null && page < 1)
|
|
{
|
|
page = 1;
|
|
}
|
|
|
|
var pageSize = 10;
|
|
var shortLinks = modelList
|
|
.OrderByDescending(s => s.chnumero)
|
|
.ToPagedList(page ?? 1, pageSize);
|
|
|
|
|
|
ViewBag.Impianti = getImpianti(impianto);
|
|
ViewBag.Tecnici = getTecnici(tecnico);
|
|
ViewBag.StatiChiamata = getStatiChiamata(stato);
|
|
|
|
return View(shortLinks);
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
|
|
#endregion INDEX
|
|
|
|
#region CREATE
|
|
|
|
public IActionResult Create(string id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
|
|
ViewBag.Impianti = getImpianti(null);
|
|
|
|
ViewBag.StatiChiamata = getStatiChiamata(null);
|
|
//ViewBag.TipiChiamata = getTipiChiamata();
|
|
ViewBag.CodiciSegnalazione = getCodiciSegnalazione();
|
|
ViewBag.Tecnici = getTecnici(null);
|
|
|
|
// Pre-seleziona impianto
|
|
var model = new Chiamate();
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
model.chcodimp = id;
|
|
}
|
|
|
|
return View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Create(Chiamate model)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
tenant = helper.GetStringValue("tenant");
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login2","Login");
|
|
}
|
|
|
|
#region campi da impostare
|
|
|
|
model.chcodazi = tenant;
|
|
model.chaziimp = tenant;
|
|
model.chserial = getNewSeriale();
|
|
model.chnumero=getNewNumeroChiamata();
|
|
//DateTime adesso = DateTime.Now;
|
|
//model.chdata = adesso;
|
|
//model.chdtass = adesso;
|
|
//model.chdtapp = adesso;
|
|
if (model.chdata == null)
|
|
{
|
|
model.chdata = DateTime.Now;
|
|
}
|
|
//model.chdtapp = model.chdata;
|
|
model.chdtass = model.chdata;
|
|
model.chtipo = "A";//X=creato da app, A creato da adhoc. DEVO METTERE A perche altrimenti l'app lo tratta come una chiamata da commessa
|
|
model.chmodrac = "EMAIL";
|
|
//int year=adesso.Year;
|
|
//int ora = adesso.Hour;
|
|
//int min=adesso.Minute;
|
|
//model.chora = ora;
|
|
//model.choraapi = ora;
|
|
//model.chorass = ora;
|
|
//model.chmin = min;
|
|
//model.chminapi = min;
|
|
//model.chminass = min;
|
|
|
|
//MF 25/10/2024 Anno, ore e minuti prendono data appuntamento e non più data apertura chiamata
|
|
//int year = model.chdata.Value.Year;
|
|
//int hour = model.chdata.Value.Hour;
|
|
//int minute = model.chdata.Value.Minute;
|
|
|
|
int year = model.chdtapp.Value.Year;
|
|
int hour = model.chdtapp.Value.Hour;
|
|
int minute = model.chdtapp.Value.Minute;
|
|
|
|
model.chora = hour;
|
|
model.chmin = minute;
|
|
model.choraapi = hour;
|
|
model.chminapi = minute;
|
|
model.chorass = hour;
|
|
model.chminass = minute;
|
|
model.chcodese=Convert.ToString(year);
|
|
|
|
#endregion
|
|
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
urlBase = apiUrl + "chiamata/add";
|
|
urlBase = urlBase + "?token=" + token;
|
|
client = new HttpClient();
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client.BaseAddress = baseAddress;
|
|
string data = JsonConvert.SerializeObject(model);
|
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
return RedirectToAction("Index");
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
//return View();
|
|
}
|
|
|
|
#endregion CREATE
|
|
|
|
#region DETAIL
|
|
|
|
public IActionResult Details(string id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
urlBase = apiUrl + "chiamateListMngr";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
Chiamate chiamata = new Chiamate();
|
|
|
|
List<Chiamate> modelList = new List<Chiamate>();
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Chiamate>>(data);
|
|
chiamata = modelList.Where(x => x.chserial.Equals(id)).First();
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
return View(chiamata);
|
|
}
|
|
|
|
#endregion DETAIL
|
|
|
|
#region EDIT
|
|
|
|
public IActionResult Edit(string id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
urlBase = apiUrl + "chiamateListMngr";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
Chiamate chiamata = new Chiamate();
|
|
|
|
List<Chiamate> modelList = new List<Chiamate>();
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Chiamate>>(data);
|
|
chiamata = modelList.Where(t => t.chserial.Equals(id)).First();
|
|
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
|
|
ViewBag.Impianti = getImpianti(null);
|
|
ViewBag.StatiChiamata = getStatiChiamata(null);
|
|
ViewBag.CodiciSegnalazione = getCodiciSegnalazione();
|
|
ViewBag.Tecnici = getTecnici(null);
|
|
return View(chiamata);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Edit(Chiamate model)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
tenant = helper.GetStringValue("tenant");
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return RedirectToAction("Login2", "Login");
|
|
}
|
|
model.chcodazi = tenant;
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "chiamata/mod";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
//model.chdtapp = model.chdata;
|
|
|
|
//model.chdtass = model.chdata;
|
|
model.chdtass = model.chdtapp;
|
|
|
|
//int year = model.chdata.Value.Year;
|
|
//int hour = model.chdata.Value.Hour;
|
|
//int minute = model.chdata.Value.Minute;
|
|
|
|
int year = model.chdtapp.Value.Year;
|
|
int hour = model.chdtapp.Value.Hour;
|
|
int minute = model.chdtapp.Value.Minute;
|
|
|
|
model.chora = hour;
|
|
model.chmin = minute;
|
|
model.choraapi = hour;
|
|
model.chminapi = minute;
|
|
model.chorass = hour;
|
|
model.chminass = minute;
|
|
|
|
string data = JsonConvert.SerializeObject(model);
|
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
return RedirectToAction("Index");
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
}
|
|
|
|
#endregion EDIT
|
|
|
|
#region DELETE
|
|
|
|
[HttpGet]
|
|
public IActionResult Delete(string id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
urlBase = apiUrl + "chiamateListMngr";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
Chiamate chiamata = new Chiamate();
|
|
List<Chiamate> modelList = new List<Chiamate>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Chiamate>>(data);
|
|
chiamata = modelList.Where(x => x.chserial.Equals(id)).First();
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
return View(chiamata);
|
|
}
|
|
|
|
|
|
[HttpPost, ActionName("DeleteConfirmed")]
|
|
public IActionResult DeleteConfirmed(string id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
urlBase = apiUrl + "chiamata/del?" + "chserial=" + id + "&";
|
|
urlBase = urlBase + "token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
string data = JsonConvert.SerializeObject(id);
|
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
return RedirectToAction("Index");
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
//return View();
|
|
}
|
|
#endregion DELETE
|
|
|
|
|
|
|
|
#region metodi interni
|
|
|
|
private byte GetImgFromRapp_New()
|
|
{
|
|
var img = new Byte();
|
|
return img;
|
|
}
|
|
|
|
private List<SelectListItem> getImpianti(string impianto)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
//if (!string.IsNullOrEmpty(impianto))
|
|
//{
|
|
// helper.SetStringValue("imp", impianto);
|
|
//}
|
|
//else
|
|
//{
|
|
// helper.SetStringValue("imp", "");
|
|
//}
|
|
|
|
token = helper.GetStringValue("tok");
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "impiantiListMngr";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
List<Impianto> modelList = new List<Impianto>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Impianto>>(data);
|
|
modelList = modelList.Where(x => x.imfinatt == null).ToList();
|
|
|
|
//per gestire primo elemento tendina (deve essere vuoto)
|
|
SelectListItem listItemFirt = new SelectListItem();
|
|
|
|
listItemFirt.Value = string.Empty;
|
|
listItemFirt.Text = " - Impianto";
|
|
selectItems.Add(listItemFirt);
|
|
|
|
foreach (var role in modelList)
|
|
{
|
|
SelectListItem listItem = new SelectListItem();
|
|
string s = role.imcodimp + " - " + role.imdescri;
|
|
listItem.Value = role.imcodimp;
|
|
listItem.Text = s;
|
|
if(role.imcodimp!=null && role.imcodimp.Equals(impianto))
|
|
{
|
|
listItem.Selected = true;
|
|
}
|
|
selectItems.Add(listItem);
|
|
}
|
|
}
|
|
return selectItems;
|
|
}
|
|
private List<SelectListItem> getStatiChiamata(string stato)
|
|
{
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
|
|
SelectListItem listItemFirt = new SelectListItem();
|
|
listItemFirt.Value = string.Empty;
|
|
listItemFirt.Text = " - Stato";
|
|
selectItems.Add(listItemFirt);
|
|
|
|
SelectListItem listItem = new SelectListItem();
|
|
listItem.Value = "C";
|
|
listItem.Text = "Assegnata";
|
|
if(!string.IsNullOrEmpty(stato) &&stato.Equals("C"))
|
|
listItem.Selected = true;
|
|
selectItems.Add(listItem);
|
|
|
|
listItem = new SelectListItem();
|
|
listItem.Value = "B";
|
|
listItem.Text = "Da Assegnare";
|
|
if (!string.IsNullOrEmpty(stato) && stato.Equals("B"))
|
|
listItem.Selected = true;
|
|
selectItems.Add(listItem);
|
|
|
|
listItem = new SelectListItem();
|
|
listItem.Value = "Z";
|
|
listItem.Text = "Chiusa";
|
|
if (!string.IsNullOrEmpty(stato) && stato.Equals("Z"))
|
|
listItem.Selected = true;
|
|
selectItems.Add(listItem);
|
|
|
|
listItem = new SelectListItem();
|
|
listItem.Value = "S";
|
|
listItem.Text = "Sospesa";
|
|
if (!string.IsNullOrEmpty(stato) && stato.Equals("S"))
|
|
listItem.Selected = true;
|
|
selectItems.Add(listItem);
|
|
|
|
return selectItems;
|
|
}
|
|
private List<SelectListItem> getTipiChiamata()
|
|
{
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
|
|
SelectListItem listItem = new SelectListItem();
|
|
listItem.Value = "A";
|
|
listItem.Text = "Tipo A";
|
|
selectItems.Add(listItem);
|
|
|
|
listItem = new SelectListItem();
|
|
listItem.Value = "B";
|
|
listItem.Text = "Tipo B";
|
|
selectItems.Add(listItem);
|
|
|
|
return selectItems;
|
|
}
|
|
private List<SelectListItem> getCodiciSegnalazione()
|
|
{
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
|
|
SelectListItem listItem = new SelectListItem();
|
|
listItem.Value = "Intervento";
|
|
listItem.Text = "Intervento";
|
|
selectItems.Add(listItem);
|
|
|
|
listItem = new SelectListItem();
|
|
listItem.Value = "Collaudo";
|
|
listItem.Text = "Collaudo";
|
|
selectItems.Add(listItem);
|
|
|
|
listItem = new SelectListItem();
|
|
listItem.Value = "InterventoGar";
|
|
listItem.Text = "Intervento in garanzia";
|
|
selectItems.Add(listItem);
|
|
|
|
listItem = new SelectListItem();
|
|
listItem.Value = "InterventoMan";
|
|
listItem.Text = "Intervento in manutenzione";
|
|
selectItems.Add(listItem);
|
|
|
|
listItem = new SelectListItem();
|
|
listItem.Value = "InterventoCli";
|
|
listItem.Text = "Intervento a carico del cliente";
|
|
selectItems.Add(listItem);
|
|
|
|
return selectItems;
|
|
}
|
|
private List<SelectListItem> getTecnici(string tecnico)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "tecniciList";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
List<SelectListItem> selectItems = new List<SelectListItem>();
|
|
List<Tecnici> modelList = new List<Tecnici>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Tecnici>>(data);
|
|
modelList = modelList.Where(x => x.tcdatobs == null).ToList();
|
|
//per gestire primo elemento tendina (deve essere vuoto)
|
|
SelectListItem listItemFirst = new SelectListItem();
|
|
|
|
listItemFirst.Value = string.Empty;
|
|
listItemFirst.Text = " - Tecnico";
|
|
selectItems.Add(listItemFirst);
|
|
|
|
foreach (var role in modelList)
|
|
{
|
|
SelectListItem listItem = new SelectListItem();
|
|
|
|
string s = role.tccodice + " - " + role.tcdescri;
|
|
listItem.Value = role.tccodice;
|
|
listItem.Text = s;
|
|
if (role.tccodice != null && role.tccodice.Equals(tecnico))
|
|
{
|
|
listItem.Selected = true;
|
|
}
|
|
selectItems.Add(listItem);
|
|
}
|
|
}
|
|
return selectItems;
|
|
}
|
|
private string getNewSeriale()
|
|
{
|
|
int p = -1;
|
|
string seriale = string.Empty;
|
|
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;
|
|
List<Progressivo> progressivi = new List<Progressivo>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
progressivi = JsonConvert.DeserializeObject<List<Progressivo>>(data);
|
|
var last = progressivi.Where(t => t.tipo_prog.Equals(_serchiam)).First();
|
|
p = last.val_prog;
|
|
p++;
|
|
seriale = Convert.ToString(p);
|
|
seriale = seriale.PadLeft(10, '0');
|
|
Progressivo upd = new Progressivo();
|
|
upd.val_prog = p;
|
|
upd.tipo_prog = _serchiam;
|
|
upd.azienda = tenant;
|
|
updateTabellaProgressivi(upd);
|
|
}
|
|
return seriale;
|
|
}
|
|
private async void updateTabellaProgressivi(Progressivo p)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
tenant = helper.GetStringValue("tenant");
|
|
urlBase = apiUrl + "progressivo/mod";
|
|
urlBase = urlBase + "?token=" + token;
|
|
//Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
|
|
var stringPayload = JsonConvert.SerializeObject(p);
|
|
var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
|
|
var httpResponse = await client.PostAsync(urlBase, httpContent);
|
|
if (httpResponse.Content != null)
|
|
{
|
|
var responseContent = await httpResponse.Content.ReadAsStringAsync();
|
|
}
|
|
}
|
|
private decimal getNewNumeroChiamata()
|
|
{
|
|
int p = -1;
|
|
decimal numero =0;
|
|
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;
|
|
List<Progressivo> progressivi = new List<Progressivo>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
progressivi = JsonConvert.DeserializeObject<List<Progressivo>>(data);
|
|
var last = progressivi.Where(t => t.tipo_prog.Equals(_numchiam)).First();
|
|
p = last.val_prog;
|
|
p++;
|
|
numero = Convert.ToDecimal(p);
|
|
Progressivo upd = new Progressivo();
|
|
upd.val_prog = p;
|
|
upd.tipo_prog = _numchiam;
|
|
upd.azienda = tenant;
|
|
updateTabellaProgressivi(upd);
|
|
}
|
|
return numero;
|
|
}
|
|
|
|
[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 });
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|