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; } [Required] public int UserId { get; set; } public virtual User User { get; set; } public int AssemblyId { get; set; } [Required] public DateTime DateMake { get; set; } [Required] public string ClientFIO { get; set; } = string.Empty; private Dictionary? _requestOrders = null; [NotMapped] public Dictionary RequestOrders { get { if (_requestOrders == null) { //!!!ТУТ ПРОПИСАТЬ ЛОГИКУ (НЕ ЗНАЮ ПОКА, КАК) } return _requestOrders; } } [ForeignKey("OrderId")] public virtual List Orders { get; set; } = new(); public static Request Create(ComputerShopDatabase context, RequestBindingModel model) { return new Request() { Id = model.Id, UserId = model.UserId, AssemblyId = model.AssemblyId, DateMake = model.DateMake, ClientFIO = model.ClientFIO, Orders = model.RequestOrders.Select(x => new RequestOrder { Order = context.Orders.First(y => y.Id == x.Key) }).ToList() }; } //!!!МБ ТУТ ЕЩЁ ЧТО-ТО ОБНОВИТЬ public void Update(RequestBindingModel model) { DateMake = model.DateMake; ClientFIO = model.ClientFIO; } //!!!МБ ТУТ НЕ ВСЁ НАДО ПРИСВАИВАТЬ public RequestViewModel GetViewModel => new() { Id = Id, UserId = UserId, UserLogin = User.Login, AssemblyId = AssemblyId, DateMake = DateMake, ClientFIO = ClientFIO }; //!!!ДОПИСАТЬ UpdateOrders } }