using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using FurnitureAssemblyDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FurnitureAssemblyDatabaseImplement.Models { public class Workpiece : IWorkpieceModel { public int Id { get; private set; } [Required] public string WorkpieceName { get; private set; } = string.Empty; [Required] public double Cost { get; set; } // для реализации связи многие ко многим с изделиями [ForeignKey("WorkpieceId")] public virtual List FurnitureWorkpieces { get; set; } = new(); public static Workpiece? Create(WorkpieceBindingModel model) { if (model == null) { return null; } return new Workpiece() { Id = model.Id, WorkpieceName = model.WorkpieceName, Cost = model.Cost }; } public static Workpiece Create(WorkpieceViewModel model) { return new Workpiece { Id = model.Id, WorkpieceName = model.WorkpieceName, Cost = model.Cost }; } public void Update(WorkpieceBindingModel model) { if (model == null) { return; } WorkpieceName = model.WorkpieceName; Cost = model.Cost; } public WorkpieceViewModel GetViewModel => new() { Id = Id, WorkpieceName = WorkpieceName, Cost = Cost }; } }