public async Task <ActionResult> Quantity() { var result = await _mediator.Send(CartQuantityQuery.Create()); var obj = new { quantity = result }; return(Json(obj, JsonRequestBehavior.AllowGet)); }
public async Task <int> Handle(CartQuantityQuery request, CancellationToken cancellationToken) { var cart = _cartFactory.LoadOrCreateCart(); if (cart == null) { return(await Task.FromResult(0)); } var quantity = cart.GetAllLineItems().Sum(x => x.Quantity); return(await Task.FromResult(Convert.ToInt32(quantity))); }