67 lines
1.3 KiB
C#

using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace FileImplements.Models
{
public class Key : IKeyModel
{
public int Id { get; private set; }
public string Name { get; private set; } = string.Empty;
public string Path { get; private set; } = string.Empty;
public static Key? Create(KeyBindingModel model)
{
if (model == null)
{
return null;
}
return new Key()
{
Id = model.Id,
Name = model.Name,
Path = model.Path
};
}
public static Key? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Key()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
Name = element.Element("Name")!.Value,
Path = element.Element("Name")!.Value
};
}
public void Update(KeyBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Path = model.Path;
}
public KeyViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Path = Path
};
public XElement GetXElement => new("Food",
new XAttribute("Id", Id),
new XElement("Name", Name),
new XElement("Path", Path));
}
}