From 41fa66267d57286f097ce88e10ab06ac0ff01e73 Mon Sep 17 00:00:00 2001 From: dex_moth Date: Tue, 30 Apr 2024 15:57:30 +0400 Subject: [PATCH] =?UTF-8?q?vendor=20=D1=8F=20=D0=BD=D0=B0=D0=BF=D0=B8?= =?UTF-8?q?=D1=88=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ComputerHardwareStore.sln | 6 +++ .../ViewModels/ProductViewModel.cs | 4 +- .../ComputerHardwareStoreDBContext.cs | 3 ++ .../Models/Build.cs | 22 ++++++++ .../Models/Component.cs | 11 ++-- .../Models/Order.cs | 7 +-- .../Models/Product.cs | 3 +- .../Models/StoreKeeper.cs | 52 +++++++++++++++++++ 8 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Build.cs create mode 100644 ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/StoreKeeper.cs diff --git a/ComputerHardwareStore/ComputerHardwareStore.sln b/ComputerHardwareStore/ComputerHardwareStore.sln index 1edd1ac..cb44a3d 100644 --- a/ComputerHardwareStore/ComputerHardwareStore.sln +++ b/ComputerHardwareStore/ComputerHardwareStore.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreContra EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerHardwareStoreBusinessLogic", "ComputerHardwareStoreBusinessLogic\ComputerHardwareStoreBusinessLogic.csproj", "{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDatabaseImplement", "ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj", "{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Debug|Any CPU.Build.0 = Debug|Any CPU {D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Release|Any CPU.ActiveCfg = Release|Any CPU {D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Release|Any CPU.Build.0 = Release|Any CPU + {09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ProductViewModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ProductViewModel.cs index 00cc4c2..c1ba122 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ProductViewModel.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ProductViewModel.cs @@ -10,8 +10,6 @@ namespace ComputerHardwareStoreContracts.ViewModels public string Name { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } - public Dictionary CannedComponents { get; set; } = new(); - - public Dictionary ProductComponents => throw new NotImplementedException(); + public Dictionary ProductComponents { get; set; } = new(); } } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs index 9226f42..dac47e6 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs @@ -31,5 +31,8 @@ namespace ComputerHardwareStoreDatabaseImplement public virtual DbSet Components { set; get; } public virtual DbSet Products { set; get; } public virtual DbSet ProductComponents { set; get; } + + public virtual DbSet StoreKeepers { set; get; } + public virtual DbSet Builds { set; get; } } } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Build.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Build.cs new file mode 100644 index 0000000..4d650c3 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Build.cs @@ -0,0 +1,22 @@ + +using ComputerHardwareStoreDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ComputerHardwareStoreDatabaseImplement.Models +{ + public class Build : IBuildModel + { + public int Id { get; private set; } + [Required] + public string Name { get; private set; } = string.Empty; + [Required] + public double Price { get; set; } + [Required] + public int VendorId { get; private set; } + public virtual Vendor Vendor { get; private set; } = new(); + + [ForeignKey("BuildId")] + public Dictionary BuildComponents => throw new NotImplementedException(); + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Component.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Component.cs index 1a15d7e..3089400 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Component.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Component.cs @@ -13,9 +13,13 @@ namespace ComputerHardwareStoreDatabaseImplement.Models public string Name { get; private set; } = string.Empty; [Required] public double Cost { get; set; } + [Required] + public int StoreKeeperId { get; private set; } + public virtual StoreKeeper? StoreKeeper { get; set; } + [ForeignKey("ComponentId")] public virtual List ProductComponents { get; set; } = new(); - public static Component? Create(ComponentBindingModel model) + public static Component? Create(ComputerHardwareStoreDBContext context, ComponentBindingModel model) { if (model == null) { @@ -25,7 +29,8 @@ namespace ComputerHardwareStoreDatabaseImplement.Models { Id = model.Id, Name = model.Name, - Cost = model.Cost + Cost = model.Cost, + StoreKeeper = context.StoreKeepers.First(x => x.Id == model.StoreKeeperId) }; } public void Update (ComponentBindingModel model) @@ -44,7 +49,5 @@ namespace ComputerHardwareStoreDatabaseImplement.Models Name = Name, Cost = Cost }; - - public int StoreKeeperId => throw new NotImplementedException(); } } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Order.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Order.cs index eebf5a7..5c08691 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Order.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Order.cs @@ -30,12 +30,10 @@ namespace ComputerHardwareStoreDatabaseImplement.Models return new Order() { Id = model.Id, - Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - ProductId = model.CannedId, Product = context.Products.First(x => x.Id == model.ProductId) }; } @@ -51,12 +49,11 @@ namespace ComputerHardwareStoreDatabaseImplement.Models public OrderViewModel GetViewModel => new() { Id = Id, - ProductId = ProductId, - Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - ProductName = Product.ProductName }; + + public Dictionary OrderProduct => throw new NotImplementedException(); } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs index 0d67d07..a7af49c 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs @@ -23,8 +23,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models if (_productComponents == null) { _productComponents = Components - .ToDictionary(c => c.ComponentId, c => - (c.Component as IComponentModel, c.Count)); + .ToDictionary(c => c.ComponentId, c => (c.Component as IComponentModel, c.Count)); } return _productComponents; } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/StoreKeeper.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/StoreKeeper.cs new file mode 100644 index 0000000..1c2028d --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/StoreKeeper.cs @@ -0,0 +1,52 @@ +using ComputerHardwareStoreContracts.BindingModels; +using ComputerHardwareStoreContracts.ViewModels; +using ComputerHardwareStoreDataModels.Models; +using System.ComponentModel.DataAnnotations; + +namespace ComputerHardwareStoreDatabaseImplement.Models +{ + public class StoreKeeper : IStoreKeeperModel + { + public int Id { get; private set; } + [Required] + public string Name { get; private set; } = string.Empty; + [Required] + + public string Login { get; private set; } = string.Empty; + [Required] + + public string Password { get; private set; } = string.Empty; + + public static StoreKeeper? Create(ComputerHardwareStoreDBContext context, StoreKeeperBindingModel model) + { + if (model == null) + { + return null; + } + return new StoreKeeper() + { + Id = model.Id, + Name = model.Name, + Login = model.Login, + Password = model.Password, + }; + } + public void Update(StoreKeeperBindingModel model) + { + if (model == null) + { + return; + } + Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name; + Password = string.IsNullOrEmpty(model.Password) ? Password : model.Password; + } + + public StoreKeeperViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Login = Login, + Password = Password + }; + } +}