using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Core.Enum;
namespace Core
{
public class SupportRequest
{
#region Public Properties
public string CodApp { get; set; } = "";
public string CodImp { get; set; } = "";
public string CodInst { get; set; } = "";
public string ContactEmail { get; set; } = "";
public string ContactName { get; set; } = "";
public string ContactPhone { get; set; } = "";
public int idxSubLic { get; set; } = 0;
public TipologiaTicket Tipo { get; set; } = TipologiaTicket.ND;
public bool IsValid
{
get => !string.IsNullOrEmpty(MasterKey) && !string.IsNullOrEmpty(ContactEmail) && !string.IsNullOrEmpty(CodInst) && !string.IsNullOrEmpty(CodApp);
}
public string MasterKey { get; set; } = "";
public string ReqBody { get; set; } = "";
///
/// Init classe in modalità "empty"
///
public SupportRequest()
{ }
///
/// Istanzia un nuovo ogetto richiesta supporto
///
/// Codice Applicazione (es EBW-UP)
/// Codice Impegno (es codice chiave HW)
/// Codice Cliente/Installazione
/// Email x contatto
/// Nome del richiedente/clietne
/// Tel richiedente/cliente
/// Chiave master di comunicazione da LiMan
/// Testo delal richiesta
/// Idx univoco di sublic (es x gestione utenti)
/// Tipo ticket da gestire (default fileUpload)
public SupportRequest(string codApp, string codImp, string codInst, string contactEmail, string contactName, string contactPhone, string masterKey, string ReqBody, int idxSubLic = 0, TipologiaTicket tipo = TipologiaTicket.FileUpload)
{
this.CodApp = CodApp;
this.CodImp = CodImp;
this.CodInst = CodInst;
this.ContactEmail = contactEmail;
this.ContactName = contactName;
this.ContactPhone = contactPhone;
this.MasterKey = masterKey;
this.ReqBody = ReqBody;
this.idxSubLic = idxSubLic;
this.Tipo = tipo;
}
///
/// Effettua salvataggio su file di un oggetto richiesta file upload
///
/// Oggetto richiesta (già istanziato)
/// Path dove salvare il file
public static bool SaveRequest(SupportRequest currReq, string filePath)
{
bool fatto = false;
try
{
string rawData = JsonConvert.SerializeObject(currReq, Formatting.Indented);
File.WriteAllText(filePath, rawData);
fatto = true;
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
return fatto;
}
#endregion Public Properties
}
}