PIbd-23-Radaev-A.V.-GiftShop/GiftShop/GiftShopListImplement/Models/Gift.cs

52 lines
1.3 KiB
C#
Raw Permalink Normal View History

2024-02-06 12:37:25 +04:00
using GiftShopContracts.BindingModels;
using GiftShopContracts.ViewModels;
using GiftShopDataModels.Models;
namespace GiftShopListImplement.Models
{
internal class Gift : IGiftModel
{
public int Id { get; private set; }
public string GiftName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> GiftComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
public static Gift? Create(GiftBindingModel? model)
{
if (model == null)
{
return null;
}
return new Gift()
{
Id = model.Id,
GiftName = model.GiftName,
Price = model.Price,
GiftComponents = model.GiftComponents
};
}
public void Update(GiftBindingModel? model)
{
if (model == null)
{
return;
}
GiftName = model.GiftName;
Price = model.Price;
GiftComponents = model.GiftComponents;
}
public GiftViewModel GetViewModel => new()
{
Id = Id,
GiftName = GiftName,
Price = Price,
GiftComponents = GiftComponents
};
}
}