CONTROLLO LOGIN 2 + CONTROLLO ERRORE CAMPO COD FIS SU CREATE

This commit is contained in:
michele 2023-12-06 12:57:21 +01:00
parent 76b064389f
commit 5b51e4f593
9 changed files with 120 additions and 54 deletions

View File

@ -43,8 +43,11 @@ namespace VirtualTask.Controllers
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return RedirectToAction("Index", "Login"); {
return RedirectToAction("Login2", "Login");
}
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin"); admin = helper.GetStringValue("admin");
@ -110,6 +113,10 @@ namespace VirtualTask.Controllers
[HttpPost] [HttpPost]
public IActionResult Create(Anag model) public IActionResult Create(Anag model)
{ {
SessionHelper helper = new SessionHelper(this);
admin = helper.GetStringValue("admin");
ViewBag.Admin = admin;
AnagCommImp anagCommImp = new AnagCommImp(); AnagCommImp anagCommImp = new AnagCommImp();
if (ModelState.IsValid) if (ModelState.IsValid)
@ -130,17 +137,16 @@ namespace VirtualTask.Controllers
if (string.IsNullOrEmpty(sCodFis)) if (string.IsNullOrEmpty(sCodFis))
{ {
bparivaOK = true; bcodfiscOK = true;
} }
else else
{ {
bcodfiscOK = CodiceFiscale.VerificaCodiceFiscale(sCodFis); bcodfiscOK = CodiceFiscale.VerificaCodiceFiscale(sCodFis);
} }
if (!bcodfiscOK) if (!bcodfiscOK)
{ {
ModelState.AddModelError("andescri", "Codice Fiscale non corretto"); ModelState.AddModelError("ancodfis", "Codice Fiscale non corretto");
} }
if (!bparivaOK) if (!bparivaOK)
{ {
@ -149,7 +155,7 @@ namespace VirtualTask.Controllers
if (bcodfiscOK && bparivaOK) if (bcodfiscOK && bparivaOK)
{ {
SessionHelper helper = new SessionHelper(this); //SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
tenant = helper.GetStringValue("tenant"); tenant = helper.GetStringValue("tenant");
@ -312,33 +318,78 @@ namespace VirtualTask.Controllers
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); admin = helper.GetStringValue("admin");
tenant = helper.GetStringValue("tenant"); ViewBag.Admin = admin;
model.ancodazi = tenant;
apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "anagrafiche/mod";
urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
client.BaseAddress = baseAddress;
string data = JsonConvert.SerializeObject(model); bool bcodfiscOK = false;
bool bparivaOK = false;
string sCodFis = !string.IsNullOrEmpty(model.ancodfis) ? model.ancodfis : string.Empty;
string sParIva = !string.IsNullOrEmpty(model.anpariva) ? model.anpariva : string.Empty;
StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); if (string.IsNullOrEmpty(sParIva))
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
if (response.IsSuccessStatusCode)
{ {
return RedirectToAction("Index"); bparivaOK = true;
} }
else else
{ {
errMes = response.Content.ReadAsStringAsync().Result; bparivaOK = _checkVatItaFormale("IT", sParIva);
helper.SetStringValue("errMsg", errMes);
return RedirectToAction("Error");
} }
if (string.IsNullOrEmpty(sCodFis))
{
bcodfiscOK = true;
}
else
{
bcodfiscOK = CodiceFiscale.VerificaCodiceFiscale(sCodFis);
}
if (!bcodfiscOK)
{
ModelState.AddModelError("ancodfis", "Codice Fiscale non corretto");
}
if (!bparivaOK)
{
ModelState.AddModelError("anpariva", "Partita Iva non corretta");
}
if (bcodfiscOK && bparivaOK)
{
//SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok");
tenant = helper.GetStringValue("tenant");
model.ancodazi = tenant;
apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "anagrafiche/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");
}
}
else
{
return View("Edit", model);
}
} }
#endregion EDIT #endregion EDIT

View File

@ -35,8 +35,13 @@ namespace VirtualTask.Controllers
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
//if (string.IsNullOrEmpty(token))
// return RedirectToAction("Index", "Login");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return RedirectToAction("Index", "Login"); {
return RedirectToAction("Login2", "Login");
}
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin"); admin = helper.GetStringValue("admin");
@ -109,7 +114,7 @@ namespace VirtualTask.Controllers
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
{ {
return RedirectToAction("Index", "Login"); return RedirectToAction("Login2", "Login");
} }
model.pirifazi = tenant; model.pirifazi = tenant;
@ -227,7 +232,7 @@ namespace VirtualTask.Controllers
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
{ {
return RedirectToAction("Index", "Login"); return RedirectToAction("Login2", "Login");
} }
model.pirifazi = token; model.pirifazi = token;

View File

@ -40,8 +40,9 @@ namespace VirtualTask.Controllers
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return RedirectToAction("Index", "Login"); {
return RedirectToAction("Login2", "Login");
}
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin"); admin = helper.GetStringValue("admin");
ViewBag.Admin = admin; ViewBag.Admin = admin;
@ -116,7 +117,7 @@ namespace VirtualTask.Controllers
tenant = helper.GetStringValue("tenant"); tenant = helper.GetStringValue("tenant");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
{ {
return RedirectToAction("Index","Login"); return RedirectToAction("Login2","Login");
} }
#region campi da impostare #region campi da impostare
@ -268,7 +269,7 @@ namespace VirtualTask.Controllers
tenant = helper.GetStringValue("tenant"); tenant = helper.GetStringValue("tenant");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
{ {
return RedirectToAction("Index", "Login"); return RedirectToAction("Login2", "Login");
} }
model.chcodazi = tenant; model.chcodazi = tenant;
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");

View File

@ -38,7 +38,9 @@ namespace VirtualTask.Controllers
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return RedirectToAction("Index", "Login"); {
return RedirectToAction("Login2", "Login");
}
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin"); admin = helper.GetStringValue("admin");
@ -109,7 +111,7 @@ namespace VirtualTask.Controllers
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
{ {
return RedirectToAction("Index", "Login"); return RedirectToAction("Login2", "Login");
} }
model.cccodazi = tenant; model.cccodazi = tenant;

View File

@ -39,8 +39,12 @@ namespace VirtualTask.Controllers
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
//if (string.IsNullOrEmpty(token))
// return RedirectToAction("Index", "Login");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return RedirectToAction("Index", "Login"); {
return RedirectToAction("Login2", "Login");
}
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin"); admin = helper.GetStringValue("admin");
@ -122,7 +126,7 @@ namespace VirtualTask.Controllers
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
{ {
return RedirectToAction("Index", "Login"); return RedirectToAction("Login2", "Login");
} }
model.lacodazi = tenant; model.lacodazi = tenant;

View File

@ -36,9 +36,11 @@ namespace VirtualTask.Controllers
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return RedirectToAction("Index", "Login"); {
return RedirectToAction("Login2", "Login");
}
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin"); admin = helper.GetStringValue("admin");
@ -106,8 +108,14 @@ namespace VirtualTask.Controllers
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
tenant = helper.GetStringValue("tenant"); tenant = helper.GetStringValue("tenant");
//if (string.IsNullOrEmpty(token))
// return RedirectToAction("Index", "Login");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return RedirectToAction("Index", "Login"); {
return RedirectToAction("Login2", "Login");
}
model.imcodazi = tenant; model.imcodazi = tenant;
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");

View File

@ -36,7 +36,9 @@ namespace VirtualTask.Controllers
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return RedirectToAction("Index", "Login"); {
return RedirectToAction("Login2", "Login");
}
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin"); admin = helper.GetStringValue("admin");

View File

@ -36,7 +36,9 @@ namespace VirtualTask.Controllers
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return RedirectToAction("Index", "Login"); {
return RedirectToAction("Login2", "Login");
}
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin"); admin = helper.GetStringValue("admin");

View File

@ -18,19 +18,9 @@ namespace VirtualTask.Controllers
string errMes = string.Empty; string errMes = string.Empty;
string admin = string.Empty; string admin = string.Empty;
//MF commentati perchè L'Uri viene costruito
//Uri baseAddress = new Uri("http://10.0.0.187:8000/api/Polo/tecniciList?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVEVTVCIsImp0aSI6IjA2MzA5MzlmLTBhZDgtNDhkMi04ZTI5LWI3Mjk3N2IyOWM1YiIsInRlbmFudCI6Ik1BUlJPIiwidGNjb2RpY2UiOiJaWlogICAgICAgICAgICAiLCJleHAiOjE3MDE3Njk0NTUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjE5NTUiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CDt3wR6ube4zzNscVG9Qv6bzOnNF6A9-bIZxxjbKmKI");
HttpClient client; HttpClient client;
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
//Uri baseAddressCreate = new Uri("http://10.0.0.187:8000/api/Polo/tecnici/add?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVEVTVCIsImp0aSI6IjA2MzA5MzlmLTBhZDgtNDhkMi04ZTI5LWI3Mjk3N2IyOWM1YiIsInRlbmFudCI6Ik1BUlJPIiwidGNjb2RpY2UiOiJaWlogICAgICAgICAgICAiLCJleHAiOjE3MDE3Njk0NTUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjE5NTUiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CDt3wR6ube4zzNscVG9Qv6bzOnNF6A9-bIZxxjbKmKI");
//HttpClient clientCreate;
//Uri baseAddressEdit = new Uri("http://10.0.0.187:8000/api/Polo/tecnici/mod?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVEVTVCIsImp0aSI6IjA2MzA5MzlmLTBhZDgtNDhkMi04ZTI5LWI3Mjk3N2IyOWM1YiIsInRlbmFudCI6Ik1BUlJPIiwidGNjb2RpY2UiOiJaWlogICAgICAgICAgICAiLCJleHAiOjE3MDE3Njk0NTUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjE5NTUiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CDt3wR6ube4zzNscVG9Qv6bzOnNF6A9-bIZxxjbKmKI");
//HttpClient clientEdit;
//Uri baseAddressDelete = new Uri("http://10.0.0.187:8000/api/Polo/tecnici/del?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVEVTVCIsImp0aSI6IjA2MzA5MzlmLTBhZDgtNDhkMi04ZTI5LWI3Mjk3N2IyOWM1YiIsInRlbmFudCI6Ik1BUlJPIiwidGNjb2RpY2UiOiJaWlogICAgICAgICAgICAiLCJleHAiOjE3MDE3Njk0NTUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjE5NTUiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CDt3wR6ube4zzNscVG9Qv6bzOnNF6A9-bIZxxjbKmKI");
//HttpClient clientDelete;
public TecniciController(IConfiguration configuration) public TecniciController(IConfiguration configuration)
{ {
@ -47,7 +37,9 @@ namespace VirtualTask.Controllers
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return RedirectToAction("Index", "Login"); {
return RedirectToAction("Login2", "Login");
}
apiUrl = helper.GetStringValue("apiUrl"); apiUrl = helper.GetStringValue("apiUrl");
admin = helper.GetStringValue("admin"); admin = helper.GetStringValue("admin");
@ -118,7 +110,7 @@ namespace VirtualTask.Controllers
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
{ {
return RedirectToAction("Index", "Login"); return RedirectToAction("Login2", "Login");
} }
model.tccodazi = tenant; model.tccodazi = tenant;
@ -218,7 +210,6 @@ namespace VirtualTask.Controllers
string data = response.Content.ReadAsStringAsync().Result; string data = response.Content.ReadAsStringAsync().Result;
modelList = JsonConvert.DeserializeObject<List<Tecnici>>(data); modelList = JsonConvert.DeserializeObject<List<Tecnici>>(data);
tecnico = modelList.Where(x => x.tccodice.Equals(id)).First(); tecnico = modelList.Where(x => x.tccodice.Equals(id)).First();
} }
else else
{ {
@ -240,7 +231,7 @@ namespace VirtualTask.Controllers
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
{ {
return RedirectToAction("Index", "Login"); return RedirectToAction("Login2", "Login");
} }
tecnico.tccodazi = tenant; tecnico.tccodazi = tenant;