1011 lines
39 KiB
C#
1011 lines
39 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using NuGet.Protocol.Plugins;
|
|
using System.Diagnostics;
|
|
using System.Net.Mail;
|
|
using System.Net;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using VirtualTask.Models;
|
|
using X.PagedList;
|
|
using Humanizer;
|
|
using System.Numerics;
|
|
using System.Reflection.Metadata;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using NuGet.Common;
|
|
using System.Security.Policy;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
|
|
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;
|
|
string admin = string.Empty;
|
|
string urlConfirm = string.Empty;
|
|
string time_sheet=string.Empty;
|
|
|
|
|
|
HttpClient client;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly IHttpContextAccessor _context;
|
|
|
|
public RegistrazioniController(IConfiguration configuration, IHttpContextAccessor context)
|
|
{
|
|
|
|
client = new HttpClient();
|
|
_configuration = configuration;
|
|
var key = _configuration["ApplicationInsights:rootUrlApi"];
|
|
apiUrl = key;
|
|
_context = context;
|
|
var request = _context.HttpContext.Request;
|
|
urlConfirm=_configuration["ApplicationInsights:rootUrl"];
|
|
}
|
|
|
|
#region INDEX
|
|
|
|
public IActionResult Index(string searchString, int? page = 1)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
urlBase = apiUrl + "RegistrazioniList";
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
time_sheet = helper.GetStringValue("time_sheet");
|
|
ViewBag.TimeSheet = time_sheet;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<Registrazione> modelList = new List<Registrazione>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Registrazione>>(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);
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
string tokenMail = RandomString(10);
|
|
model.token = tokenMail;
|
|
bool bAziPres = false;
|
|
bool privacy1=false;
|
|
|
|
Controllo cUtePres = isLoginPresente(model.username, model.passwd, helper);
|
|
if (cUtePres.isPresente)
|
|
{
|
|
ModelState.AddModelError("tcuser", "Login già utilizzata. Scegliere un nome utente differente");
|
|
}
|
|
|
|
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(model.privacy1==false)
|
|
{
|
|
ModelState.AddModelError("privacy1", "E' necessario accettare la privacy");
|
|
privacy1 = true;
|
|
}
|
|
if (model.ModuloRapportini == false && model.ModuloTimesheet == false)
|
|
{
|
|
ModelState.AddModelError("ModuloRapportini", "E' necessario indicare il modulo che si vuole attivare");
|
|
privacy1 = true;
|
|
}
|
|
|
|
if (!bAziPres && bEmail && !privacy1 && !cUtePres.isPresente)
|
|
{
|
|
urlBase = apiUrl + "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)
|
|
{
|
|
//mando mail avvenuta richiesta
|
|
string message = getMailText(model.cognome, tokenMail, model.email);
|
|
string subject = _configuration["ApplicationInsights:subjectMail"];
|
|
bool esito = MailSent(model.email, subject, message);
|
|
bool esito2 = MailSent("audiffredi@poloinformatico.it", subject, message);
|
|
bool esito3 = MailSent("ferri@poloinformatico.it", subject, message);
|
|
return RedirectToAction("RegistrazioneOk");
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return View("Create", model);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
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();
|
|
}
|
|
|
|
public async Task<ActionResult> ConfirmEmail(string Token, string Email)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
urlBase = apiUrl + "RegistrazioniList";
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<Registrazione> modelList = new List<Registrazione>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Registrazione>>(data);
|
|
|
|
var reg=modelList.Where(t=>t.email.Equals(Email)&& t.token.Equals(Token)).ToList();
|
|
var trovato = reg.First();
|
|
|
|
UpdRegistrazione(trovato);
|
|
//mando mail riepilogo dati registrazione
|
|
string message = getMailTextRiepilogo(trovato);
|
|
string subject= _configuration["ApplicationInsights:subjectMailRiepilogo"];
|
|
bool esito = MailSent(trovato.email, subject, message);
|
|
return RedirectToAction("RegistrazioneFinished");
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
|
|
public IActionResult RegistrazioneFinished()
|
|
{
|
|
return View();
|
|
}
|
|
#endregion CREATE
|
|
|
|
#region DETAILS
|
|
|
|
public IActionResult Details(int id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
urlBase = apiUrl + "registrazioniList";
|
|
//urlBase = "http://10.0.0.187:8000/api/Polo/RegistrazioniList";
|
|
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
Registrazione reg = new Registrazione();
|
|
|
|
List<Registrazione> modelList = new List<Registrazione>();
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Registrazione>>(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);
|
|
}
|
|
|
|
#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 = apiUrl + "registrazioniList";
|
|
|
|
//urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
Registrazione reg = new Registrazione();
|
|
|
|
List<Registrazione> modelList = new List<Registrazione>();
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Registrazione>>(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;
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
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;
|
|
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
|
|
Registrazione reg = new Registrazione();
|
|
List<Registrazione> modelList = new List<Registrazione>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Registrazione>>(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?" + "id=" + id /*+ "&"*/;
|
|
//urlBase = urlBase + "token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
|
|
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
|
|
|
|
#region ATTIVA
|
|
[HttpGet]
|
|
public IActionResult Attiva(int id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
//token = helper.GetStringValue("tok");
|
|
|
|
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;
|
|
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
|
|
Registrazione reg = new Registrazione();
|
|
List<Registrazione> modelList = new List<Registrazione>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Registrazione>>(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]
|
|
public IActionResult Attiva(Registrazione model)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
token = helper.GetStringValue("tok");
|
|
string errore = string.Empty;
|
|
admin = helper.GetStringValue("admin");
|
|
// prima verifico che l'utente connesso sia SA
|
|
if (!string.IsNullOrEmpty(admin) && admin.Equals("S"))
|
|
{
|
|
urlBase = apiUrl + "attivazioneStored";
|
|
urlBase = urlBase + "?token=" + token;
|
|
urlBase = urlBase + "&id=" + model.id;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
//string data = response.Content.ReadAsStringAsync().Result;
|
|
//string e = JsonConvert.DeserializeObject<string>(data);
|
|
|
|
return RedirectToAction("Index");
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", "Errore in attivazione");
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
helper.SetStringValue("errMsg", "Utente non abilitato per la funzione");
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DISATTIVA
|
|
|
|
[HttpGet]
|
|
public IActionResult Disattiva(int id)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
|
|
//token = helper.GetStringValue("tok");
|
|
|
|
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;
|
|
|
|
admin = helper.GetStringValue("admin");
|
|
ViewBag.Admin = admin;
|
|
|
|
Registrazione reg = new Registrazione();
|
|
List<Registrazione> modelList = new List<Registrazione>();
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Registrazione>>(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]
|
|
public IActionResult Disattiva(Registrazione model)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
token = helper.GetStringValue("tok");
|
|
string errore = string.Empty;
|
|
admin = helper.GetStringValue("admin");
|
|
// prima verifico che l'utente connesso sia SA
|
|
if (!string.IsNullOrEmpty(admin) && admin.Equals("S"))
|
|
{
|
|
urlBase = apiUrl + "DisattivazioneStored";
|
|
urlBase = urlBase + "?token=" + token;
|
|
urlBase = urlBase + "&id=" + model.id;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
//string data = response.Content.ReadAsStringAsync().Result;
|
|
//string e = JsonConvert.DeserializeObject<string>(data);
|
|
|
|
return RedirectToAction("Index");
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", "Errore in attivazione");
|
|
return RedirectToAction("Error");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
helper.SetStringValue("errMsg", "Utente non abilitato per la funzione");
|
|
return RedirectToAction("Error");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
[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 });
|
|
}
|
|
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;
|
|
}
|
|
|
|
private bool MailSent(string receiver, string subject, string message)
|
|
{
|
|
//REMEMBER per una mail gmail bisogna andare nelle impostazioni
|
|
//e impostare "Accesso app meno sicure" a ON
|
|
bool sent = false;
|
|
|
|
|
|
string senderMail = _configuration["ApplicationInsights:mittenteMail"];
|
|
string senderName = _configuration["ApplicationInsights:nomeMail"];
|
|
string pwdMail = _configuration["ApplicationInsights:pwdMail"];
|
|
|
|
|
|
|
|
//string message = getMailText(nome, tokenMail, receiver);
|
|
|
|
var senderEmail = new MailAddress(senderMail, senderName);
|
|
var receiverEmail = new MailAddress(receiver, "Receiver");
|
|
var password = pwdMail;
|
|
var sub = subject;
|
|
var body = message;
|
|
var smtp = new SmtpClient
|
|
{
|
|
Host = "smtp.gmail.com",
|
|
Port = 587,
|
|
EnableSsl = true,
|
|
|
|
DeliveryMethod = SmtpDeliveryMethod.Network,
|
|
UseDefaultCredentials = false,
|
|
Credentials = new NetworkCredential(senderEmail.Address, password)
|
|
};
|
|
using (var mess = new MailMessage(senderEmail, receiverEmail)
|
|
{
|
|
Subject = subject,
|
|
Body = body,
|
|
IsBodyHtml = true
|
|
})
|
|
{
|
|
smtp.Send(mess);
|
|
}
|
|
return sent;
|
|
}
|
|
|
|
private string getMailText(string nome,string tokenEmail, string emailReg)
|
|
{
|
|
string txt = string.Empty;
|
|
StringBuilder sb=new StringBuilder();
|
|
sb.Append(urlConfirm);
|
|
sb.Append("/Registrazioni/ConfirmEmail");
|
|
sb.Append("?Token=");
|
|
sb.Append(tokenEmail);
|
|
sb.Append("&Email=");
|
|
sb.Append(emailReg);
|
|
|
|
string url = sb.ToString();
|
|
|
|
txt = string.Format("Gentile sig. <b>{0}</b><br> Grazie per essersi registrato. Per completare la registrazione fare click al link: <a href =\"{1}\" title =\"Conferma registrazione\">Conferma</a>", nome, url) ;
|
|
//txt = "<b>titolo contenuto</b><br>contenuto mail di registrazione";
|
|
return txt;
|
|
}
|
|
|
|
private string getMailTextRiepilogo(Registrazione r)
|
|
{
|
|
string txt = string.Empty;
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append(string.Format("Gentile sig. <b>{0}</b><br>", r.cognome));
|
|
sb.Append("Le confermiamo il completamento della procedura di registrazione<br>");
|
|
sb.Append("Di seguito il riepilogo della sua registrazione:<br>");
|
|
sb.Append(string.Format("Nome: <b>{0}</b><br>", !string.IsNullOrEmpty(r.nome)?r.nome:string.Empty));
|
|
sb.Append(string.Format("Cognome: <b>{0}</b><br>", !string.IsNullOrEmpty(r.cognome) ? r.cognome : string.Empty));
|
|
sb.Append(string.Format("Telefono: <b>{0}</b><br>", !string.IsNullOrEmpty(r.telefono) ? r.telefono : string.Empty));
|
|
sb.Append(string.Format("Cellulare: <b>{0}</b><br>", !string.IsNullOrEmpty(r.cellulare) ? r.cellulare : string.Empty));
|
|
sb.Append(string.Format("Email: <b>{0}</b><br>", !string.IsNullOrEmpty(r.email) ? r.email : string.Empty));
|
|
sb.Append(string.Format("Azienda: <b>{0}</b><br>", !string.IsNullOrEmpty(r.azienda) ? r.azienda : string.Empty));
|
|
sb.Append(string.Format("Città: <b>{0}</b><br>", !string.IsNullOrEmpty(r.citta) ? r.citta : string.Empty));
|
|
sb.Append(string.Format("Provincia: <b>{0}</b><br>", !string.IsNullOrEmpty(r.provincia) ? r.provincia : string.Empty));
|
|
sb.Append(string.Format("Nazione: <b>{0}</b><br>", !string.IsNullOrEmpty(r.nazione) ? r.nazione : string.Empty));
|
|
sb.Append(string.Format("Username: <b>{0}</b><br>", !string.IsNullOrEmpty(r.username) ? r.username : string.Empty));
|
|
sb.Append(string.Format("Password: <b>{0}</b><br>", !string.IsNullOrEmpty(r.passwd) ? r.passwd : string.Empty));
|
|
|
|
txt = sb.ToString();
|
|
return txt;
|
|
}
|
|
|
|
public Controllo isLoginPresente(string user, string pwd, SessionHelper helper)
|
|
{
|
|
Controllo c = new Controllo();
|
|
c.isPresente = false;
|
|
|
|
urlBase = apiUrl + "tecniciListAll";
|
|
urlBase = urlBase + "?usr=" + user;
|
|
urlBase = urlBase + "&pwd=" + pwd;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
List<Tecnici> modelList = new List<Tecnici>();
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
modelList = JsonConvert.DeserializeObject<List<Tecnici>>(data);
|
|
if (modelList != null && modelList.Count > 0)
|
|
c.isPresente = true;
|
|
}
|
|
else
|
|
{
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
helper.SetStringValue("errMsg", errMes);
|
|
c.errMsg = errMes;
|
|
}
|
|
return c;
|
|
}
|
|
|
|
private static Random random = new Random();
|
|
|
|
public static string RandomString(int length)
|
|
{
|
|
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
return new string(Enumerable.Repeat(chars, length)
|
|
.Select(s => s[random.Next(s.Length)]).ToArray());
|
|
}
|
|
|
|
public bool UpdRegistrazione(Registrazione model)
|
|
{
|
|
bool upd=false;
|
|
model.attivato = "S";
|
|
urlBase = apiUrl + "registrazioni/mod";
|
|
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)
|
|
{
|
|
upd = true;
|
|
}
|
|
return upd;
|
|
}
|
|
|
|
#region attiva utente
|
|
private Configurazione_out readConfTemplate()
|
|
{
|
|
Configurazione_out co=new Configurazione_out();
|
|
SessionHelper helper = new SessionHelper(this);
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
token = helper.GetStringValue("tok");
|
|
string errore = string.Empty;
|
|
|
|
urlBase = apiUrl + "configurazioni";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
client = new HttpClient();
|
|
client.BaseAddress = baseAddress;
|
|
|
|
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string data = response.Content.ReadAsStringAsync().Result;
|
|
co = JsonConvert.DeserializeObject<Configurazione_out>(data);
|
|
}
|
|
else
|
|
{
|
|
errore = "Errore in inserimento configurazioni. ";
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
errore = errore + errMes;
|
|
co.err_detail = errore;
|
|
}
|
|
return co;
|
|
}
|
|
private string insertConfigurazione(Configurazione_out co, Registrazione model)
|
|
{
|
|
string errore =string.Empty;
|
|
|
|
Configurazioni c = fillConf(co, model);
|
|
urlBase = apiUrl + "configurazioni/add";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Uri baseAddress = new Uri(urlBase);
|
|
string data = JsonConvert.SerializeObject(c);
|
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
errore = "Errore in inserimento configurazioni. ";
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
errore = errore + errMes;
|
|
}
|
|
|
|
return errore;
|
|
}
|
|
private string insertTecnico(Registrazione model)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
token = helper.GetStringValue("tok");
|
|
string errore =string.Empty;
|
|
|
|
urlBase = apiUrl + "tecnici/add";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Tecnici tec = fillTecnico(model);
|
|
Uri baseAddress = new Uri(urlBase);
|
|
|
|
string data = JsonConvert.SerializeObject(tec);
|
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
errore = "Errore in inserimento tecnico. ";
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
errore = errore + errMes;
|
|
}
|
|
return errore;
|
|
}
|
|
private Configurazioni fillConf(Configurazione_out c, Registrazione r)
|
|
{
|
|
string _path = "E:\\AAAFTPAPP\\";
|
|
string _ftp = "ftp://10.0.0.10/";
|
|
|
|
Configurazioni _out = new Configurazioni();
|
|
_out.azienda = r.azienda;
|
|
_out.path_buoni = _path + r.azienda;
|
|
_out.prefisso_buoni_chia = c.prefisso_buoni_chia;
|
|
_out.prefisso_buoni_man = c.prefisso_buoni_man;
|
|
_out.ftp_url = _ftp + r.azienda;
|
|
_out.ftp_usr = c.ftp_usr;
|
|
_out.ftp_pwd = c.ftp_pwd;
|
|
_out.ftp_port = c.ftp_port;
|
|
|
|
_out.abilita_naviga = c.abilita_naviga;
|
|
_out.abilita_telefona = c.abilita_telefona;
|
|
_out.abilita_chiamate = c.abilita_chiamate;
|
|
_out.abilita_manutenzioni = c.abilita_manutenzioni;
|
|
_out.abilita_barcode = c.abilita_barcode;
|
|
_out.abilita_inserimento_chiamate = c.abilita_inserimento_chiamate;
|
|
|
|
_out.chiamate_accetta = c.chiamate_accetta;
|
|
_out.chiamate_accetta_barcode = c.chiamate_accetta_barcode;
|
|
_out.chiamate_accetta_offline = c.chiamate_accetta_offline;
|
|
|
|
_out.chiamate_rifiuta = c.chiamate_rifiuta;
|
|
_out.chiamate_rifiuta_barcode = c.chiamate_rifiuta_barcode;
|
|
_out.chiamate_rifiuta_offline = c.chiamate_rifiuta_offline;
|
|
_out.chiamate_chiudi_barcode = c.chiamate_chiudi_barcode;
|
|
_out.chiamate_firma_barcode = c.chiamate_firma_barcode;
|
|
_out.chiamate_chiudi_salva_barcode = c.chiamate_chiudi_salva_barcode;
|
|
_out.chiamate_chiudi_salva_offline = c.chiamate_chiudi_salva_offline;
|
|
|
|
_out.manutenzioni_accetta = c.manutenzioni_accetta;
|
|
_out.manutenzioni_accetta_barcode = c.manutenzioni_accetta_barcode;
|
|
_out.manutenzioni_accetta_offline = c.manutenzioni_accetta_offline;
|
|
_out.manutenzioni_rifiuta = c.manutenzioni_rifiuta_barcode;
|
|
_out.manutenzioni_rifiuta_barcode = c.manutenzioni_rifiuta;
|
|
_out.manutenzioni_chiudi_barcode = c.manutenzioni_chiudi_barcode;
|
|
_out.manutenzioni_firma_barcode = c.manutenzioni_firma_barcode;
|
|
_out.manutenzioni_chiudi_salva_barcode = c.manutenzioni_chiudi_salva_barcode;
|
|
_out.manutenzioni_chiudi_salva_offline = c.manutenzioni_chiudi_salva_offline;
|
|
|
|
_out.dpi_checkbox = c.dpi_checkbox;
|
|
_out.anagrafica = c.anagrafica;
|
|
_out.stato_finale = c.stato_finale;
|
|
_out.descrizione_intervento = c.descrizione_intervento;
|
|
_out.composizione_impianto = c.composizione_impianto;
|
|
_out.note_intervento = c.note_intervento;
|
|
_out.esito_intervento = c.esito_intervento;
|
|
_out.ora_inizio_fine = c.ora_inizio_fine;
|
|
|
|
_out.materiali = c.materiali;
|
|
_out.diritto_chiamata = c.diritto_chiamata;
|
|
_out.manodopera = c.manodopera;
|
|
_out.spese_viaggio = c.spese_viaggio;
|
|
_out.tipo_pagamento = c.tipo_pagamento;
|
|
_out.note_pagamento = c.note_pagamento;
|
|
_out.causale = c.causale;
|
|
|
|
_out.time_sheet = c.time_sheet;
|
|
_out.time_sheet_offline = c.time_sheet_offline;
|
|
_out.costo_orario = c.costo_orario;
|
|
|
|
_out.storico = c.storico;
|
|
_out.storico_tecnico = c.storico_tecnico;
|
|
_out.storico_interventi = c.storico_interventi;
|
|
_out.storico_impianto = c.storico_impianto;
|
|
_out.ricerca_impianti = c.ricerca_impianti;
|
|
_out.ora_inizio_fine_automatica = c.ora_inizio_fine_automatica;
|
|
_out.stampa_orario = c.stampa_orario;
|
|
_out.intestazione_stampa = !string.IsNullOrEmpty(r.RagioneSociale) ? r.RagioneSociale : r.azienda;
|
|
_out.seriale_template_chi = "0000000001";
|
|
_out.abilita_inserimento_chiamate = c.abilita_inserimento_chiamate;
|
|
_out.abilita_data_rapp_edit = c.abilita_data_rapp_edit;
|
|
_out.numeri_decimali = c.numeri_decimali;
|
|
_out.max_record = c.max_record;
|
|
_out.prezzi_visibili = c.prezzi_visibili;
|
|
_out.desc_supp_prodotti_visibile = c.desc_supp_prodotti_visibile;
|
|
|
|
return _out;
|
|
}
|
|
private Tecnici fillTecnico(Registrazione r)
|
|
{
|
|
Tecnici _out = new Tecnici();
|
|
_out.tccodice = "TECNICO01";
|
|
string nome = !string.IsNullOrEmpty(r.nome) ? r.nome.Trim() : string.Empty;
|
|
string cognome = !string.IsNullOrEmpty(r.cognome) ? r.cognome.Trim() : string.Empty;
|
|
|
|
nome = nome+" "+ cognome;
|
|
if(nome.Length>=39)
|
|
{
|
|
nome= nome.Substring(0, 39);
|
|
}
|
|
_out.tcdescri = nome;
|
|
_out.tcpwd = r.passwd;
|
|
_out.tcuser = r.username;
|
|
_out.tccodazi = r.azienda;
|
|
_out.tctelef1 = r.telefono;
|
|
//manca indirizzo
|
|
//manca provincia
|
|
//manca nazione
|
|
//manca cellulare
|
|
//manca email
|
|
//manca tcdoute=1
|
|
_out.tccoor = Convert.ToDecimal("40");
|
|
return _out;
|
|
}
|
|
private string insertCodChiusura(Registrazione model)
|
|
{
|
|
SessionHelper helper = new SessionHelper(this);
|
|
apiUrl = helper.GetStringValue("apiUrl");
|
|
token = helper.GetStringValue("tok");
|
|
string errore = string.Empty;
|
|
|
|
urlBase = apiUrl + "chiusure/add";
|
|
urlBase = urlBase + "?token=" + token;
|
|
Chiusure chiu = new Chiusure();
|
|
chiu.cccodazi = model.azienda;
|
|
chiu.cccodice = "0001";
|
|
chiu.ccdescr = "Attività eseguita con successo";
|
|
chiu.ccdessup = "Attività eseguita con successo";
|
|
Uri baseAddress = new Uri(urlBase);
|
|
|
|
string data = JsonConvert.SerializeObject(chiu);
|
|
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
|
|
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
errore = "Errore in inserimento codice chiusura. ";
|
|
errMes = response.Content.ReadAsStringAsync().Result;
|
|
errore = errore + errMes;
|
|
}
|
|
return errore;
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|