Лишние инклуды

This commit is contained in:
dasha 2023-04-03 19:32:56 +04:00
parent 0a57d3ebf3
commit ea30411791
9 changed files with 7 additions and 38 deletions

View File

@ -11,8 +11,6 @@ namespace HardwareShopContracts.ViewModels
[DisplayName("Цена")]
public double Cost { get; set; }
public int UserId { get; set; }
[DisplayName("Логин кладовщика")]
public string UserLogin { get; set; } = string.Empty;
public Dictionary<int, (IBuildModel, int)>? ComponentsBuilds
{
get;

View File

@ -11,8 +11,6 @@ namespace HardwareShopContracts.ViewModels
[DisplayName("Цена")]
public double Price { get; set; }
public int UserId { get; set; }
[DisplayName("Логин кладовщика")]
public string UserLogin { get; set; } = string.Empty;
public Dictionary<int, (IComponentModel, int)> GoodsComponents
{
get;

View File

@ -10,8 +10,6 @@ namespace HardwareShopContracts.ViewModels
public int Id { get; set; }
public int GoodId { get; set; }
public int UserId { get; set; }
[DisplayName("Логин кладовщика")]
public string UserLogin { get; set; } = string.Empty;
[DisplayName("Товар")]
public string GoodName { get; set; } = string.Empty;
[DisplayName("Количество")]

View File

@ -13,7 +13,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
{
using var context = new HardwareShopDatabase();
var element = context.Components
.Include(x => x.User)
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.FirstOrDefault(rec => rec.Id == model.Id);
@ -31,14 +30,12 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
using var context = new HardwareShopDatabase();
if (!string.IsNullOrEmpty(model.ComponentName) || model.Id.HasValue)
return context.Components
.Include(x => x.User)
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName)
&& x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
if (model.UserId.HasValue)
return context.Components
.Include(x => x.User)
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.FirstOrDefault(x => x.UserId == model.UserId)?.GetViewModel;
@ -51,7 +48,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
if (model.UserId.HasValue)
{
return context.Components
.Include(x => x.User)
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.Where(x => x.UserId == model.UserId)
@ -61,7 +57,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
if (!string.IsNullOrEmpty(model.ComponentName))
{
return context.Components
.Include(x => x.User)
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.Where(x => x.ComponentName.Contains(model.ComponentName))
@ -75,7 +70,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
{
using var context = new HardwareShopDatabase();
return context.Components
.Include(x => x.User)
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.Select(x => x.GetViewModel)
@ -93,7 +87,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
context.Components.Add(newComponent);
context.SaveChanges();
return context.Components
.Include(x => x.User)
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.FirstOrDefault(x => x.Id == newComponent.Id)?.GetViewModel;
@ -106,7 +99,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
try
{
var good = context.Components
.Include(x => x.User)
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.FirstOrDefault(rec => rec.Id == model.Id);

View File

@ -13,7 +13,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
{
using var context = new HardwareShopDatabase();
var element = context.Goods
.Include(x => x.User)
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.FirstOrDefault(rec => rec.Id == model.Id);
@ -31,14 +30,12 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
using var context = new HardwareShopDatabase();
if (model.UserId.HasValue)
return context.Goods
.Include(x => x.User)
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.FirstOrDefault(x => x.UserId == model.UserId)
?.GetViewModel;
if (!string.IsNullOrEmpty(model.GoodName) || model.Id.HasValue)
return context.Goods
.Include(x => x.User)
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.GoodName) && x.GoodName == model.GoodName) ||
@ -52,7 +49,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
using var context = new HardwareShopDatabase();
if (model.UserId.HasValue)
return context.Goods
.Include(x => x.User)
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.Where(x => x.UserId == model.UserId)
@ -60,7 +56,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
.ToList();
if (!string.IsNullOrEmpty(model.GoodName))
return context.Goods
.Include(x => x.User)
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.Where(x => x.GoodName.Contains(model.GoodName))
@ -73,7 +68,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
{
using var context = new HardwareShopDatabase();
return context.Goods
.Include(x => x.User)
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.Select(x => x.GetViewModel)
@ -91,7 +85,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
context.Goods.Add(newGood);
context.SaveChanges();
return context.Goods
.Include(x => x.User)
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.FirstOrDefault(x => x.Id == newGood.Id)?.GetViewModel;
@ -104,7 +97,6 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
try
{
var good = context.Goods
.Include(x => x.User)
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.FirstOrDefault(rec => rec.Id == model.Id);

View File

@ -13,7 +13,7 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
{
using var context = new HardwareShopDatabase();
var element = context.Orders
.Include(x => x.Good).Include(x => x.User)
.Include(x => x.Good)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
@ -32,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
}
using var context = new HardwareShopDatabase();
return context.Orders
.Include(x => x.Good).Include(x => x.User)
.Include(x => x.Good)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
@ -45,7 +45,7 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
}
using var context = new HardwareShopDatabase();
return context.Orders
.Include(x => x.Good).Include(x => x.User)
.Include(x => x.Good)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
@ -55,7 +55,7 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
{
using var context = new HardwareShopDatabase();
return context.Orders
.Include(x => x.Good).Include(x => x.User)
.Include(x => x.Good)
.Select(x => x.GetViewModel)
.ToList();
}
@ -71,7 +71,7 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
context.Orders.Add(newOrder);
context.SaveChanges();
return context.Orders
.Include(x => x.Good).Include(x => x.User)
.Include(x => x.Good)
.FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel;
}
@ -80,7 +80,7 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
{
using var context = new HardwareShopDatabase();
var order = context.Orders
.Include(x => x.Good).Include(x => x.User)
.Include(x => x.Good)
.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{

View File

@ -27,8 +27,6 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
[ForeignKey("ComponentId")]
public virtual List<ComponentBuild> Builds { get; set; } = new();
public virtual User User { get; set; } = null!;
private Dictionary<int, (IBuildModel, int)>? _componentsBuilds = null;
[NotMapped]
@ -76,7 +74,6 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
ComponentName = ComponentName,
Cost = Cost,
UserId = UserId,
UserLogin = User.Login,
ComponentsBuilds = ComponentsBuilds
};

View File

@ -20,8 +20,6 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
[Required]
public int UserId { get; set; }
public virtual User User { get; set; } = null!;
private Dictionary<int, (IComponentModel, int)>? _goodsComponents = null;
[ForeignKey("GoodId")]
@ -79,7 +77,6 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
GoodName = GoodName,
Price = Price,
UserId = UserId,
UserLogin = User.Login,
GoodsComponents = GoodsComponents
};

View File

@ -30,8 +30,6 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
public DateTime? DateImplement { get; set; }
public virtual User User { get; set; } = null!;
public virtual Good Good { get; set; } = null!;
public static Order? Create(OrderBindingModel? model)
@ -73,8 +71,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
GoodName = Good.GoodName,
UserLogin = User.Login
GoodName = Good.GoodName
};
}
}