76 lines
2.0 KiB
C#
76 lines
2.0 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.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Xml.Linq;
|
|||
|
|
|||
|
namespace FurnitureAssemblyFileImplement.Models
|
|||
|
{
|
|||
|
public class Workpiece : IWorkpieceModel
|
|||
|
{
|
|||
|
public int Id { get; private set; }
|
|||
|
|
|||
|
public string WorkpieceName { get; private set; } = string.Empty;
|
|||
|
|
|||
|
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()));
|
|||
|
}
|
|||
|
}
|