using System; using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; namespace Unisoft.PayrollDAL.Employee { public class EmployeeAddon { private Dictionary _attributes; private string _feAddon; private int employeeAddonId; private int? employeeId; private string perMobNum; private long? entryLong; private DateTime? entryDateTime; private double? entryDouble; private short? entryInt16; private byte? entryByte; private int? formulaInt; private string lovString; private string standardList; private string fileSelection; private string bonusApplicable; [JsonPropertyName("EMPLOYEEID")] public int? AddonEmployeeId { get { return employeeId; } set { employeeId = value; } } [JsonPropertyName("PERMOBNUM")] public string EmployeeAddonPerMobNum { get { return perMobNum; } set { perMobNum = value; } } [JsonPropertyName("ENTRYLONG")] public long? EmployeeAddonEntryLong { get { return entryLong; } set { entryLong = value; } } [JsonPropertyName("ENTRYDATETIME")] public DateTime? EmployeeAddonEntryDateTime { get { return entryDateTime; } set { entryDateTime = value; } } [JsonPropertyName("ENTRYDOUBLE")] public double? EmployeeAddonEntryDouble { get { return entryDouble; } set { entryDouble = value; } } [JsonPropertyName("ENTRYINT16")] public short? EmployeeAddonEntryInt16 { get { return entryInt16; } set { entryInt16 = value; } } [JsonPropertyName("ENTRYBYTE")] public byte? EmployeeAddonEntryByte { get { return entryByte; } set { entryByte = value; } } [JsonPropertyName("FORMULAINT")] public int? EmployeeAddonFormulaInt { get { return formulaInt; } set { formulaInt = value; } } [JsonPropertyName("LOVSTRING")] public string EmployeeAddonLovString { get { return lovString; } set { lovString = value; } } [JsonPropertyName("STANDARDLIST")] public string EmployeeAddonStandardList { get { return standardList; } set { standardList = value; } } [JsonPropertyName("FILESELECTION")] public string EmployeeAddonFileSelection { get { return fileSelection; } set { fileSelection = value; } } [JsonPropertyName("BONUSAPPLICABLE")] public string EmployeeAddonBonusApplicable { get { return bonusApplicable; } set { bonusApplicable = value; } } [JsonPropertyName("FeAddon")] public string FeAddon { get => _feAddon; set { _feAddon = value; if (!string.IsNullOrEmpty(value)) { try { _attributes = JsonSerializer.Deserialize>(value); } catch { _attributes = new Dictionary(); } } else { _attributes = new Dictionary(); } } } [JsonPropertyName("GetAddon")] public string GetAddon { get; set; } [JsonPropertyName("Attributes")] public Dictionary Attributes { get { if (_attributes == null) { _attributes = new Dictionary(); } try { GetAddon = JsonSerializer.Serialize(_attributes); } catch { GetAddon = "{}"; } return _attributes; } set { _attributes = value ?? new Dictionary(); } } public EmployeeAddon() { _attributes = new Dictionary(); _feAddon = string.Empty; GetAddon = "{}"; } public T GetAttributeValue(string key, T defaultValue = default) { if (_attributes != null && _attributes.ContainsKey(key)) { try { if (_attributes[key] is JsonElement jsonElement) { return JsonSerializer.Deserialize(jsonElement.GetRawText()); } return (T)Convert.ChangeType(_attributes[key], typeof(T)); } catch { return defaultValue; } } return defaultValue; } public void SetAttributeValue(string key, object value) { if (_attributes == null) { _attributes = new Dictionary(); } _attributes[key] = value; } public bool HasAttribute(string key) { return _attributes != null && _attributes.ContainsKey(key); } public void RemoveAttribute(string key) { if (_attributes != null && _attributes.ContainsKey(key)) { _attributes.Remove(key); } } public void ClearAttributes() { if (_attributes != null) { _attributes.Clear(); } GetAddon = "{}"; } } }