Exemple #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);
        }
        public bool AddToShoppingCart(AddToShoppingCardDto item, string userID)
        {
            var user = this._userRepository.Get(userID);

            var userShoppingCard = user.UserCart;

            if (item.ProductId != null && userShoppingCard != null)
            {
                var product = this.GetDetailsForProduct(item.ProductId);

                if (product != null)
                {
                    ProductInShoppingCart itemToAdd = new ProductInShoppingCart
                    {
                        Id             = Guid.NewGuid(),
                        Product        = product,
                        ProductId      = product.Id,
                        ShoppingCart   = userShoppingCard,
                        ShoppingCartId = userShoppingCard.Id,
                        Quantity       = item.Quantity
                    };

                    this._productInShoppingCartRepository.Insert(itemToAdd);
                    _logger.LogInformation("Product was successfully added into ShoppingCart");
                    return(true);
                }
                return(false);
            }
            _logger.LogInformation("Something was wrong. ProductId or UserShoppingCard may be unaveliable!");
            return(false);
        }