public void OnAddProduct(object source, EventProduct e)
        {
            LittleGuy littleGuy = (LittleGuy)source;

            foreach (Product product in littleGuy.ShopList)
            {
                if (product.Name == e.Product.Name)
                {
                    if (product.Stock == 0)
                    {
                        littleGuy.RemoveProduct(e.Product);
                        Console.WriteLine("Producto no permitido");
                        Thread.Sleep(3000);
                    }
                    else
                    {
                        int cont = 0;
                        foreach (Product cartProduct in littleGuy.Cart.Products)
                        {
                            if (cartProduct.Name == e.Product.Name)
                            {
                                cont++;
                            }
                        }
                        if (cont >= 2)
                        {
                            littleGuy.RemoveProduct(e.Product);
                            Console.WriteLine("Producto repetido");
                            Thread.Sleep(3000);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void OnLittleGuyTookProduct(object source, LittleGuyProductEventArgs args)
        {
            Console.WriteLine("\nBig Sister says: Hey! Estas agregando algo al carrito");
            Console.WriteLine($"Big Sister says: Acabas de agregar {args.cart.Products[args.cart.Products.Count - 1].Name}");
            Thread.Sleep(3000);
            Product        productoAgregado = args.cart.Products[args.cart.Products.Count - 1];
            LittleGuy      guy      = (LittleGuy)source;
            List <Product> ShopList = (List <Product>)guy.ShopList;

            foreach (Product product in ShopList)
            {
                if (product.Name == productoAgregado.Name)
                {
                    Console.WriteLine(product.Stock);
                    if (product.Stock == 1)
                    {
                        product.Stock -= 1;
                        Console.WriteLine("Big Sister says: It is necessary...");
                        Thread.Sleep(3000);
                        break;
                    }
                    else
                    {
                        guy.RemoveProduct(productoAgregado);
                        Console.WriteLine("Big Sister says: You cant buy that product!");
                        Thread.Sleep(3000);
                    }
                }
            }
        }
        public void OnProductAdded(object source, Product product) // no se si puse algo mal, pero creo que nunca entra a este metodo
        {                                                          // cuando agrrego algo al carro no imprime nada de OnProductAdded
            Console.WriteLine("Product added");                    // no pude solucionarlo.
            LittleGuy littleGuy = (LittleGuy)source;

            Console.WriteLine(product.Name);
            if (recipe.Contains(product.Name))
            {
                Console.WriteLine("consolewriteline test");
                items.Add(product);
            }
            else
            {
                Console.WriteLine("That's not in the list littleguy");
                littleGuy.RemoveProduct(product);
            }
        }