2024-02-25 20:02:29 +04:00

46 lines
1.3 KiB
C#

using ShipyardContracts.BindingModels;
using ShipyardContracts.ViewModels;
using ShipyardDataModels.Models;
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, (IDetailModel, int)> ShipDetails { get; private set; } = new Dictionary<int, (IDetailModel, int)>();
public static Ship? Create(ShipBindingModel? model)
{
if (model == null)
{
return null;
}
return new Ship()
{
Id = model.Id,
ShipName = model.ShipName,
Price = model.Price,
ShipDetails = model.ShipDetails
};
}
public void Update(ShipBindingModel? model)
{
if (model == null)
{
return;
}
ShipName = model.ShipName;
Price = model.Price;
ShipDetails = model.ShipDetails;
}
public ShipViewModel GetViewModel => new()
{
Id = Id,
ShipName = ShipName,
Price = Price,
ShipDetails = ShipDetails
};
}
}