コード例 #1
0
            public async Task <ShoppingCartDto> Handle(GetCartQuery request, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                Domain.Entities.ShoppingCart?shoppingCart = await applicationDataContext
                                                            .ShoppingCarts
                                                            .AsQueryable()
                                                            .Include(sc => sc.Discounts)
                                                            .FirstAsync();

                System.Collections.Generic.IEnumerable <Domain.Entities.ShoppingCartItem>?shoppingCartItems = applicationDataContext.ShoppingCartItems
                                                                                                              .Include(sci => sci.Product)
                                                                                                              .Include(sci => sci.ProductVariant)
                                                                                                              .AsEnumerable();

                decimal total = 0;

                foreach (Domain.Entities.ShoppingCartItem?item in shoppingCartItems)
                {
                    if (item.ProductVariant != null)
                    {
                        total += await priceService.GetProductPriceAsync(shoppingCart.Discounts, item.ProductVariant) * item.Quantity;
                    }
                    else
                    {
                        total += await priceService.GetProductPriceAsync(shoppingCart.Discounts, item.Product) * item.Quantity;
                    }
                }

                return(new ShoppingCartDto()
                {
                    Items = mapper.ProjectTo <ShoppingCartItemDto>(shoppingCartItems.AsQueryable()),
                    Total = total
                });
            }
コード例 #2
0
 /// <summary>
 /// Applies the cursor pagination algorithm to the <paramref name="enumerable"/>.
 /// </summary>
 /// <param name="enumerable">
 /// The enumerable on which the the cursor pagination algorithm shall be applied to.
 /// </param>
 /// <param name="context">
 /// The field resolver context.
 /// </param>
 /// <param name="defaultPageSize">
 /// The default page size if no boundaries are set.
 /// </param>
 /// <param name="totalCount">
 /// The total count if already known.
 /// </param>
 /// <param name="cancellationToken">
 /// The cancellation token.
 /// </param>
 /// <typeparam name="TEntity">
 /// The entity type.
 /// </typeparam>
 /// <returns>
 /// Returns a connection instance that represents the result of applying the
 /// cursor paging algorithm to the provided <paramref name="enumerable"/>.
 /// </returns>
 public static ValueTask <Connection <TEntity> > ApplyCursorPaginationAsync <TEntity>(
     this System.Collections.Generic.IEnumerable <TEntity> enumerable,
     IResolverContext context,
     int?defaultPageSize = null,
     int?totalCount      = null,
     CancellationToken cancellationToken = default)
 => ApplyCursorPaginationAsync(
     enumerable.AsQueryable(),
     context,
     defaultPageSize,
     totalCount,
     cancellationToken);