Exemplo n.º 1
0
        public Basket AddUpdateBasket(string user, string productId, int quantity)
        {
            CatalogRepository catalogRepository = new CatalogRepository();
            Basket            basket            = baskets.FirstOrDefault(item => item.User == user);

            if (basket == null)
            {
                throw new Exception("Basket not available");
            }
            Catalog.Models.ProductQty product = basket.Products.FirstOrDefault(p => p.ProductId == productId);
            if (product == null)
            {
                Catalog.Models.Catalog catalog = catalogRepository.GetCatalogs(productId);
                ProductQty             p       = new ProductQty();
                p.ProductId = catalog.Id;
                p.Quantity  = quantity;
                basket.Products.Add(p);
            }
            else
            {
                basket.Products.Remove(product);
                product.ProductId = productId;
                product.Quantity  = quantity;
                basket.Products.Add(product);
            }

            return(basket);
        }
Exemplo n.º 2
0
        public bool RemoveProduct(string user, string productId)
        {
            CatalogRepository catalogRepository = new CatalogRepository();
            Basket            basket            = baskets.FirstOrDefault(item => item.User == user);

            if (basket == null)
            {
                throw new Exception("Basket not available");
            }
            Catalog.Models.ProductQty product = basket.Products.FirstOrDefault(p => p.ProductId == productId);
            if (product == null)
            {
                throw new Exception("Product not available in basket");
            }
            else
            {
                basket.Products.Remove(product);
            }
            return(true);
        }