PIbd-23_Mochalov_D.V._LawFirm/LawFirm/LawFirmFileImplement/Models/Blank.cs

78 lines
2.0 KiB
C#

using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace LawFirmFileImplement.Models
{
[DataContract]
public class Blank : IBlankModel
{
[DataMember]
public string BlankName { get; private set; } = String.Empty;
[DataMember]
public double Cost { get; set; }
[DataMember]
public int Id { get; private set; }
public static Blank? Create(BlankBindingModel? model)
{
if (model == null)
{
return null;
}
return new Blank()
{
Id = model.Id,
BlankName = model.BlankName,
Cost = model.Cost
};
}
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,
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
};
}
public void Update(BlankBindingModel? model)
{
if (model == null)
{
return;
}
BlankName = model.BlankName;
Cost = model.Cost;
}
public BlankViewModel GetViewModel => new()
{
Id = Id,
BlankName = BlankName,
Cost = Cost
};
public XElement GetXElement => new(
"Blank",
new XAttribute("Id", Id),
new XElement("BlankName", BlankName),
new XElement("Cost", Cost.ToString())
);
}
}