PIbd-21_KozyrevSS_SewingDre.../SewingDresses/SewingDressesListImplement/Models/Dress.cs

53 lines
1.4 KiB
C#

using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
namespace SewingDressesListImplement.Models
{
public class Dress : IDressModel
{
public int Id { get; private set; }
public string DressName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> DressComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
public static Dress? Create(DressBindingModel? model)
{
if (model == null)
{
return null;
}
return new Dress()
{
Id = model.Id,
DressName = model.DressName,
Price = model.Price,
DressComponents = model.DressComponents
};
}
public void Update(DressBindingModel? model)
{
if (model == null)
{
return;
}
DressName = model.DressName;
Price = model.Price;
DressComponents = model.DressComponents;
}
public DressViewModel GetViewModel => new()
{
Id = Id,
DressName = DressName,
Price = Price,
DressComponents = DressComponents
};
}
}