registrazioni

This commit is contained in:
Marco Audiffredi 2023-11-08 15:41:20 +01:00
parent 893143a8a5
commit e731c78676
9 changed files with 220 additions and 106 deletions

View File

@ -116,7 +116,7 @@ namespace VirtualTask.Controllers
ModelState.AddModelError("anpariva", "Partita Iva non corretta");
}
if (bcodfiscOK)
if (bcodfiscOK && bparivaOK)
{
SessionHelper helper = new SessionHelper(this);

View File

@ -13,20 +13,27 @@ namespace VirtualTask.Controllers
HttpClient client;
SessionHelper helper;
string errMes=string.Empty;
public LoginController()
private readonly IConfiguration _configuration;
public LoginController(IConfiguration configuration)
{
apiUrl = "http://10.0.0.187:8000/api/Polo/";
//apiUrl = "http://10.0.0.187:8000/api/Polo/";
//apiUrl = "http://testapi.poloinformatico.it:9001/api/Polo/";
client = new HttpClient();
helper = new SessionHelper(this);
_configuration = configuration;
var key = _configuration["ApplicationInsights:rootUrlApi"];
apiUrl = key;
}
public IActionResult Index()
{
return View();
}
public IActionResult Login()
{
return View();
}
//public IActionResult Login()
//{
// return View();
//}
[HttpPost]
@ -68,39 +75,39 @@ namespace VirtualTask.Controllers
{
return View();
}
[HttpPost]
public IActionResult Login2(Login model)
{
string url = apiUrl + "loginTechnicalVT";
Uri baseAddress = new Uri(url);
client.BaseAddress = baseAddress;
ViewBag.Error = string.Empty;
//[HttpPost]
//public IActionResult Login2(Login model)
//{
// string url = apiUrl + "loginTechnicalVT";
// Uri baseAddress = new Uri(url);
// client.BaseAddress = baseAddress;
// ViewBag.Error = string.Empty;
LoginOut loginOut = new LoginOut();
string data = JsonConvert.SerializeObject(model);
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
if (response.IsSuccessStatusCode)
{
string risultato = response.Content.ReadAsStringAsync().Result;
loginOut = JsonConvert.DeserializeObject<LoginOut>(risultato);
// LoginOut loginOut = new LoginOut();
// string data = JsonConvert.SerializeObject(model);
// StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
// HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
// if (response.IsSuccessStatusCode)
// {
// string risultato = response.Content.ReadAsStringAsync().Result;
// loginOut = JsonConvert.DeserializeObject<LoginOut>(risultato);
helper.SetStringValue("tok", loginOut.Tok);
helper.SetStringValue("apiUrl", apiUrl);
helper.SetStringValue("tenant", model.Tenant);
helper.SetStringValue("tecnico", model.Username);
return RedirectToAction("Index", "Home");
}
else
{
errMes = response.Content.ReadAsStringAsync().Result;
loginOut = JsonConvert.DeserializeObject<LoginOut>(errMes);
// helper.SetStringValue("tok", loginOut.Tok);
// helper.SetStringValue("apiUrl", apiUrl);
// helper.SetStringValue("tenant", model.Tenant);
// helper.SetStringValue("tecnico", model.Username);
// return RedirectToAction("Index", "Home");
// }
// else
// {
// errMes = response.Content.ReadAsStringAsync().Result;
// loginOut = JsonConvert.DeserializeObject<LoginOut>(errMes);
helper.SetStringValue("errMsg", loginOut.err_detail);
ViewBag.Error = loginOut.err_detail;
return View();
}
}
// helper.SetStringValue("errMsg", loginOut.err_detail);
// ViewBag.Error = loginOut.err_detail;
// return View();
// }
//}
}
}

View File

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using VirtualTask.Models;
using X.PagedList;
@ -16,10 +17,14 @@ namespace VirtualTask.Controllers
string errMes = string.Empty;
HttpClient client;
private readonly IConfiguration _configuration;
public RegistrazioniController()
public RegistrazioniController(IConfiguration configuration)
{
client = new HttpClient();
_configuration = configuration;
var key = _configuration["ApplicationInsights:rootUrlApi"];
apiUrl = key;
}
#region INDEX
@ -27,15 +32,8 @@ namespace VirtualTask.Controllers
public IActionResult Index(string searchString, int? page = 1)
{
SessionHelper helper = new SessionHelper(this);
//token = helper.GetStringValue("tok");
urlBase = apiUrl + "RegistrazioniList";
//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;
@ -94,40 +92,70 @@ namespace VirtualTask.Controllers
{
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)
if (ModelState.IsValid)
{
return RedirectToAction("Index");
bool bAziPres = false;
bAziPres = checkAziendaPresente(model.azienda);
if (bAziPres)
{
ModelState.AddModelError("azienda", "Azienda presente in archivio. Inserire un valore diverso.");
}
bool bEmail = model.email.Equals(model.emailConf);
if (!bEmail)
{
ModelState.AddModelError("email", "I campi Email e Conferma Email devono essere uguali");
}
if (!bAziPres && bEmail)
{
urlBase = apiUrl + "registrazioni/add";
//urlBase = "http://10.0.0.187:8000/api/Polo/registrazioni/add";
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("RegistrazioneOk");
}
else
{
errMes = response.Content.ReadAsStringAsync().Result;
helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error");
}
}
else
{
return View("Create", model);
}
}
else
{
errMes = response.Content.ReadAsStringAsync().Result;
helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error");
foreach (var Elemento in ModelState.Values)
{
foreach (var Errore in Elemento.Errors)
{
string ErroreRilevato = Errore.ErrorMessage;
}
}
return View("Create", model);
}
}
public IActionResult RegistrazioneOk()
{
return View();
}
#endregion CREATE
#region DETAILS
@ -136,10 +164,9 @@ namespace VirtualTask.Controllers
{
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;
urlBase = apiUrl + "registrazioniList";
//urlBase = "http://10.0.0.187:8000/api/Polo/RegistrazioniList";
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
client.BaseAddress = baseAddress;
@ -154,7 +181,6 @@ namespace VirtualTask.Controllers
{
string data = response.Content.ReadAsStringAsync().Result;
modelList = JsonConvert.DeserializeObject<List<Registrazione>>(data);
//reg = modelList.Where(x => x.id.Equals(id)).First();
reg = modelList.Where(x => x.id == id).First();
}
else
@ -319,5 +345,33 @@ namespace VirtualTask.Controllers
string e = helper.GetStringValue("errMsg");
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrMsg = e });
}
private bool checkAziendaPresente(string azienda)
{
bool trovato = false;
bool bAziPres = false;
//urlBase = "http://10.0.0.187:8000/api/Polo/AziendePresentiList";
urlBase = apiUrl + "AziendePresentiList";
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
client.BaseAddress = baseAddress;
List<AziendaPres> modelList = new List<AziendaPres>();
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
if (response.IsSuccessStatusCode)
{
string data = response.Content.ReadAsStringAsync().Result;
modelList = JsonConvert.DeserializeObject<List<AziendaPres>>(data);
foreach(AziendaPres a in modelList)
{
if(!string.IsNullOrEmpty(a.tccodazi) && a.tccodazi.Trim().Equals(azienda))
trovato = true;
}
bAziPres = trovato;
}
return bAziPres;
}
}
}

7
Models/AziendaPres.cs Normal file
View File

@ -0,0 +1,7 @@
namespace VirtualTask.Models
{
public class AziendaPres
{
public string? tccodazi { get; set; }
}
}

View File

@ -1,17 +1,41 @@
namespace VirtualTask.Models
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;
namespace VirtualTask.Models
{
public class Registrazione
{
public int id { get; set; }
[Display(Name = "Nome"), Required(ErrorMessage = "Nome obbligatorio")]
public string? nome { get; set; }
[Display(Name = "Cognome"), Required(ErrorMessage = "Cognome obbligatorio")]
public string? cognome { get; set; }
[Display(Name = "Telefono"), Required(ErrorMessage = "Telefono obbligatorio")]
public string? telefono { get; set;}
[Display(Name = "Cellulare"), Required(ErrorMessage = "Cellulare obbligatorio")]
public string? cellulare { get; set;}
[RegularExpression("^[a-zA-Z0-9_\\.-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", ErrorMessage = "formato campo Email non valido")]
[Display(Name = "Email"), Required(ErrorMessage = "Email obbligatorio")]
public string? email { get; set;}
[RegularExpression("^[a-zA-Z0-9_\\.-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", ErrorMessage = "formato campo Conferma Email non valido")]
[Display(Name = "Conferma Email"), Required(ErrorMessage = "Conferma Email obbligatorio")]
public string? emailConf { get; set;}
[Display(Name = "Azienda"), Required(ErrorMessage = "Azienda obbligatorio")]
public string? azienda { get; set; }
[Display(Name = "Username"), Required(ErrorMessage = "Username obbligatorio")]
public string? username { get; set; }
[Display(Name = "Password"), Required(ErrorMessage = "Password obbligatorio")]
public string? passwd { get; set;}
public string? citta { get; set;}
public string? provincia { get; set;}
public string? nazione { get; set;}

View File

@ -11,90 +11,93 @@
<h4 class="agy-sub-heading">@ViewData["Title"]</h4>
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
@Html.HiddenFor(x => x.id)
@Html.HiddenFor(x => x.attivato)
@Html.ValidationSummary(false, "", new { @class = "text-danger" })
<input type="hidden" id="id" value="0" name="id" />
<input type="hidden" id="attivato" value="N" name="attivato" />
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="nome" class="agy-form-field require" placeholder="Nome" />
<span asp-validation-for="nome" class="text-danger"></span>
<input asp-for="nome" class="agy-form-field" placeholder="Nome" />
@* <span asp-validation-for="nome" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="cognome" class="agy-form-field require" placeholder="Cognome" />
<span asp-validation-for="cognome" class="text-danger"></span>
<input asp-for="cognome" class="agy-form-field" placeholder="Cognome" />
@*<span asp-validation-for="cognome" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="telefono" class="agy-form-field require" placeholder="Telefono" />
<span asp-validation-for="telefono" class="text-danger"></span>
<input asp-for="telefono" class="agy-form-field" placeholder="Telefono" />
@*<span asp-validation-for="telefono" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="cellulare" class="agy-form-field require" placeholder="Cellulare" />
<span asp-validation-for="cellulare" class="text-danger"></span>
<input asp-for="cellulare" class="agy-form-field" placeholder="Cellulare" />
@*<span asp-validation-for="cellulare" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="email" class="agy-form-field require" placeholder="Email" />
<span asp-validation-for="email" class="text-danger"></span>
<input asp-for="email" class="agy-form-field" placeholder="Email" />
@*<span asp-validation-for="email" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="emailConf" class="agy-form-field require" placeholder="Conferma Email" />
<span asp-validation-for="emailConf" class="text-danger"></span>
<input asp-for="emailConf" class="agy-form-field" placeholder="Conferma Email" />
@*<span asp-validation-for="emailConf" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="azienda" class="agy-form-field require" placeholder="Azienda" />
<span asp-validation-for="azienda" class="text-danger"></span>
<input asp-for="azienda" class="agy-form-field" placeholder="Azienda" />
@*<span asp-validation-for="azienda" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="citta" class="agy-form-field require" placeholder="Città" />
<span asp-validation-for="citta" class="text-danger"></span>
<input asp-for="citta" class="agy-form-field" placeholder="Città" />
@*<span asp-validation-for="citta" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="provincia" class="agy-form-field require" placeholder="Provincia" />
<span asp-validation-for="provincia" class="text-danger"></span>
<input asp-for="provincia" class="agy-form-field" placeholder="Provincia" />
@*<span asp-validation-for="provincia" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="nazione" class="agy-form-field require" placeholder="Nazione" />
<span asp-validation-for="nazione" class="text-danger"></span>
<input asp-for="nazione" class="agy-form-field" placeholder="Nazione" />
@*<span asp-validation-for="nazione" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="username" class="agy-form-field require" placeholder="Username" />
<span asp-validation-for="username" class="text-danger"></span>
<input asp-for="username" class="agy-form-field" placeholder="Username" />
@* <span asp-validation-for="username" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="agy-field-holder">
<input asp-for="passwd" class="agy-form-field require" placeholder="Password" />
<span asp-validation-for="passwd" class="text-danger"></span>
<input asp-for="passwd" class="agy-form-field" placeholder="Password" />
@* <span asp-validation-for="passwd" class="text-danger"></span>*@
</div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-12">
<button type="button" class="agy-btn submitForm">Submit</button>
<button type="submit" class="agy-btn submitForm">Submit</button>
<div class="response"></div>
</div>
</div>

View File

@ -0,0 +1,15 @@
@{
ViewData["Title"] = "Registrazione Inviata con successo";
Layout = "~/Views/Shared/_Layout2.cshtml";
}
<div class="col-lg-8 col-md-12 col-sm-12 col-12">
<div class="agy-contact-form">
<h4 class="agy-sub-heading">@ViewData["Title"]</h4>
<div class="row">Grazie per esserti registrato</div>
</div>
</div>

View File

@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<PublishSingleFile>false</PublishSingleFile>
</PropertyGroup>
<ItemGroup>

View File

@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"ApplicationInsights": {
"rootUrlApi": "http://testapi.poloinformatico.it:9001/api/Polo/"
},
"AllowedHosts": "*"
}