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 Komment : IKommentModel { 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 Komment? Create(KommentBindingModel model) { if (model == null) { return null; } return new Komment() { Id = model.Id, WorkPieceName = model.WorkPieceName, Cost = model.Cost }; } public static Komment Create(KommentViewModel model) { return new Komment { Id = model.Id, WorkPieceName = model.WorkPieceName, Cost = model.Cost }; } public void Update(KommentBindingModel model) { if (model == null) { return; } WorkPieceName = model.WorkPieceName; Cost = model.Cost; } public KommentViewModel GetViewModel => new() { Id = Id, WorkPieceName = WorkPieceName, Cost = Cost }; } }