PIbd21_Makarov_DV_FlowerShop/FlowerShop/FlowerShopFileImplement/Models/Implementer.cs

71 lines
2.0 KiB
C#

using FlowerShopContracts.BindingModels;
using FlowerShopContracts.ViewModels;
using FlowerShopDataModels.Models;
using System.Xml.Linq;
namespace FlowerShopFileImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel Model)
{
if (Model == null)
return null;
return new()
{
Id = Model.Id,
ImplementerFIO = Model.ImplementerFIO,
Password = Model.Password,
WorkExperience = Model.WorkExperience,
Qualification = Model.Qualification,
};
}
public static Implementer? Create(XElement Element)
{
if (Element == null)
return null;
return new()
{
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
ImplementerFIO = Element.Element("ImplementerFIO")!.Value,
Password = Element.Element("Password")!.Value,
WorkExperience = Convert.ToInt32(Element.Element("WorkExperience")!.Value),
Qualification = Convert.ToInt32(Element.Element("Qualification")!.Value),
};
}
public void Update(ImplementerBindingModel Model)
{
if (Model == null)
return;
ImplementerFIO = Model.ImplementerFIO;
Password = Model.Password;
WorkExperience = Model.WorkExperience;
Qualification = Model.Qualification;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
ImplementerFIO = ImplementerFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification,
};
public XElement GetXElement => new(
"Implementer",
new XAttribute("Id", Id),
new XElement("ImplementerFIO", ImplementerFIO),
new XElement("Password", Password),
new XElement("WorkExperience", WorkExperience),
new XElement("Qualification", Qualification)
);
}
}