CourseWork_Factory/FactoryView/FactoryDatabaseImplement/Models/Component.cs

62 lines
1.5 KiB
C#
Raw Normal View History

2023-04-08 19:10:10 +04:00

using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FactoryDataModels.Models;
namespace FactoryDatabaseImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
[Required]
public string ComponentName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
[Required]
public int EnginierId { get; set; }
[ForeignKey("ComponentId")]
public virtual List<ReinforcedComponent> ReinforcedComponents { get; set; } = new();
[ForeignKey("ComponentId")]
public virtual List<Stage> Stages { get; set; } = new();
public static Component Create(ComponentBindingModel model)
{
return new Component
{
Id = model.Id,
ComponentName = model.ComponentName,
};
}
public void Update(ComponentBindingModel model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
};
}
}