You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
703 B
26 lines
703 B
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
|
|
|
namespace Microsoft.eShopWeb.Infrastructure.Data;
|
|
|
|
public class BasketQueryService : IBasketQueryService
|
|
{
|
|
private readonly CatalogContext _dbContext;
|
|
|
|
public BasketQueryService(CatalogContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
public async Task<int> CountTotalBasketItems(string username)
|
|
{
|
|
var totalItems = await _dbContext.Baskets
|
|
.Where(basket => basket.BuyerId == username)
|
|
.SelectMany(item => item.Items)
|
|
.SumAsync(sum => sum.Quantity);
|
|
|
|
return totalItems;
|
|
}
|
|
}
|
|
|