PIbd-23-Yunusov-N.N.-CarRep.../CarRepairShop/CarRepairShopListImplement/Models/Repair.cs

50 lines
1.4 KiB
C#
Raw Normal View History

2024-02-09 22:08:31 +04:00
using CarRepairShopContracts.BindingModels;
using CarRepairShopContracts.ViewModels;
using CarRepairShopDataModels.Models;
namespace CarRepairShopListImplement.Models
{
public class Repair : IRepairModel
{
public int Id { get; private set; }
public string RepairName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> RepairComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Repair? Create(RepairBindingModel? model)
{
if (model == null)
{
return null;
}
return new Repair()
{
Id = model.Id,
RepairName = model.RepairName,
Price = model.Price,
RepairComponents = model.RepairComponents
};
}
public void Update(RepairBindingModel? model)
{
if (model == null)
{
return;
}
RepairName = model.RepairName;
Price = model.Price;
RepairComponents = model.RepairComponents;
}
public RepairViewModel GetViewModel => new()
{
Id = Id,
RepairName = RepairName,
Price = Price,
RepairComponents = RepairComponents
};
}
}