52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
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
|
|
};
|
|
}
|
|
}
|