public Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                var shoppingCart = _eventStore.Load <ShoppingCart>(request.ShoppingCartId);

                if (shoppingCart == null)
                {
                    shoppingCart = new ShoppingCart(request.CurrentUserId, _dateTime.UtcNow);
                }

                if (shoppingCart.Status != ShoppingCartStatus.Shopping)
                {
                    throw new Exception();
                }

                if (shoppingCart != null && shoppingCart.Version != request.Version)
                {
                    throw new ConcurrencyException();
                }

                shoppingCart.AddShoppingCartItem(request.ProductId);

                _eventStore.Save(shoppingCart);

                return(Task.FromResult(new Response()
                {
                    ShoppingCart = ShoppingCartDto.FromShoppingCart(shoppingCart)
                }));
            }
Esempio n. 2
0
 public Task <Response> Handle(Request request, CancellationToken cancellationToken)
 {
     return(Task.FromResult(new Response()
     {
         ShoppingCart = ShoppingCartDto.FromShoppingCart(_repository.Query <ShoppingCart>(request.ShoppingCartId))
     }));
 }
Esempio n. 3
0
            public Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                var shoppingCart = new ShoppingCart(request.CurrentUserId, _dateTime.UtcNow);

                _eventStore.Save(shoppingCart);

                return(Task.FromResult(new Response()
                {
                    ShoppingCart = ShoppingCartDto.FromShoppingCart(shoppingCart)
                }));
            }
            public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                var shoppingCart = _repository.Query <ShoppingCart>()
                                   .SingleOrDefault(x => x.UserId == request.CurrentUserId && x.Status == ShoppingCartStatus.Shopping);

                if (shoppingCart != null)
                {
                    return new Response()
                           {
                               ShoppingCart = ShoppingCartDto.FromShoppingCart(shoppingCart)
                           }
                }
                ;

                return(new Response()
                {
                });
            }
        }
 public Task <Response> Handle(Request request, CancellationToken cancellationToken)
 => Task.FromResult(new Response()
 {
     ShoppingCarts = _repository.Query <ShoppingCart>().Select(x => ShoppingCartDto.FromShoppingCart(x)).ToList()
 });