110 lines
3.2 KiB
C#
110 lines
3.2 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
// <Auto-Generated>
|
|
// This is here so CodeMaid doesn't reorganize this document
|
|
// </Auto-Generated>
|
|
namespace LiMan.DB.DBModels
|
|
{
|
|
[Table("EnrollRequest")]
|
|
public partial class EnrollRequestModel
|
|
{
|
|
/// <summary>
|
|
/// ID univoco
|
|
/// </summary>
|
|
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
public int IdReq { get; set; }
|
|
|
|
/// <summary>
|
|
/// Passcode usato per autorizzare (un valore random NON DUPLICATO con quelli attivi al momento della richiesta)
|
|
/// </summary>
|
|
public int Passcode { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// Payload richiesta, ovvero la serializzazione json di un Dict[string,string] delle info ricevute
|
|
/// </summary>
|
|
public string ReqPayload { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// DataOra richiesta enroll
|
|
/// </summary>
|
|
public DateTime DtReq { get; set; } = DateTime.Now;
|
|
|
|
/// <summary>
|
|
/// DataOra approvazione
|
|
/// </summary>
|
|
public DateTime? DtAppr { get; set; } = null;
|
|
|
|
/// <summary>
|
|
/// Username approvatore
|
|
/// </summary>
|
|
public string UserAppr { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Licenza fornita in risposta alla richiesta
|
|
/// </summary>
|
|
public int IdxLic { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// Indica Scaduta se non approvata e richiesta da oltre 15 minuti
|
|
/// </summary>
|
|
[NotMapped]
|
|
public bool IsScaduta
|
|
{
|
|
get => DtAppr == null && DateTime.Now.Subtract(DtReq).TotalMinutes > minScad;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// DataOra Scadenza richiesta (periodo indicato - 10 sec)
|
|
/// </summary>
|
|
[NotMapped]
|
|
public DateTime DtScadenza
|
|
{
|
|
get => DtReq.AddSeconds(minScad * 60 - 10);
|
|
}
|
|
|
|
[NotMapped]
|
|
public Dictionary<string, string> DictAttrib
|
|
{
|
|
get
|
|
{
|
|
Dictionary<string, string> answ = new Dictionary<string, string>();
|
|
if (!string.IsNullOrEmpty(ReqPayload))
|
|
{
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<Dictionary<string, string>>(ReqPayload);
|
|
}
|
|
catch { }
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
public int DictNumKVP()
|
|
{
|
|
return DictAttrib.Count;
|
|
}
|
|
public Dictionary<string, string> DictAttribShort(int numMax)
|
|
{
|
|
Dictionary<string, string> answ = DictAttrib;
|
|
if (answ.Count > numMax)
|
|
{
|
|
answ = answ.Take(numMax).ToDictionary(x => x.Key, x => x.Value);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Scadenza massima (in minuti) per la richiesta
|
|
/// </summary>
|
|
private const int minScad = 15;
|
|
}
|
|
}
|