using ComputerShopContracts.BindingModels; using ComputerShopContracts.ViewModels; using ComputerShopDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace ComputerShopDatabaseImplement.Models { public class Component : IComponentModel { public int Id { get; private set; } [Required] public double Cost { get; private set; } [Required] public string ComponentName { get; private set; } = string.Empty; [Required] public string Description { get; private set; } = string.Empty; [Required] public int UserId { get; private set; } [ForeignKey("ComponentId")] public virtual List AssemblyComponents { get; set; } = new(); public static Component Create(ComponentBindingModel Model) { return new() { Id = Model.Id, Cost = Model.Cost, ComponentName = Model.ComponentName, UserId = Model.UserId, }; } public void Update(ComponentBindingModel Model) { Cost = Model.Cost; ComponentName = Model.ComponentName; } public ComponentViewModel ViewModel => new() { Id = Id, Cost = Cost, ComponentName = ComponentName, UserId = UserId, }; } }