From ff2f0d57db9832a092f87024bff1b0923976ece6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sun, 2 Apr 2023 16:32:22 +0400 Subject: [PATCH] fix --- .../SearchModels/BuildSearchModel.cs | 2 - .../Implements/Worker/BuildStorage.cs | 45 ++++++++++--------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs index 19cb465..3d5caee 100644 --- a/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs +++ b/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs @@ -8,7 +8,5 @@ namespace HardwareShopContracts.SearchModels public string? BuildName { get; set; } = string.Empty; public int? UserId { get; set; } - - public int? PurchaseId { get; set; } } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs index 8b8c068..cd6992f 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs @@ -13,9 +13,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker { using var context = new HardwareShopDatabase(); return context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) .Include(x => x.User) .ToList() .Select(x => x.GetViewModel) @@ -24,17 +23,25 @@ namespace HardwareShopDatabaseImplement.Implements.Worker public List GetFilteredList(BuildSearchModel model) { - if (!model.UserId.HasValue) + if (string.IsNullOrEmpty(model.BuildName) && !model.UserId.HasValue) { return new(); } using var context = new HardwareShopDatabase(); + if (!string.IsNullOrEmpty(model.BuildName)) + { + return context.Builds + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) + .Include(x => x.BuildName.Contains(model.BuildName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } return context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) - .Include(x => x.User) - .Where(x => x.UserId == model.UserId) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) + .Include(x => x.UserId == model.UserId) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -48,9 +55,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker } using var context = new HardwareShopDatabase(); return context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) .Include(x => x.User) .Where(x => x.Id == model.Id) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) || @@ -69,9 +75,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker context.Builds.Add(newBuild); context.SaveChanges(); return context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) .Include(x => x.User) .Where(x => x.UserId == model.Id) .FirstOrDefault(x => x.Id == newBuild.Id) @@ -85,9 +90,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker try { var build = context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) .Include(x => x.User) .Where(x => x.UserId == model.UserId) .FirstOrDefault(x => x.Id == model.Id); @@ -112,9 +116,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker { using var context = new HardwareShopDatabase(); var element = context.Builds - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Include(x => x.Comments) + .Include(x => x.Purchases) + .ThenInclude(x => x.Purchase) .Include(x => x.User) .Where(x => x.UserId == model.Id) .FirstOrDefault(rec => rec.Id == model.Id);