From 576d8eef75980284f117bad3eb2da6bd8c07ce44 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 4 Apr 2023 18:48:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Storekeeper/ReportStorekeeperLogic.cs | 18 ++++++++++++ .../HardwareShopClientApp.csproj | 1 + HardwareShop/HardwareShopClientApp/Program.cs | 29 ++++++++++++++++++- .../HardwareShopDatabase.cs | 2 +- .../Models/Storekeeper/Component.cs | 1 + .../Models/Storekeeper/Good.cs | 2 ++ 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs index 2b70fe5..4bc9653 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs @@ -25,6 +25,24 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper } public List GetBuildGood(List goods) { + /*var result = new List(); + + foreach (var good in goods) + { + var builds = good.GoodComponents? + .SelectMany(x => x.Value.Item1.ComponentBuilds + .Select(y => y.Value.Item1.BuildName)) + .ToList(); + ReportBuildGoodViewModel record = new() + { + GoodName = good.GoodName, + Builds = builds + }; + result.Add(record); + } + return result;*/ + + var list = new List(); var builds = _buildStorage.GetFullList(); diff --git a/HardwareShop/HardwareShopClientApp/HardwareShopClientApp.csproj b/HardwareShop/HardwareShopClientApp/HardwareShopClientApp.csproj index db0fa77..56e9939 100644 --- a/HardwareShop/HardwareShopClientApp/HardwareShopClientApp.csproj +++ b/HardwareShop/HardwareShopClientApp/HardwareShopClientApp.csproj @@ -12,6 +12,7 @@ + diff --git a/HardwareShop/HardwareShopClientApp/Program.cs b/HardwareShop/HardwareShopClientApp/Program.cs index 9ff3bc8..c96d71c 100644 --- a/HardwareShop/HardwareShopClientApp/Program.cs +++ b/HardwareShop/HardwareShopClientApp/Program.cs @@ -1,4 +1,4 @@ -using HardwareShopClientApp; +/*using HardwareShopClientApp; var builder = WebApplication.CreateBuilder(args); @@ -27,3 +27,30 @@ app.MapControllerRoute( pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); +*/ + +using HardwareShopBusinessLogic.BusinessLogics.Storekeeper; +using HardwareShopDatabaseImplement.Implements.Storekeeper; +using HardwareShopDatabaseImplement.Implements.Worker; + +ComponentStorage _componentStorage = new(); +GoodStorage _goodStorage = new(); +PurchaseStorage _purchaseStorage = new(); +BuildStorage _buildStorage = new(); + +ReportStorekeeperLogic reportLogic = new(_componentStorage, _goodStorage, _purchaseStorage, _buildStorage); + +var goods = _goodStorage.GetFilteredList(new() { UserId = 1 }); +var reportRecords = reportLogic.GetBuildGood(goods); + +Console.WriteLine("start"); +foreach (var reportRecord in reportRecords) +{ + Console.WriteLine("good: " + reportRecord.GoodName); + Console.WriteLine("> builds:"); + for (int i = 0; i < reportRecord.Builds.Count; i++) + { + Console.WriteLine(i + 1 + ". " + reportRecord.Builds[i]); + } + Console.WriteLine(); +} \ No newline at end of file diff --git a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs index 0ef834d..90abdf7 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs @@ -10,7 +10,7 @@ namespace HardwareShopDatabaseImplement { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store;Username=user;Password=12345"); + optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Database=Computer_Hardware_Store;Username=user;Password=12345"); } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Component.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Component.cs index 5918beb..a1c0cad 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Component.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Component.cs @@ -84,6 +84,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper { // удалили те, которых нет в модели context.ComponentsBuilds.RemoveRange(componentBuilds.Where(rec => !model.ComponentBuilds.ContainsKey(rec.BuildId))); context.SaveChanges(); + componentBuilds = context.ComponentsBuilds.Where(rec => rec.ComponentId == model.Id).ToList(); // обновили количество у существующих записей foreach (var updateBuild in componentBuilds) { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs index 2af49d1..0914995 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs @@ -90,6 +90,8 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper .RemoveRange(goodComponents .Where(rec => !model.GoodComponents.ContainsKey(rec.ComponentId))); context.SaveChanges(); + goodComponents = context.GoodsComponents + .Where(rec => rec.GoodId == model.Id).ToList(); // обновили количество у существующих записей foreach (var updateComponent in goodComponents) {