PIbd-23_Leonteva_V._A._LawFirm/LawFirm/LawFirmFileImplement/Models/Blank.cs
2024-06-19 23:52:53 +04:00

64 lines
1.8 KiB
C#

using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System.Xml.Linq;
using System.Runtime.Serialization;
namespace LawFirmFileImplement.Models
{
[DataContract]
public class Blank : IBlankModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string BlankName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; set; }
public static Blank? Create(BlankBindingModel model)
{
if (model == null)
{
return null;
}
return new Blank()
{
Id = model.Id,
BlankName = model.BlankName,
Price = model.Price
};
}
public static Blank? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Blank()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
BlankName = element.Element("BlankName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value)
};
}
public void Update(BlankBindingModel model)
{
if (model == null)
{
return;
}
BlankName = model.BlankName;
Price = model.Price;
}
public BlankViewModel GetViewModel => new()
{
Id = Id,
BlankName = BlankName,
Price = Price
};
public XElement GetXElement => new("Blank",
new XAttribute("Id", Id),
new XElement("BlankName", BlankName),
new XElement("Price", Price.ToString()));
}
}