Example #1
0
        public bool AddToShoppingCart(Domain.DTO.AddToShoppingCartDto item, string userID)
        {
            var user = this._userRepository.Get(userID);

            var userShoppingCart = user.UserCart;

            if (item.selectedProductId != null && userShoppingCart != null)
            {
                var product = this.GetDetailsForProduct(item.selectedProductId);

                if (product != null)
                {
                    ProductInShoppingCart itemToAdd = new ProductInShoppingCart
                    {
                        Id             = Guid.NewGuid(),
                        product        = product,
                        ProductId      = product.Id,
                        cart           = userShoppingCart,
                        ShoppingCartId = userShoppingCart.Id,
                        Qantity        = item.quantity
                    };

                    this._productInShoppingCartRepository.Insert(itemToAdd);
                    _logger.LogInformation("Product was succesfully added into Shopping Cart.");
                    return(true);
                }
                return(false);
            }
            _logger.LogInformation("Something went wrong.");
            return(false);
        }
Example #2
0
        public Domain.DTO.AddToShoppingCartDto GetShoppingCartInfo(Guid?id)
        {
            var product = this.GetDetailsForProduct(id);

            Domain.DTO.AddToShoppingCartDto model = new Domain.DTO.AddToShoppingCartDto
            {
                selectedProduct   = product,
                selectedProductId = product.Id,
                quantity          = 1
            };
            return(model);
        }