52 lines
1.4 KiB
C#

using MotorPlantContracts.BindingModels;
using MotorPlantContracts.VeiwModels;
using MotorPlantDataModels.Models;
namespace MotorPlantListImplement.Models
{
public class Motor: IMotorModel
{
public int Id { get; private set; }
public string MotorName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> MotorComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)> { };
public static Motor? Create(MotorBindingModel? model)
{
if(model == null)
{
return null;
}
return new Motor()
{
Id = model.Id,
MotorName = model.MotorName,
Price = model.Price,
MotorComponents = model.MotorComponents
};
}
public void Update(MotorBindingModel? model)
{
if (model == null)
{
return;
}
MotorName = model.MotorName;
Price = model.Price;
MotorComponents = model.MotorComponents;
}
public MotorViewModel GetViewModel => new()
{
Id = Id,
MotorName = MotorName,
Price = Price,
MotorComponents = MotorComponents
};
}
}