PIbd22_NikiforovaMV_Automob.../AutomobilePlantListImplements/Models/Car.cs
2024-04-17 10:13:26 +04:00

58 lines
1.5 KiB
C#

using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModels;
namespace AutomobilePlantListImplements.Models
{
public class Car : ICarModel
{
public string CarName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> CarComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
public int Id { get; private set; }
public static Car? Create(CarBindingModel? model)
{
if (model == null)
{
return null;
}
return new Car()
{
Id = model.Id,
CarName = model.CarName,
Price = model.Price,
CarComponents = model.CarComponents
};
}
public void Update(CarBindingModel? model)
{
if (model == null)
{
return;
}
CarName = model.CarName;
Price = model.Price;
CarComponents = model.CarComponents;
}
public CarViewModel GetViewModel => new()
{
Id = Id,
CarName = CarName,
Price = Price,
CarComponents = CarComponents
};
}
}