ISEbd-21_Agliullov.D.A._Con.../ConfectionaryListImplement/Shop.cs
2023-02-15 05:47:23 +04:00

65 lines
1.7 KiB
C#

using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDataModels;
using ConfectioneryDataModels.Models;
namespace ConfectioneryListImplement
{
public class Shop : IShopModel
{
public string Name { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public int MaxCountPastries { get; private set; }
public DateTime DateOpening { get; private set; }
public Dictionary<int, (IPastryModel, int)> Pastries
{
get;
private set;
} = new();
public int Id { get; private set; }
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
Name = model.Name,
Address = model.Address,
DateOpening = model.DateOpening,
MaxCountPastries = model.MaxCountPastries,
Pastries = new()
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
Address = model.Address;
DateOpening = model.DateOpening;
MaxCountPastries = model.MaxCountPastries;
Pastries = model.Pastries;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Address = Address,
Pastries = Pastries,
DateOpening = DateOpening,
MaxCountPastries = MaxCountPastries,
};
}
}