fix
This commit is contained in:
parent
03d8c6db0a
commit
cf82bd4fe7
@ -12,7 +12,7 @@ namespace HardwareShopContracts.BindingModels
|
|||||||
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (IComponentModel, int)> GoodComponents
|
public Dictionary<int, (IComponentModel, int)> GoodsComponents
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
@ -55,7 +55,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
|||||||
GoodName = model.GoodName,
|
GoodName = model.GoodName,
|
||||||
Price = model.Price,
|
Price = model.Price,
|
||||||
UserId = model.UserId,
|
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),
|
Component = context.Components.First(y => y.Id == x.Key),
|
||||||
Count = x.Value.Item2
|
Count = x.Value.Item2
|
||||||
@ -80,7 +80,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
|||||||
Price = Price,
|
Price = Price,
|
||||||
UserId = UserId,
|
UserId = UserId,
|
||||||
UserLogin = User.Login,
|
UserLogin = User.Login,
|
||||||
GoodComponents = GoodsComponents
|
GoodsComponents = GoodsComponents
|
||||||
};
|
};
|
||||||
|
|
||||||
public void UpdateComponents(HardwareShopDatabase context, GoodBindingModel model)
|
public void UpdateComponents(HardwareShopDatabase context, GoodBindingModel model)
|
||||||
@ -91,18 +91,18 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
|||||||
{ // удалили те, которых нет в модели
|
{ // удалили те, которых нет в модели
|
||||||
context.GoodsComponents
|
context.GoodsComponents
|
||||||
.RemoveRange(goodComponents
|
.RemoveRange(goodComponents
|
||||||
.Where(rec => !model.GoodComponents.ContainsKey(rec.ComponentId)));
|
.Where(rec => !model.GoodsComponents.ContainsKey(rec.ComponentId)));
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
// обновили количество у существующих записей
|
// обновили количество у существующих записей
|
||||||
foreach (var updateComponent in goodComponents)
|
foreach (var updateComponent in goodComponents)
|
||||||
{
|
{
|
||||||
updateComponent.Count = model.GoodComponents[updateComponent.ComponentId].Item2;
|
updateComponent.Count = model.GoodsComponents[updateComponent.ComponentId].Item2;
|
||||||
model.GoodComponents.Remove(updateComponent.ComponentId);
|
model.GoodsComponents.Remove(updateComponent.ComponentId);
|
||||||
}
|
}
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
var good = context.Goods.First(x => x.Id == Id);
|
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
|
context.GoodsComponents.Add(new GoodComponent
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user