290 lines
11 KiB
C#
290 lines
11 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using System.Net;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using VirtualTask.Models;
|
|
using X.PagedList;
|
|
|
|
namespace VirtualTask.Controllers
|
|
{
|
|
public class ChiusureController : Controller
|
|
{
|
|
|
|
string apiUrl = string.Empty;
|
|
string urlBase = string.Empty;
|
|
string token = string.Empty;
|
|
|
|
//Uri baseAddress = new Uri("http://10.0.0.187:8000/api/Polo/codici_chiusura?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVEVTVCIsImp0aSI6IjA2MzA5MzlmLTBhZDgtNDhkMi04ZTI5LWI3Mjk3N2IyOWM1YiIsInRlbmFudCI6Ik1BUlJPIiwidGNjb2RpY2UiOiJaWlogICAgICAgICAgICAiLCJleHAiOjE3MDE3Njk0NTUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjE5NTUiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CDt3wR6ube4zzNscVG9Qv6bzOnNF6A9-bIZxxjbKmKI");
|
|
HttpClient client;
|
|
|
|
//Uri baseAddressCreate = new Uri("http://10.0.0.187:8000/api/Polo/chiusure/add?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVEVTVCIsImp0aSI6IjA2MzA5MzlmLTBhZDgtNDhkMi04ZTI5LWI3Mjk3N2IyOWM1YiIsInRlbmFudCI6Ik1BUlJPIiwidGNjb2RpY2UiOiJaWlogICAgICAgICAgICAiLCJleHAiOjE3MDE3Njk0NTUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjE5NTUiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CDt3wR6ube4zzNscVG9Qv6bzOnNF6A9-bIZxxjbKmKI");
|
|
//HttpClient clientCreate;
|
|
|
|
//Uri baseAddressEdit = new Uri("http://10.0.0.187:8000/api/Polo/chiusure/mod?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVEVTVCIsImp0aSI6IjA2MzA5MzlmLTBhZDgtNDhkMi04ZTI5LWI3Mjk3N2IyOWM1YiIsInRlbmFudCI6Ik1BUlJPIiwidGNjb2RpY2UiOiJaWlogICAgICAgICAgICAiLCJleHAiOjE3MDE3Njk0NTUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjE5NTUiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CDt3wR6ube4zzNscVG9Qv6bzOnNF6A9-bIZxxjbKmKI");
|
|
//HttpClient clientEdit;
|
|
|
|
//Uri baseAddressDelete = new Uri("http://10.0.0.187:8000/api/Polo/chiusure/del?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVEVTVCIsImp0aSI6IjA2MzA5MzlmLTBhZDgtNDhkMi04ZTI5LWI3Mjk3N2IyOWM1YiIsInRlbmFudCI6Ik1BUlJPIiwidGNjb2RpY2UiOiJaWlogICAgICAgICAgICAiLCJleHAiOjE3MDE3Njk0NTUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjE5NTUiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CDt3wR6ube4zzNscVG9Qv6bzOnNF6A9-bIZxxjbKmKI");
|
|
//HttpClient clientDelete;
|
|
|
|
public ChiusureController()
|
|
{
|
|
//client = new HttpClient();
|
|
//client.BaseAddress = baseAddress;
|
|
|
|
//clientCreate = new HttpClient();
|
|
//clientCreate.BaseAddress = baseAddressCreate;
|
|
|
|
//clientEdit = new HttpClient();
|
|
//clientEdit.BaseAddress = baseAddressEdit;
|
|
|
|
//clientDelete = new HttpClient();
|
|
//clientDelete.BaseAddress = baseAddressDelete;
|
|
|
|
}
|
|
|
|
#region INDEX
|
|
|
|
public IActionResult Index(string searchString, int? page = 1)
|
|
{
|
|
//List<Chiusure> modelList = new List<Chiusure>();
|
|
//HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
//if (response.IsSuccessStatusCode)
|
|
//{
|
|
// string data = response.Content.ReadAsStringAsync().Result;
|
|
// modelList = JsonConvert.DeserializeObject<List<Chiusure>>(data);
|
|
//}
|
|
//return View(modelList);
|
|
|
|
SessionHelper helper = new SessionHelper(this);
|
|
token = helper.GetStringValue("tok");
|
|
if (string.IsNullOrEmpty(token))
|
|
return RedirectToAction("Index", "Login");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "codici_chiusura";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<Chiusure> modelList = new List<Chiusure>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Chiusure>>(data);
|
|
}
|
|
if (!string.IsNullOrEmpty(searchString))
|
|
{
|
|
modelList = modelList.Where(s => s.ccdescr.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.cccodice)
|
|
.ToPagedList(page ?? 1, pageSize);
|
|
|
|
return View(shortLinks);
|
|
}
|
|
|
|
#endregion INDEX
|
|
|
|
#region CREATE
|
|
|
|
public IActionResult Create()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Create(Chiusure model)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "chiusure/add";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
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");
|
|
}
|
|
|
|
return View();
|
|
}
|
|
|
|
#endregion CREATE
|
|
|
|
#region DETAIL
|
|
|
|
public IActionResult Details(string id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "codici_chiusura";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
Chiusure chiusura = new Chiusure();
|
|
|
|
List<Chiusure> modelList = new List<Chiusure>();
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Chiusure>>(data);
|
|
chiusura = modelList.Where(x => x.cccodice.Equals(id)).First();
|
|
}
|
|
|
|
return View(chiusura);
|
|
}
|
|
|
|
#endregion DETAIL
|
|
|
|
#region EDIT
|
|
|
|
public IActionResult Edit(string id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "codici_chiusura";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
Chiusure ele = new Chiusure();
|
|
|
|
List<Chiusure> modelList = new List<Chiusure>();
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Chiusure>>(data);
|
|
var el = modelList.Where(t => t.cccodice.Equals(id)).First();
|
|
ele = el;
|
|
}
|
|
|
|
return View(ele);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Edit(Chiusure model)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "chiusure/mod";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
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");
|
|
}
|
|
return View(model);
|
|
}
|
|
|
|
#endregion EDIT
|
|
|
|
#region DELETE
|
|
|
|
[HttpGet]
|
|
public IActionResult Delete(string id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "codici_chiusura";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
Chiusure elem = new Chiusure();
|
|
List<Chiusure> modelList = new List<Chiusure>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Chiusure>>(data);
|
|
elem = modelList.Where(t => t.cccodice.Equals(id)).First();
|
|
}
|
|
|
|
return View(elem);
|
|
}
|
|
|
|
[HttpPost, ActionName("DeleteConfirmed")]
|
|
public IActionResult DeleteConfirmed(string id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
token = helper.GetStringValue("tok");
|
|
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
urlBase = apiUrl + "chiusure/del?" + "codice=" + 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");
|
|
}
|
|
|
|
return View();
|
|
|
|
}
|
|
|
|
#endregion DELETE
|
|
}
|
|
}
|