96 lines
3.1 KiB
C#
96 lines
3.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Office.Interop.Excel;
|
|
using Newtonsoft.Json;
|
|
using static VirtualTask.Controllers.LoginController;
|
|
using System.Runtime.Intrinsics.Arm;
|
|
using VirtualTask.Models;
|
|
using X.PagedList;
|
|
|
|
namespace VirtualTask.Controllers
|
|
{
|
|
public class MagNewVTController : Controller
|
|
{
|
|
string apiUrl = string.Empty;
|
|
string urlBase = string.Empty;
|
|
string token = string.Empty;
|
|
string tenant = string.Empty;
|
|
string errMes = string.Empty;
|
|
string admin = string.Empty;
|
|
string time_sheet = string.Empty;
|
|
HttpClient client;
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public MagNewVTController(IConfiguration configuration)
|
|
{
|
|
client = new HttpClient();
|
|
_configuration = configuration;
|
|
var key = _configuration["ApplicationInsights:rootUrlApi"];
|
|
apiUrl = key;
|
|
}
|
|
|
|
public IActionResult Index(string serRapp, string searchString, 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;
|
|
|
|
urlBase = apiUrl + "VTMagNewList";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<MagNewVT> modelList = new List<MagNewVT>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<MagNewVT>>(data);
|
|
modelList = modelList.Where(x => x.Seriale_Rapportino.Equals(serRapp)).ToList();
|
|
|
|
if (!string.IsNullOrEmpty(searchString))
|
|
{
|
|
modelList = modelList.Where(s => s.Desc_Art.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.Seriale_Rapportino)
|
|
.ToPagedList(page ?? 1, pageSize);
|
|
|
|
|
|
return View(shortLinks);
|
|
|
|
//return View(modelList.ToPagedList());
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
}
|
|
}
|