удаление лишних инклудов

This commit is contained in:
Николай 2023-04-03 19:52:40 +04:00
parent 5c849f7d59
commit 76c9fa6580
9 changed files with 2 additions and 32 deletions

View File

@ -12,9 +12,6 @@ namespace HardwareShopContracts.ViewModels
[DisplayName("Название Сборки")]
public string BuildName { get; set; } = string.Empty;
[DisplayName("Логин пользователя")]
public string UserLogin { get; set; } = string.Empty;
public int UserId { get; set; }
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();

View File

@ -16,8 +16,5 @@ namespace HardwareShopContracts.ViewModels
public int BuildId { get; set; }
public int UserId { get; set; }
[DisplayName("Логин пользователя")]
public string UserLogin { get; set; } = string.Empty;
}
}

View File

@ -18,9 +18,6 @@ namespace HardwareShopContracts.ViewModels
public int UserId { get; set; }
[DisplayName("Логин пользователя")]
public string UserLogin { get; set; } = string.Empty;
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
}
}

View File

@ -15,7 +15,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
.Include(x => x.User)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
@ -57,7 +56,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Builds
.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) ||
(model.Id.HasValue && x.Id == model.Id))
@ -77,7 +75,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
.Include(x => x.User)
.Where(x => x.UserId == model.Id)
.FirstOrDefault(x => x.Id == newBuild.Id)
?.GetViewModel;
@ -92,7 +89,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
var build = context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
.Include(x => x.User)
.Where(x => x.UserId == model.UserId)
.FirstOrDefault(x => x.Id == model.Id);
if (build == null)
@ -118,7 +114,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
var element = context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
.Include(x => x.User)
.Where(x => x.UserId == model.Id)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)

View File

@ -14,7 +14,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
using var context = new HardwareShopDatabase();
return context.Comments
.Include(x => x.Build)
.Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
}
@ -30,14 +29,12 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
{
return context.Comments
.Include(x => x.Build)
.Include(x => x.User)
.Where(x => x.UserId == model.UserId)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Comments
.Include(x => x.Build)
.Include(x => x.User)
.Where(x => x.BuildId == model.BuildId)
.Select(x => x.GetViewModel)
.ToList();
@ -52,7 +49,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
using var context = new HardwareShopDatabase();
return context.Comments
.Include(x => x.Build)
.Include(x => x.User)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
@ -75,7 +71,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
using var context = new HardwareShopDatabase();
var comment = context.Comments
.Include(x => x.Build)
.Include(x => x.User)
.FirstOrDefault(x => x.Id == model.Id);
if (comment == null)
{
@ -91,7 +86,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
using var context = new HardwareShopDatabase();
var element = context.Comments
.Include(x => x.Build)
.Include(x => x.User)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{

View File

@ -17,7 +17,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
}
@ -34,7 +33,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User)
.Where(x => x.UserId == model.UserId)
.Select(x => x.GetViewModel)
.ToList();
@ -42,7 +40,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User)
.Where(x => x.DatePurchase == model.DatePurchase)
.Select(x => x.GetViewModel)
.ToList();
@ -58,7 +55,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
@ -76,7 +72,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User)
.FirstOrDefault(x => x.Id == newPurchase.Id)
?.GetViewModel;
}
@ -90,7 +85,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
var purchase = context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User)
.FirstOrDefault(x => x.Id == model.Id);
if (purchase == null)
{
@ -115,7 +109,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
var element = context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{

View File

@ -70,7 +70,6 @@ namespace HardwareShopDatabaseImplement.Models.Worker
Id = Id,
BuildName = BuildName,
Price = Price,
UserLogin = User.Login,
UserId = UserId,
BuildPurchases = BuildPurchases,
};
@ -91,7 +90,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
context.SaveChanges();
}
var build = context.Builds.First(x => x.Id == Id);
//добавляем в бд элементы которые есть в модели, но ещё нет в бд
//добавляем в бд сборки которые есть в модели, но ещё нет в бд
foreach (var bp in model.BuildPurchases)
{
context.PurchasesBuilds.Add(new PurchaseBuild

View File

@ -52,7 +52,6 @@ namespace HardwareShopDatabaseImplement.Models.Worker
BuildId = BuildId,
BuildName = Build.BuildName,
UserId = UserId,
UserLogin = User.Login,
};
}
}

View File

@ -78,7 +78,6 @@ namespace HardwareShopDatabaseImplement.Models.Worker
PurchaseStatus = PurchaseStatus,
DatePurchase = DatePurchase,
UserId = UserId,
UserLogin = User.Login,
PurchaseGoods = PurchaseGoods
};
@ -98,7 +97,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
context.SaveChanges();
}
var purchase = context.Purchases.First(x => x.Id == Id);
//добавляем в бд блюда которые есть в моделе, но ещё нет в бд
//добавляем в бд товары которые есть в моделе, но ещё нет в бд
foreach (var dc in model.PurchaseGoods)
{
context.PurchasesGoods.Add(new PurchaseGood