PIbd-23_Leonteva_V._A._LawFirm/LawFirm/LawFirmFileImplement/Models/Blank.cs

59 lines
1.7 KiB
C#
Raw Normal View History

2024-04-22 22:48:19 +04:00
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System.Xml.Linq;
namespace LawFirmFileImplement.Models
{
public class Blank : IBlankModel
{
public int Id { get; private set; }
public string BlankName { get; private set; } = string.Empty;
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()));
}
}