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