PIbd-21_RazubaevSM_Plumbing.../PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs

49 lines
1.2 KiB
C#
Raw Normal View History

2024-03-23 11:06:35 +04:00
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
2024-05-16 17:00:28 +04:00
using System.Runtime.Serialization;
2024-03-23 11:06:35 +04:00
namespace PlumbingRepairListImplement.Models
{
2024-05-16 17:00:28 +04:00
[DataContract]
2024-03-23 11:06:35 +04:00
internal class Component : IComponentModel
{
2024-05-16 17:00:28 +04:00
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ComponentName { get; private set; } = string.Empty;
[DataMember]
public double Cost { get; set; }
2024-03-23 11:06:35 +04:00
public static Component? Create(ComponentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public void Update(ComponentBindingModel? model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
}
}