using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
//
// This is here so CodeMaid doesn't reorganize this document
//
namespace WebDoorCreator.Data.DbModels
{
///
/// Tabella dati operation CONCRETE collegate alla porta
///
[Table("DoorOp")]
public class DoorOpModel
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int DoorOpId { get; set; }
///
/// porta di riferimento
///
public int DoorId { get; set; } = 0;
///
/// Tipo astratto di riferimento
///
public string ObjectId { get; set; } = "";
///
/// Descrizione
///
public string Description { get; set; } = "";
///
/// Data inserimento ordine
///
public DateTime DateIns { get; set; } = DateTime.Now;
///
/// Codice utente che ha creato
///
public string UserIdIns { get; set; } = "";
///
/// Data (ultima) modifica ordine
///
public DateTime DateMod { get; set; } = DateTime.Now;
///
/// Codice utente che ha creato
///
public string UserIdMod { get; set; } = "";
///
/// Oggetto Json per specifica configurazione ammessa
///
public string JsoncConfigVal { get; set; } = "";
///
/// Oggetto Json per salvare i VALORI selezionati
///
public string JsoncActVal { get; set; } = "";
///
/// Id dell'utente che ha preso conferma del template
///
public string userConfirm { get; set; } = "";
///
/// Data e ora in cui è stata presa conferma del template
///
public DateTime? DtConfirm { get; set; }
[ForeignKey("DoorId")]
public virtual DoorModel? DoorNav { get; set; }
//[ForeignKey("DoorOpTypId")]
//public virtual DoorOpTypeModel? DoorOpTypeNav { get; set; }
[NotMapped]
public Dictionary CurrVals
{
get
{
Dictionary answ = new Dictionary();
if (!string.IsNullOrEmpty(JsoncActVal))
{
try
{
var deserialized = JsonConvert.DeserializeObject>(JsoncActVal);
answ = deserialized ?? new Dictionary();
}
catch
{ }
}
return answ;
}
set
{
JsoncActVal = JsonConvert.SerializeObject(value);
}
}
[NotMapped]
public Dictionary> GraphicParams
{
get
{
Dictionary> answ = new Dictionary>();
if (!string.IsNullOrEmpty(JsoncConfigVal))
{
try
{
var deserialized = JsonConvert.DeserializeObject>>(JsoncConfigVal);
answ = deserialized ?? new Dictionary>();
}
catch
{ }
}
return answ;
}
set
{
JsoncConfigVal = JsonConvert.SerializeObject(value);
}
}
///
/// Comparazione tra il dizionario currVal corrente e quello ricevuto
///
/// Dizionario x comparazione
///
public bool JsonActValEquals(Dictionary newDict)
{
string JsonNewVal = JsonConvert.SerializeObject(newDict);
bool answ = JsoncActVal.Equals(JsonNewVal);
return answ;
}
///
/// Comparazione tra il dizionario configurazioni corrente e quello ricevuto
///
/// Dizionario x comparazione
///
public bool JsoncConfigValEquals(Dictionary> newDict)
{
string JsonNewVal = JsonConvert.SerializeObject(newDict);
bool answ = JsoncConfigVal.Equals(JsonNewVal);
return answ;
}
///
/// Clone oggetto
///
///
///
///
public DoorOpModel ObjClone(string userName, int doorId)
{
DoorOpModel answ = new DoorOpModel();
DateTime adesso = DateTime.Now;
if (doorId == 0)
{
answ = new DoorOpModel()
{
DateIns = adesso,
DateMod = adesso,
UserIdIns = userName,
UserIdMod = userName,
ObjectId = ObjectId,
DoorId = DoorId,
JsoncConfigVal = JsoncConfigVal,
JsoncActVal = JsoncActVal,
userConfirm = userConfirm,
DtConfirm = DtConfirm
};
}
else
{
answ = new DoorOpModel()
{
DateIns = adesso,
DateMod = adesso,
UserIdIns = userName,
UserIdMod = userName,
ObjectId = ObjectId,
DoorId = doorId,
JsoncConfigVal = JsoncConfigVal,
JsoncActVal = JsoncActVal,
userConfirm = userConfirm,
DtConfirm = DtConfirm
};
}
return answ;
}
}
}