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