PIbd-21_MasenkinMS_Aircraft.../AircraftPlant/AircraftPlantDatabaseImplement/Models/Component.cs
2024-03-10 01:33:27 +04:00

105 lines
2.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
};
}
}