diff --git a/Course/Contracts/BindingModels/ProductBindingModel.cs b/Course/Contracts/BindingModels/ProductBindingModel.cs index 57e6974..f4891e6 100644 --- a/Course/Contracts/BindingModels/ProductBindingModel.cs +++ b/Course/Contracts/BindingModels/ProductBindingModel.cs @@ -8,6 +8,9 @@ namespace Contracts.BindingModels public int UserId { get; set; } public string Name { get; set; } = string.Empty; public double Cost { get; set; } + public Dictionary ProductDetails { get; set; } = new(); - } + + public int? MachineId { get; set; } + } } diff --git a/Course/Contracts/SearchModels/ProductSearchModel.cs b/Course/Contracts/SearchModels/ProductSearchModel.cs index ba7016d..5f6bdae 100644 --- a/Course/Contracts/SearchModels/ProductSearchModel.cs +++ b/Course/Contracts/SearchModels/ProductSearchModel.cs @@ -11,5 +11,6 @@ namespace Contracts.SearchModels public int? Id { get; set; } public string? Name { get; set; } public int? UserId { get; set; } + public int? MachineId { get; set; } } } diff --git a/Course/Contracts/ViewModels/ProductViewModel.cs b/Course/Contracts/ViewModels/ProductViewModel.cs index 1ea4eb4..6ac9be4 100644 --- a/Course/Contracts/ViewModels/ProductViewModel.cs +++ b/Course/Contracts/ViewModels/ProductViewModel.cs @@ -16,6 +16,7 @@ namespace Contracts.ViewModels [DisplayName("Цена изделия")] public double Cost { get; set; } public int UserId { get; set; } + public int? MachineId { get; set; } public Dictionary DetailProducts { get; set; } = new(); } } diff --git a/Course/DataModels/Models/IProductModel.cs b/Course/DataModels/Models/IProductModel.cs index e61107e..b70bc62 100644 --- a/Course/DataModels/Models/IProductModel.cs +++ b/Course/DataModels/Models/IProductModel.cs @@ -4,5 +4,6 @@ { string Name { get; } double Cost { get; } + int? MachineId { get; } } } diff --git a/Course/DatabaseImplement/Models/Product.cs b/Course/DatabaseImplement/Models/Product.cs index d3d568d..9b31d2f 100644 --- a/Course/DatabaseImplement/Models/Product.cs +++ b/Course/DatabaseImplement/Models/Product.cs @@ -16,6 +16,8 @@ namespace DatabaseImplement.Models [Required] public int UserId { get; set; } public virtual Implementer User { get; set; } + public int? MachineId { get; set; } + public virtual Machine? Machine { get; set; } private Dictionary? _detailProducts = null; [NotMapped] public Dictionary DetailProducts @@ -44,6 +46,8 @@ namespace DatabaseImplement.Models Name = model.Name, Cost = model.Cost, UserId = model.UserId, + MachineId = model.MachineId, + Machine = model.MachineId.HasValue ? context.Machines.FirstOrDefault(x => x.Id == model.MachineId) : null, Details = model.ProductDetails.Select(x => new DetailProduct { Detail = context.Details.First(y => y.Id == x.Key), @@ -58,7 +62,8 @@ namespace DatabaseImplement.Models Id = model.Id, Name = model.Name, Cost = model.Cost, - UserId = model.UserId + UserId = model.UserId, + MachineId = model.MachineId }; } public void Update(ProductBindingModel model) @@ -67,6 +72,7 @@ namespace DatabaseImplement.Models return; Name = model.Name; Cost = model.Cost; + MachineId = model.MachineId; } public ProductViewModel GetViewModel => new() { @@ -74,7 +80,8 @@ namespace DatabaseImplement.Models Name = Name, Cost = Cost, UserId = UserId, - DetailProducts = DetailProducts + DetailProducts = DetailProducts, + MachineId= MachineId }; public void UpdateDetails(FactoryGoWorkDatabase context, ProductBindingModel model) {