This commit is contained in:
Николай 2023-04-02 16:37:37 +04:00
parent 03d8c6db0a
commit cf82bd4fe7
2 changed files with 7 additions and 7 deletions

View File

@ -12,7 +12,7 @@ namespace HardwareShopContracts.BindingModels
public int UserId { get; set; }
public Dictionary<int, (IComponentModel, int)> GoodComponents
public Dictionary<int, (IComponentModel, int)> GoodsComponents
{
get;
set;

View File

@ -55,7 +55,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
GoodName = model.GoodName,
Price = model.Price,
UserId = model.UserId,
Components = model.GoodComponents.Select(x => new GoodComponent
Components = model.GoodsComponents.Select(x => new GoodComponent
{
Component = context.Components.First(y => y.Id == x.Key),
Count = x.Value.Item2
@ -80,7 +80,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
Price = Price,
UserId = UserId,
UserLogin = User.Login,
GoodComponents = GoodsComponents
GoodsComponents = GoodsComponents
};
public void UpdateComponents(HardwareShopDatabase context, GoodBindingModel model)
@ -91,18 +91,18 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
{ // удалили те, которых нет в модели
context.GoodsComponents
.RemoveRange(goodComponents
.Where(rec => !model.GoodComponents.ContainsKey(rec.ComponentId)));
.Where(rec => !model.GoodsComponents.ContainsKey(rec.ComponentId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateComponent in goodComponents)
{
updateComponent.Count = model.GoodComponents[updateComponent.ComponentId].Item2;
model.GoodComponents.Remove(updateComponent.ComponentId);
updateComponent.Count = model.GoodsComponents[updateComponent.ComponentId].Item2;
model.GoodsComponents.Remove(updateComponent.ComponentId);
}
context.SaveChanges();
}
var good = context.Goods.First(x => x.Id == Id);
foreach (var gc in model.GoodComponents)
foreach (var gc in model.GoodsComponents)
{
context.GoodsComponents.Add(new GoodComponent
{