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

78 lines
2.0 KiB
C#
Raw Normal View History

2023-02-11 15:30:32 +04:00
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;
2023-02-11 15:30:32 +04:00
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace LawFirmFileImplement.Models
{
[DataContract]
2023-02-11 15:30:32 +04:00
public class Blank : IBlankModel
{
[DataMember]
2023-02-11 15:30:32 +04:00
public string BlankName { get; private set; } = String.Empty;
[DataMember]
2023-02-11 15:30:32 +04:00
public double Cost { get; set; }
[DataMember]
2023-02-11 15:30:32 +04:00
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())
);
}
}