diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs index 4bc9653..81ed199 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs @@ -25,13 +25,17 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper } public List GetBuildGood(List goods) { - /*var result = new List(); + 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)) + var builds = good.GoodComponents + //получили сборки и количество компонентов + .Select(x => _componentStorage.GetComponentBuilds(new() { Id = x.Key }) + //если кол-во компонентов в товаре == кол-ву в сборке + .Where(y => x.Value.Item2 == y.Item2)) + .SelectMany(x => x.Select(x => x.Item1)) + .Distinct() .ToList(); ReportBuildGoodViewModel record = new() { @@ -40,30 +44,7 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper }; result.Add(record); } - return result;*/ - - - var list = new List(); - var builds = _buildStorage.GetFullList(); - - foreach (var good in goods) - { - var record = new ReportBuildGoodViewModel - { - GoodName = good.GoodName, - Builds = new() - }; - var components = good.GoodComponents; - foreach (var build in builds) - { - // сработает ли такая проверка? - if (build.BuildComponents == good.GoodComponents) - { - builds.Add(build); - } - } - } - return list; + return result; } public List GetComponents(ReportBindingModel model) diff --git a/HardwareShop/HardwareShopClientApp/Program.cs b/HardwareShop/HardwareShopClientApp/Program.cs index c96d71c..197e9bb 100644 --- a/HardwareShop/HardwareShopClientApp/Program.cs +++ b/HardwareShop/HardwareShopClientApp/Program.cs @@ -1,4 +1,9 @@ -/*using HardwareShopClientApp; +using HardwareShopClientApp; +using HardwareShopBusinessLogic.BusinessLogics.Storekeeper; +using HardwareShopDatabaseImplement.Implements.Storekeeper; +using HardwareShopDatabaseImplement.Implements.Worker; +/* + var builder = WebApplication.CreateBuilder(args); @@ -26,12 +31,10 @@ app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); -app.Run(); +//app.Run(); */ -using HardwareShopBusinessLogic.BusinessLogics.Storekeeper; -using HardwareShopDatabaseImplement.Implements.Storekeeper; -using HardwareShopDatabaseImplement.Implements.Worker; + ComponentStorage _componentStorage = new(); GoodStorage _goodStorage = new(); @@ -53,4 +56,5 @@ foreach (var reportRecord in reportRecords) Console.WriteLine(i + 1 + ". " + reportRecord.Builds[i]); } Console.WriteLine(); -} \ No newline at end of file +} + diff --git a/HardwareShop/HardwareShopContracts/StoragesContracts/IComponentStorage.cs b/HardwareShop/HardwareShopContracts/StoragesContracts/IComponentStorage.cs index bf1430d..e77aa04 100644 --- a/HardwareShop/HardwareShopContracts/StoragesContracts/IComponentStorage.cs +++ b/HardwareShop/HardwareShopContracts/StoragesContracts/IComponentStorage.cs @@ -12,5 +12,6 @@ namespace HardwareShopContracts.StoragesContracts ComponentViewModel? Insert(ComponentBindingModel model); ComponentViewModel? Update(ComponentBindingModel model); ComponentViewModel? Delete(ComponentBindingModel model); + List> GetComponentBuilds(ComponentSearchModel model); } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Storekeeper/ComponentStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Storekeeper/ComponentStorage.cs index 8526a34..5636352 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Storekeeper/ComponentStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Storekeeper/ComponentStorage.cs @@ -118,5 +118,19 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper throw; } } + + public List> GetComponentBuilds(ComponentSearchModel model) + { + if (model == null) + { + return new(); + } + using var context = new HardwareShopDatabase(); + var builds = context.ComponentsBuilds + .Where(x => x.ComponentId == model.Id) + .Select(x => new Tuple(x.Build.BuildName, x.Count)) + .ToList(); + return builds; + } } }