diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs index ea8f726..77fb590 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs @@ -47,22 +47,9 @@ namespace HardwareShopContracts.BusinessLogicsContracts { Id = purchase.Id, Builds = new List<(string Build, int count, List<(string Component, int count)>)>(), - Goods = new List<(string Good, int count, List<(string Component, int count)>)>(), TotalCount = 0, TotalCost = 0 }; - foreach (var good in purchase.PurchaseGoods) - { - List<(string Component, int count)> componentList = new List<(string Component, int count)>(); - int goodTotalCount = 0; - foreach (var component in good.Value.Item1.GoodComponents) - { - componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2)); - goodTotalCount += component.Value.Item2; - } - record.Goods.Add(new(good.Value.Item1.GoodName, good.Value.Item2, componentList)); - record.TotalCount += goodTotalCount * good.Value.Item2; - } foreach (var build in purchase.PurchaseBuilds) { List<(string Component, int count)> componentList = new List<(string Component, int count)>(); diff --git a/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs index 1e8661f..f53ac6b 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs @@ -12,8 +12,6 @@ namespace HardwareShopContracts.ViewModels public List<(string Build, int count, List<(string Component, int count)>)> Builds { get; set; } = new(); - public List<(string Good, int count, List<(string Component, int count)>)> Goods { get; set; } = new(); - public int TotalCount { get; set; } public int TotalCost { get; set; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs index 055bce1..8f1d6c7 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs @@ -27,8 +27,13 @@ namespace HardwareShopDatabaseImplement.Implements.Worker if (!model.UserId.HasValue && !model.PurchaseStatus.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) { return context.Purchases - .Include(x => x.Goods) - .ThenInclude(x => x.Good) + .Include(x => x.Builds) + .ThenInclude(x => x.Build) + .ThenInclude(x => x.Components) + .ThenInclude(x => x.Component) + .Include(x => x.Builds) + .ThenInclude(x => x.Build) + .ThenInclude(x => x.Comments) .Where(x => x.DatePurchase >= model.DateFrom && x.DatePurchase <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -50,6 +55,23 @@ namespace HardwareShopDatabaseImplement.Implements.Worker .ToList(); } + public List GetReportFilteredList(PurchaseSearchModel model) + { + using var context = new HardwareShopDatabase(); + if (!model.UserId.HasValue) + { + return null; + } + return context.Purchases + .Include(x => x.Builds) + .ThenInclude(x => x.Build) + .ThenInclude(x => x.Components) + .ThenInclude(x => x.Component) + .Where(x => x.UserId == model.UserId) + .Select(x => x.GetViewModel) + .ToList(); + } + public PurchaseViewModel? GetElement(PurchaseSearchModel model) { if (!model.Id.HasValue) diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs index 8efd262..d59a872 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs @@ -27,7 +27,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker public virtual List Comments { get; set; } = new(); [ForeignKey("BuildId")] - public virtual List? Components { get; set; } + public virtual List Components { get; set; } = new(); [ForeignKey("BuildId")] diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs index 352f3e1..86fdcb3 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs @@ -27,7 +27,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker public virtual User User { get; set; } [ForeignKey("PurchaseId")] - public virtual List? Builds { get; set; } + public virtual List Builds { get; set; } = new(); [ForeignKey("PurchaseId")] public virtual List Goods { get; set; } = new();