PIbd-21_Ihonkina_E.S._Preca.../PrecastConcretePlantDataBaseImplemet/Models/Component.cs

63 lines
1.8 KiB
C#
Raw Normal View History

2023-03-18 19:33:11 +04:00
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Models;
using System;
2023-03-18 18:19:08 +04:00
using System.Collections.Generic;
2023-03-18 19:33:11 +04:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2023-03-18 18:19:08 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-03-18 19:33:11 +04:00
namespace PrecastConcretePlantDatabaseImplement.Models
2023-03-18 18:19:08 +04:00
{
2023-03-18 19:33:11 +04:00
public class Component : IComponentModel
2023-03-18 18:19:08 +04:00
{
2023-03-18 19:33:11 +04:00
public int Id { get; private set; }
[Required]
public string ComponentName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
[ForeignKey("ComponentId")]
public virtual List<ReinforcedComponent> ReinforcedComponents { get; set; } =
new();
public static Component? Create(ComponentBindingModel model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public static Component Create(ComponentViewModel model)
{
return new Component
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public void Update(ComponentBindingModel model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
2023-03-18 18:19:08 +04:00
}
}