PIbd-23_Starostin_I.K._Ship.../ShipyardListImplement/Ship.cs

50 lines
1.4 KiB
C#

using ShipyardContracts.ViewModels;
using ShipyardDataModels.Models;
using ShipyardContracts.BindingModels;
namespace ShipyardListImplement.Models
{
public class Ship : IShipModel
{
public int Id { get; private set; }
public string ShipName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> ShipComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Ship? Create(ShipBindingModel? model)
{
if (model == null)
{
return null;
}
return new Ship()
{
Id = model.Id,
ShipName = model.ShipName,
Price = model.Price,
ShipComponents = model.ShipComponents
};
}
public void Update(ShipBindingModel? model)
{
if (model == null)
{
return;
}
ShipName = model.ShipName;
Price = model.Price;
ShipComponents = model.ShipComponents;
}
public ShipViewModel GetViewModel => new()
{
Id = Id,
ShipName = ShipName,
Price = Price,
ShipComponents = ShipComponents
};
}
}