69 lines
1.4 KiB
C#
Raw Normal View History

2023-05-19 21:46:44 +04:00
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System.Reflection;
using System.Xml.Linq;
namespace FileImplements.Models
{
public class Cert : ICertModel
{
public int Id { get; private set; }
public string Name { get; private set; } = string.Empty;
public string Path { get; private set; } = string.Empty;
public int Key_Id { get; private set; }
public static Cert? Create(CertBindingModel model)
{
if (model == null)
{
return null;
}
return new Cert()
{
Id = model.Id,
Name = model.Name,
Path = model.Path,
Key_Id = model.Key_Id,
};
}
public static Cert? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Cert()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
Name = element.Element("Name")!.Value,
Path = element.Element("Path")!.Value,
Key_Id = Convert.ToInt32(element.Attribute("Key_Id")!.Value)
};
}
public void Update(CertBindingModel? model)
{
if (model == null)
{
return;
}
Id = model.Id;
Name = model.Name;
Path = model.Path;
Key_Id = model.Key_Id;
}
public CertViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Path = Path,
Key_Id = Key_Id
};
public XElement GetXElement => new("Implementer",
new XAttribute("Id", Id),
new XElement("Name", Name),
new XElement("Path", Path),
new XElement("Key_Id", Key_Id));
}
}