ISEbd-21_Agliullov.D.A._Con.../ConfectionaryListImplement/Shop.cs

65 lines
1.7 KiB
C#
Raw Normal View History

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,
2023-02-07 11:03:47 +04:00
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,
2023-02-06 01:31:42 +04:00
Pastries = Pastries,
DateOpening = DateOpening,
MaxCountPastries = MaxCountPastries,
};
}
}