fix
This commit is contained in:
parent
934080cd54
commit
8203d22849
@ -15,7 +15,6 @@ namespace HardwareShopContracts.BindingModels
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
|
||||
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,7 @@ namespace HardwareShopContracts.SearchModels
|
||||
public string? BuildName { get; set; } = string.Empty;
|
||||
|
||||
public int? UserId { get; set; }
|
||||
|
||||
public int? PurchaseId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
public BuildViewModel? Insert(BuildBindingModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
var newBuild = Build.Create(context, model);
|
||||
var newBuild = Build.Create(model);
|
||||
if (newBuild == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -21,7 +21,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
|
||||
public List<CommentViewModel> GetFilteredList(CommentSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.BuildId.HasValue && !model.UserId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
@ -35,7 +35,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return context.Comments
|
||||
.Include(x => x.Build)
|
||||
.Include(x => x.User)
|
||||
|
@ -47,18 +47,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
}
|
||||
}
|
||||
|
||||
public static Build Create(HardwareShopDatabase context, BuildBindingModel model)
|
||||
public static Build Create(BuildBindingModel model)
|
||||
{
|
||||
return new Build()
|
||||
{
|
||||
Id = model.Id,
|
||||
BuildName = model.BuildName,
|
||||
UserId = model.UserId,
|
||||
Purchases = model.BuildPurchases.Select(x => new PurchaseBuild
|
||||
{
|
||||
Purchase = context.Purchases.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
@ -75,6 +70,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
Price = Price,
|
||||
UserLogin = User.Login,
|
||||
UserId = UserId,
|
||||
BuildPurchases = BuildPurchases,
|
||||
};
|
||||
|
||||
public void UpdatePurchases(HardwareShopDatabase context, BuildBindingModel model)
|
||||
@ -94,13 +90,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
}
|
||||
var build = context.Builds.First(x => x.Id == Id);
|
||||
//добавляем в бд блюда которые есть в моделе, но ещё нет в бд
|
||||
foreach (var dc in model.BuildPurchases)
|
||||
foreach (var bp in model.BuildPurchases)
|
||||
{
|
||||
context.PurchasesBuilds.Add(new PurchaseBuild
|
||||
{
|
||||
Build = build,
|
||||
Purchase = context.Purchases.First(x => x.Id == dc.Key),
|
||||
Count = dc.Value.Item2
|
||||
Purchase = context.Purchases.First(x => x.Id == bp.Key),
|
||||
Count = bp.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
{
|
||||
PurchaseStatus = model.PurchaseStatus;
|
||||
DatePurchase = model.DatePurchase;
|
||||
Sum = model.Sum;
|
||||
}
|
||||
|
||||
public PurchaseViewModel GetViewModel => new()
|
||||
|
Loading…
Reference in New Issue
Block a user