PIbd-21_MasenkinMS_Aircraft.../AircraftPlant/AircraftPlantListImplement/Models/Plane.cs
2024-02-21 01:42:28 +04:00

91 lines
2.4 KiB
C#

using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantListImplement.Models
{
/// <summary>
/// Сущность "Изделие"
/// </summary>
public class Plane : IPlaneModel
{
/// <summary>
/// Идентификатор
/// </summary>
public int Id { get; private set; }
/// <summary>
/// Название изделия
/// </summary>
public string PlaneName { get; private set; } = string.Empty;
/// <summary>
/// Стоимость изделия
/// </summary>
public double Price { get; private set; }
/// <summary>
/// Коллекция компонентов изделия
/// </summary>
public Dictionary<int, (IComponentModel, int)> PlaneComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
/// <summary>
/// Создание модели изделия
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public static Plane? Create(PlaneBindingModel? model)
{
if (model == null)
{
return null;
}
return new Plane()
{
Id = model.Id,
PlaneName = model.PlaneName,
Price = model.Price,
PlaneComponents = model.PlaneComponents
};
}
/// <summary>
/// Изменение модели изделия
/// </summary>
/// <param name="model"></param>
public void Update(PlaneBindingModel? model)
{
if (model == null)
{
return;
}
PlaneName = model.PlaneName;
Price = model.Price;
PlaneComponents = model.PlaneComponents;
}
/// <summary>
/// Получение модели изделия
/// </summary>
public PlaneViewModel GetViewModel => new()
{
Id = Id,
PlaneName = PlaneName,
Price = Price,
PlaneComponents = PlaneComponents
};
}
}