diff --git a/Controllers/ChiusureController.cs b/Controllers/ChiusureController.cs index 96a1b49..3bb2d7e 100644 --- a/Controllers/ChiusureController.cs +++ b/Controllers/ChiusureController.cs @@ -11,14 +11,13 @@ namespace VirtualTask.Controllers { public class ChiusureController : Controller { - string apiUrl = string.Empty; string urlBase = string.Empty; string token = string.Empty; string tenant = string.Empty; string errMes = string.Empty; - HttpClient client; + HttpClient client; public ChiusureController() { @@ -29,7 +28,6 @@ namespace VirtualTask.Controllers public IActionResult Index(string searchString, int? page = 1) { - SessionHelper helper = new SessionHelper(this); token = helper.GetStringValue("tok"); diff --git a/Controllers/RegistrazioniController.cs b/Controllers/RegistrazioniController.cs new file mode 100644 index 0000000..09edb25 --- /dev/null +++ b/Controllers/RegistrazioniController.cs @@ -0,0 +1,323 @@ +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.Diagnostics; +using System.Text; +using VirtualTask.Models; +using X.PagedList; + +namespace VirtualTask.Controllers +{ + public class RegistrazioniController : Controller + { + string apiUrl = string.Empty; + string urlBase = string.Empty; + string token = string.Empty; + string tenant = string.Empty; + string errMes = string.Empty; + + HttpClient client; + + public RegistrazioniController() + { + client = new HttpClient(); + } + + #region INDEX + + public IActionResult Index(string searchString, int? page = 1) + { + SessionHelper helper = new SessionHelper(this); + //token = helper.GetStringValue("tok"); + + //if (string.IsNullOrEmpty(token)) + // return RedirectToAction("Index", "Login"); + + //apiUrl = helper.GetStringValue("apiUrl"); + //urlBase = apiUrl + "RegistrazioniList"; + urlBase = "http://10.0.0.187:8000/api/Polo/RegistrazioniList"; + //urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + List modelList = new List(); + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + + if (!string.IsNullOrEmpty(searchString)) + { + modelList = modelList.Where(s => s.cognome.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.id) + .ToPagedList(page ?? 1, pageSize); + + return View(shortLinks); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + + #endregion INDEX + + #region CREATE + + public IActionResult Create() + { + return View(); + } + + [HttpPost] + public IActionResult Create(Registrazione model) + { + SessionHelper helper = new SessionHelper(this); + + //token = helper.GetStringValue("token"); + //tenant = helper.GetStringValue("tenant"); + + //if (string.IsNullOrEmpty(token)) + //{ + // return RedirectToAction("Index", "Login"); + //} + + //model.azienda = tenant; + + //apiUrl = helper.GetStringValue("apiUrl"); + //urlBase = apiUrl + "registrazioni/add"; + urlBase = "http://10.0.0.187:8000/api/Polo/registrazioni/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"); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + + #endregion CREATE + + #region DETAILS + + public IActionResult Details(int id) + { + SessionHelper helper = new SessionHelper(this); + + //token = helper.GetStringValue("tok"); + //urlBase = apiUrl + "registrazioniList"; + urlBase = "http://10.0.0.187:8000/api/Polo/RegistrazioniList"; + //urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + Registrazione reg = new Registrazione(); + + List modelList = new List(); + + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + //reg = modelList.Where(x => x.id.Equals(id)).First(); + reg = modelList.Where(x => x.id == id).First(); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + return View(reg); + } + + #endregion DETAILS + + #region EDIT + + public IActionResult Edit(int id) + { + SessionHelper helper = new SessionHelper(this); + + //token = helper.GetStringValue("tok"); + + //apiUrl = helper.GetStringValue("apiUrl"); + //urlBase = apiUrl + "chiusureVtList"; + urlBase = "http://10.0.0.187:8000/api/Polo/RegistrazioniList"; + //urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + Registrazione reg = new Registrazione(); + + List modelList = new List(); + + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + reg = modelList.Where(x => x.id == id).First(); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + + return View(reg); + } + + [HttpPost] + public IActionResult Edit(Registrazione model) + { + SessionHelper helper = new SessionHelper(this); + + //token = helper.GetStringValue("tok"); + //tenant = helper.GetStringValue("tenant"); + //if (string.IsNullOrEmpty(token)) + //{ + // return RedirectToAction("Index", "Login"); + //} + model.azienda = tenant; + //apiUrl = helper.GetStringValue("apiUrl"); + //urlBase = apiUrl + "registrazioni/mod"; + urlBase = apiUrl + "http://10.0.0.187:8000/api/Polo/registrazioni/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"); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + + #endregion EDIT + + #region DELETE + + [HttpGet] + public IActionResult Delete(int id) + { + SessionHelper helper = new SessionHelper(this); + + //token = helper.GetStringValue("tok"); + + //apiUrl = helper.GetStringValue("apiUrl"); + //urlBase = apiUrl + "chiusureVtList"; + urlBase = "http://10.0.0.187:8000/api/Polo/RegistrazioniList"; + //urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + Registrazione reg = new Registrazione(); + List modelList = new List(); + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + reg = modelList.Where(x => x.id.Equals(id)).First(); + return View(reg); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + + [HttpPost, ActionName("DeleteConfirmed")] + public IActionResult DeleteConfirmed(int id) + { + SessionHelper helper = new SessionHelper(this); + + //token = helper.GetStringValue("tok"); + + //apiUrl = helper.GetStringValue("apiUrl"); + urlBase = /*apiUrl + */"http://10.0.0.187:8000/api/Polo/Registrazioni/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"); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + + #endregion DELETE + + [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 }); + } + } +} diff --git a/Models/Registrazione.cs b/Models/Registrazione.cs new file mode 100644 index 0000000..0ae67d6 --- /dev/null +++ b/Models/Registrazione.cs @@ -0,0 +1,20 @@ +namespace VirtualTask.Models +{ + public class Registrazione + { + public int id { get; set; } + public string? nome { get; set; } + public string? cognome { get; set; } + public string? telefono { get; set;} + public string? cellulare { get; set;} + public string? email { get; set;} + public string? emailConf { get; set;} + public string? azienda { get; set; } + public string? username { get; set; } + public string? passwd { get; set;} + public string? citta { get; set;} + public string? provincia { get; set;} + public string? nazione { get; set;} + public string? attivato { get; set;} + } +} diff --git a/Views/Portale/Index.cshtml b/Views/Portale/Index.cshtml index 6018b76..a1d9e88 100644 --- a/Views/Portale/Index.cshtml +++ b/Views/Portale/Index.cshtml @@ -138,7 +138,7 @@ Purchase: Home
  • About Us
  • -
  • Services
  • +
  • Registrati
  • Area Riservata
  • Blog diff --git a/Views/Registrazioni/Create.cshtml b/Views/Registrazioni/Create.cshtml new file mode 100644 index 0000000..64e5521 --- /dev/null +++ b/Views/Registrazioni/Create.cshtml @@ -0,0 +1,99 @@ +@model VirtualTask.Models.Registrazione + +@{ + ViewData["Title"] = "Create"; +} + +

    Registrazione nuovo utente

    + + +
    +
    +
    +
    +
    + @*
    + + + +
    *@ + @Html.HiddenFor(x => x.id) +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + +
    +
    +
    +
    + + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/Views/Registrazioni/Delete.cshtml b/Views/Registrazioni/Delete.cshtml new file mode 100644 index 0000000..519dc00 --- /dev/null +++ b/Views/Registrazioni/Delete.cshtml @@ -0,0 +1,104 @@ +@model VirtualTask.Models.Registrazione + +@{ + ViewData["Title"] = "Delete"; +} + +

    Elimina

    + +

    Vuoi eliminare l'elemento?

    +
    +

    Registrazione

    +
    +
    +
    + @Html.DisplayNameFor(model => model.id) +
    +
    + @Html.DisplayFor(model => model.id) +
    +
    + @Html.DisplayNameFor(model => model.nome) +
    +
    + @Html.DisplayFor(model => model.nome) +
    +
    + @Html.DisplayNameFor(model => model.cognome) +
    +
    + @Html.DisplayFor(model => model.cognome) +
    +
    + @Html.DisplayNameFor(model => model.telefono) +
    +
    + @Html.DisplayFor(model => model.telefono) +
    +
    + @Html.DisplayNameFor(model => model.cellulare) +
    +
    + @Html.DisplayFor(model => model.cellulare) +
    +
    + @Html.DisplayNameFor(model => model.email) +
    +
    + @Html.DisplayFor(model => model.email) +
    +
    + @Html.DisplayNameFor(model => model.emailConf) +
    +
    + @Html.DisplayFor(model => model.emailConf) +
    +
    + @Html.DisplayNameFor(model => model.azienda) +
    +
    + @Html.DisplayFor(model => model.azienda) +
    +
    + @Html.DisplayNameFor(model => model.username) +
    +
    + @Html.DisplayFor(model => model.username) +
    +
    + @Html.DisplayNameFor(model => model.passwd) +
    +
    + @Html.DisplayFor(model => model.passwd) +
    +
    + @Html.DisplayNameFor(model => model.citta) +
    +
    + @Html.DisplayFor(model => model.citta) +
    +
    + @Html.DisplayNameFor(model => model.provincia) +
    +
    + @Html.DisplayFor(model => model.provincia) +
    +
    + @Html.DisplayNameFor(model => model.nazione) +
    +
    + @Html.DisplayFor(model => model.nazione) +
    +
    + @Html.DisplayNameFor(model => model.attivato) +
    +
    + @Html.DisplayFor(model => model.attivato) +
    +
    + +
    + | + Torna indietro +
    +
    diff --git a/Views/Registrazioni/Details.cshtml b/Views/Registrazioni/Details.cshtml new file mode 100644 index 0000000..59bf043 --- /dev/null +++ b/Views/Registrazioni/Details.cshtml @@ -0,0 +1,102 @@ +@model VirtualTask.Models.Registrazione + +@{ + ViewData["Title"] = "Details"; +} + +

    Dettaglio

    + +
    + +
    +
    +
    + @Html.DisplayNameFor(model => model.id) +
    +
    + @Html.DisplayFor(model => model.id) +
    +
    + @Html.DisplayNameFor(model => model.nome) +
    +
    + @Html.DisplayFor(model => model.nome) +
    +
    + @Html.DisplayNameFor(model => model.cognome) +
    +
    + @Html.DisplayFor(model => model.cognome) +
    +
    + @Html.DisplayNameFor(model => model.telefono) +
    +
    + @Html.DisplayFor(model => model.telefono) +
    +
    + @Html.DisplayNameFor(model => model.cellulare) +
    +
    + @Html.DisplayFor(model => model.cellulare) +
    +
    + @Html.DisplayNameFor(model => model.email) +
    +
    + @Html.DisplayFor(model => model.email) +
    +
    + @Html.DisplayNameFor(model => model.emailConf) +
    +
    + @Html.DisplayFor(model => model.emailConf) +
    +
    + @Html.DisplayNameFor(model => model.azienda) +
    +
    + @Html.DisplayFor(model => model.azienda) +
    +
    + @Html.DisplayNameFor(model => model.username) +
    +
    + @Html.DisplayFor(model => model.username) +
    +
    + @Html.DisplayNameFor(model => model.passwd) +
    +
    + @Html.DisplayFor(model => model.passwd) +
    +
    + @Html.DisplayNameFor(model => model.citta) +
    +
    + @Html.DisplayFor(model => model.citta) +
    +
    + @Html.DisplayNameFor(model => model.provincia) +
    +
    + @Html.DisplayFor(model => model.provincia) +
    +
    + @Html.DisplayNameFor(model => model.nazione) +
    +
    + @Html.DisplayFor(model => model.nazione) +
    +
    + @Html.DisplayNameFor(model => model.attivato) +
    +
    + @Html.DisplayFor(model => model.attivato) +
    +
    +
    +
    + @Html.ActionLink("Modifica", "Edit", new { /* id = Model.PrimaryKey */ }) | + Torna indietro +
    diff --git a/Views/Registrazioni/Edit.cshtml b/Views/Registrazioni/Edit.cshtml new file mode 100644 index 0000000..4fb565d --- /dev/null +++ b/Views/Registrazioni/Edit.cshtml @@ -0,0 +1,98 @@ +@model VirtualTask.Models.Registrazione + +@{ + ViewData["Title"] = "Edit"; +} + +

    Modifica

    + + +
    +
    +
    +
    +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + +
    +
    +
    +
    + + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/Views/Registrazioni/Index.cshtml b/Views/Registrazioni/Index.cshtml new file mode 100644 index 0000000..bd328de --- /dev/null +++ b/Views/Registrazioni/Index.cshtml @@ -0,0 +1,130 @@ +@using X.PagedList.Mvc.Core; +@using X.PagedList.Web.Common; +@using X.PagedList; +@model IPagedList + +@{ + ViewData["Title"] = "Index"; +} + +

    Index

    + +

    + Nuovo +

    + + + + + + + + + + + + + + + + + + + + + +@foreach (var item in Model) { + + + + + + + + + + + + + + + + + +} + +
    + @* @Html.DisplayNameFor(model => model.id) *@ + ID + + @* @Html.DisplayNameFor(model => model.nome) *@ + NOME + + @* @Html.DisplayNameFor(model => model.cognome) *@ + COGNOME + + @* @Html.DisplayNameFor(model => model.telefono) *@ + TELEFONO + + @* @Html.DisplayNameFor(model => model.cellulare) *@ + CELLULARE + + @* @Html.DisplayNameFor(model => model.email) *@ + EMAIL + + @* @Html.DisplayNameFor(model => model.emailConf) *@ + EMAIL CONFERMA + + @* @Html.DisplayNameFor(model => model.azienda) *@ + AZIENDA + + @* @Html.DisplayNameFor(model => model.username) *@ + USERNAME + + @* @Html.DisplayNameFor(model => model.passwd) *@ + PASSWORD + + @* @Html.DisplayNameFor(model => model.citta) *@ + CITTA' + + @* @Html.DisplayNameFor(model => model.provincia) *@ + PROVINCIA + + @* @Html.DisplayNameFor(model => model.nazione) *@ + NAZIONE + + @* @Html.DisplayNameFor(model => model.attivato) *@ + ATTIVATO +
    + @Html.DisplayFor(modelItem => item.id) + + @Html.DisplayFor(modelItem => item.nome) + + @Html.DisplayFor(modelItem => item.cognome) + + @Html.DisplayFor(modelItem => item.telefono) + + @Html.DisplayFor(modelItem => item.cellulare) + + @Html.DisplayFor(modelItem => item.email) + + @Html.DisplayFor(modelItem => item.emailConf) + + @Html.DisplayFor(modelItem => item.azienda) + + @Html.DisplayFor(modelItem => item.username) + + @Html.DisplayFor(modelItem => item.passwd) + + @Html.DisplayFor(modelItem => item.citta) + + @Html.DisplayFor(modelItem => item.provincia) + + @Html.DisplayFor(modelItem => item.nazione) + + @Html.DisplayFor(modelItem => item.attivato) + + @Html.ActionLink("Modifica", "Edit", new { id=item.id }) | + @Html.ActionLink("Dettaglio", "Details", new { id=item.id }) | + @Html.ActionLink("Elimina", "Delete", new { id=item.id }) +