105 lines
2.9 KiB
C#
105 lines
2.9 KiB
C#
|
using AircraftPlantContracts.BindingModels;
|
|||
|
using AircraftPlantContracts.ViewModels;
|
|||
|
using AircraftPlantDataModels.Models;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
using System.Diagnostics.Contracts;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Xml.Linq;
|
|||
|
|
|||
|
namespace AircraftPlantDatabaseImplement.Models
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Сущность "Компонент"
|
|||
|
/// </summary>
|
|||
|
public class Component : IComponentModel
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Идентификатор
|
|||
|
/// </summary>
|
|||
|
public int Id { get; private set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Название компонента
|
|||
|
/// </summary>
|
|||
|
[Required]
|
|||
|
public string ComponentName { get; private set; } = string.Empty;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Стоимость компонента
|
|||
|
/// </summary>
|
|||
|
[Required]
|
|||
|
public double Cost { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Связь с классом связи изделия и компонента
|
|||
|
/// </summary>
|
|||
|
[ForeignKey("ComponentId")]
|
|||
|
public virtual List<PlaneComponent> PlaneComponents { get; set; } = new();
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Создание модели компонента
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static Component? Create(ComponentBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
return new Component()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
ComponentName = model.ComponentName,
|
|||
|
Cost = model.Cost
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Создание модели компонента
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static Component Create(ComponentViewModel model)
|
|||
|
{
|
|||
|
return new Component()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
ComponentName = model.ComponentName,
|
|||
|
Cost = model.Cost
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Изменение модели компонента
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
public void Update(ComponentBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
ComponentName = model.ComponentName;
|
|||
|
Cost = model.Cost;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Получение модели компонента
|
|||
|
/// </summary>
|
|||
|
public ComponentViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
ComponentName = ComponentName,
|
|||
|
Cost = Cost
|
|||
|
};
|
|||
|
}
|
|||
|
}
|