using ComputerShopContracts.BindingModels; using ComputerShopContracts.ViewModels; using ComputerShopDataModels.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 ComputerShopDatabaseImplement.Models { public class Request : IRequestModel { public int Id { get; set; } public int? AssemblyId { get; set; } public virtual Assembly? Assembly { get; set; } = new(); [Required] public DateTime DateRequest { get; set; } public static Request Create(ComputerShopDatabase context, RequestBindingModel model) { return new Request() { Id = model.Id, AssemblyId = model.AssemblyId, Assembly = model.AssemblyId.HasValue ? context.Assemblies.First(x => x.Id == model.AssemblyId) : null, DateRequest = model.DateRequest, }; } public void Update(RequestBindingModel model) { if (model == null) { return; } } public RequestViewModel GetViewModel => new() { Id = Id, AssemblyId = AssemblyId, Assembly = Assembly, DateRequest = DateRequest, }; public void ConnectAssembly(ComputerShopDatabase context, int assemblyId) { AssemblyId = assemblyId; Assembly = context.Assemblies.First(x => x.Id == assemblyId); } } }