79 lines
2.1 KiB
C#
79 lines
2.1 KiB
C#
using FurnitureAssemblyContracts.BindingModels;
|
|
using FurnitureAssemblyContracts.ViewModels;
|
|
using FurnitureAssemblyDataModels.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 FurnitureAssemblyFileImplement.Models
|
|
{
|
|
[DataContract]
|
|
public class Workpiece : IWorkpieceModel
|
|
{
|
|
[DataMember]
|
|
public int Id { get; private set; }
|
|
[DataMember]
|
|
public string WorkpieceName { get; private set; } = string.Empty;
|
|
[DataMember]
|
|
public double Cost { get; set; }
|
|
|
|
public static Workpiece? Create(WorkpieceBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new Workpiece()
|
|
{
|
|
Id = model.Id,
|
|
WorkpieceName = model.WorkpieceName,
|
|
Cost = model.Cost
|
|
};
|
|
}
|
|
|
|
public static Workpiece? Create(XElement element)
|
|
{
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new Workpiece()
|
|
{
|
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
|
WorkpieceName = element.Element("WorkpieceName")!.Value,
|
|
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
|
};
|
|
}
|
|
|
|
public void Update(WorkpieceBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
WorkpieceName = model.WorkpieceName;
|
|
Cost = model.Cost;
|
|
}
|
|
|
|
public WorkpieceViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
WorkpieceName = WorkpieceName,
|
|
Cost = Cost
|
|
};
|
|
|
|
public XElement GetXElement => new("Workpiece",
|
|
new XAttribute("Id", Id),
|
|
new XElement("WorkpieceName", WorkpieceName),
|
|
new XElement("Cost", Cost.ToString()));
|
|
}
|
|
}
|