Третья усложнённая лабораторная работа. Фикс комита операции.
This commit is contained in:
parent
41e2b23042
commit
904ba78dde
@ -4,6 +4,7 @@ using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryDataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Transactions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -126,8 +127,7 @@ namespace ConfectioneryDataBaseImplement.Implements
|
||||
shop.ShopPastries.Add(pastryId, (pastry, count));
|
||||
}
|
||||
shop.RemapPastries(context);
|
||||
transaction.Commit();
|
||||
return true;
|
||||
count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -136,18 +136,23 @@ namespace ConfectioneryDataBaseImplement.Implements
|
||||
if (shop.ShopPastries.TryGetValue(pastryId, out var pastryCount))
|
||||
{
|
||||
var shopPastry = shop.ShopPastries[pastryId];
|
||||
shopPastry.Item2 = pastryCount.Item2 + count;
|
||||
shopPastry.Item2 = pastryCount.Item2 + freeShopSpace;
|
||||
shop.ShopPastries[pastryId] = shopPastry;
|
||||
}
|
||||
else
|
||||
{
|
||||
Pastry pastry = context.Pastrys.First(x => x.Id == pastryId);
|
||||
shop.ShopPastries.Add(pastryId, (pastry, count));
|
||||
shop.ShopPastries.Add(pastryId, (pastry, freeShopSpace));
|
||||
}
|
||||
shop.RemapPastries(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
|
@ -67,8 +67,9 @@ namespace ConfectioneryDataBaseImplement.Models
|
||||
|
||||
public void UpdatePastries(ConfectioneryDatabase context, ShopBindingModel model)
|
||||
{
|
||||
var list = context.ShopPastries.ToList();
|
||||
var shopPastries = context.ShopPastries.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
if (shopPastries != null && shopPastries.Count > 0)
|
||||
if (shopPastries != null)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.ShopPastries.RemoveRange(shopPastries.Where(rec => !model.ShopPastries.ContainsKey(rec.PastryId)));
|
||||
|
Loading…
Reference in New Issue
Block a user