2024-03-26 18:50:50 +04:00
|
|
|
|
using AircraftPlantContracts.BindingModels;
|
|
|
|
|
using AircraftPlantContracts.ViewModels;
|
|
|
|
|
using AircraftPlantDataModels.Models;
|
2024-03-26 21:23:10 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2024-03-26 18:50:50 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2024-06-21 14:01:04 +04:00
|
|
|
|
using System.Diagnostics.Contracts;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml.Linq;
|
2024-03-26 18:50:50 +04:00
|
|
|
|
|
|
|
|
|
namespace AircraftPlantDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Component : IComponentModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
public string ComponentName { get; private set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public double Cost { get; set; }
|
|
|
|
|
[ForeignKey("ComponentId")]
|
|
|
|
|
public virtual List<PlaneComponent> PlaneComponents { get; set; } = new();
|
|
|
|
|
public static Component? Create(ComponentBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2024-06-21 14:01:04 +04:00
|
|
|
|
|
2024-03-26 18:50:50 +04:00
|
|
|
|
return new Component()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
ComponentName = model.ComponentName,
|
|
|
|
|
Cost = model.Cost
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public static Component Create(ComponentViewModel model)
|
|
|
|
|
{
|
2024-06-21 14:01:04 +04:00
|
|
|
|
return new Component()
|
2024-03-26 18:50:50 +04:00
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
ComponentName = model.ComponentName,
|
|
|
|
|
Cost = model.Cost
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(ComponentBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-21 14:01:04 +04:00
|
|
|
|
|
2024-03-26 18:50:50 +04:00
|
|
|
|
ComponentName = model.ComponentName;
|
|
|
|
|
Cost = model.Cost;
|
|
|
|
|
}
|
|
|
|
|
public ComponentViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
ComponentName = ComponentName,
|
|
|
|
|
Cost = Cost
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-03-26 21:23:10 +04:00
|
|
|
|
}
|