60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using ShipyardContracts.BindingModels;
|
|
using ShipyardContracts.ViewModels;
|
|
using ShipyardDataModels.Models;
|
|
using System.Xml.Linq;
|
|
|
|
namespace ShipyardFileImplement.Models
|
|
{
|
|
public class Detail : IDetailModel
|
|
{
|
|
public int Id { get; private set; }
|
|
public string DetailName { get; private set; } = string.Empty;
|
|
public double Cost { get; set; }
|
|
public static Detail? Create(DetailBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Detail()
|
|
{
|
|
Id = model.Id,
|
|
DetailName = model.DetailName,
|
|
Cost = model.Cost
|
|
};
|
|
}
|
|
public static Detail? Create(XElement element)
|
|
{
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Detail()
|
|
{
|
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
|
DetailName = element.Element("DetailName")!.Value,
|
|
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
|
};
|
|
}
|
|
public void Update(DetailBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
DetailName = model.DetailName;
|
|
Cost = model.Cost;
|
|
}
|
|
public DetailViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
DetailName = DetailName,
|
|
Cost = Cost
|
|
};
|
|
public XElement GetXElement => new("Detail",
|
|
new XAttribute("Id", Id),
|
|
new XElement("DetailName", DetailName),
|
|
new XElement("Cost", Cost.ToString()));
|
|
}
|
|
|
|
} |