Exemplo n.º 1
0
        private async Task <CartViewModel> CreateCartForUser(string userId)
        {
            var cart = new Cart()
            {
                UserId = userId
            };
            await _cartRepository.AddAsync(cart);

            return(new CartViewModel()
            {
                UserId = cart.UserId,
                Id = cart.Id,
                Items = new List <CartItemViewModel>()
            });
        }
Exemplo n.º 2
0
        public async Task CreateOrderAsync(int cartId, Address shipAddress)
        {
            var cart = await _cartRepository.GetByIdAsync(cartId);

            var items = new List <OrderItem>();

            foreach (var item in cart.Items)
            {
                var catalogItem = await _productRepository.GetByIdAsync(item.CategoryItemId);

                var itemOrdered = new CategoryOrdered(catalogItem.Id, catalogItem.Name);
                var orderItem   = new OrderItem(itemOrdered, item.UnitPrice, item.UnitQuantity);
                items.Add(orderItem);
            }
            var order = new Order(cart.UserId, shipAddress, items);

            await _orderRepository.AddAsync(order);
        }