Put one Method to Count all ShoppingListsRecipe

This commit is contained in:
franc
2025-04-15 16:20:08 +02:00
parent f64f1bf1ee
commit 84c75098cf
3 changed files with 29 additions and 2 deletions
@@ -49,8 +49,6 @@
<Folder Include="Services\Category\" />
<Folder Include="Services\MediaFile\" />
<Folder Include="Services\Ingredient\" />
<Folder Include="Services\Instruction\" />
<Folder Include="Services\ShoppingList\" />
<Folder Include="Services\Recipe\" />
</ItemGroup>
@@ -0,0 +1,7 @@
namespace Francesco.Recipes.World.Services.ShoppingList
{
public interface IShoppingListService
{
Task<int> GetShoppingListRecipeCountAsync(Guid shoppingListId);
}
}
@@ -0,0 +1,22 @@
using Francesco.Recipes.World.Data;
using Microsoft.EntityFrameworkCore;
namespace Francesco.Recipes.World.Services.ShoppingList
{
public class ShoppingListService
{
private readonly FrancescosRecipesWorldDbContext _context;
public ShoppingListService(FrancescosRecipesWorldDbContext context)
{
_context = context;
}
public async Task<int> GetShoppingListRecipeCountAsync(Guid shoppingListId)
{
return await _context.RecipeShoppingLists
.Where(rsl => rsl.ShoppingList.Id == shoppingListId)
.CountAsync();
}
}
}