Build transaction on Method
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
{
|
||||
using Francesco.Recipes.World.Data;
|
||||
using Francesco.Recipes.World.Models.BackendModels.IngredientShoppingList;
|
||||
using Francesco.Recipes.World.Models.BackendModels.Recipe;
|
||||
using Francesco.Recipes.World.Models.BackendModels.RecipeShoppingList;
|
||||
using Francesco.Recipes.World.Models.BackendModels.Shoppinglist;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -182,6 +181,10 @@
|
||||
throw new ArgumentNullException(nameof(recipeIngredientShoppingListIds));
|
||||
}
|
||||
|
||||
using var transaction = await _context.Database.BeginTransactionAsync();
|
||||
|
||||
try
|
||||
{
|
||||
var affectedRecipeShoppingListIds = await _context.RecipeIngredientsShoppingLists
|
||||
.Where(risl => recipeIngredientShoppingListIds.Contains(risl.Id))
|
||||
.Select(risl => risl.RecipeShoppingList.Id)
|
||||
@@ -203,6 +206,14 @@
|
||||
{
|
||||
await RemoveRecipeIfEmptyAsync(recipeShoppingListId);
|
||||
}
|
||||
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private IQueryable<ShoppingList> GetShoppingListQuery()
|
||||
|
||||
Reference in New Issue
Block a user