Example #1
0
        // Devuelve una lista con los productos que tienen algún tipo de descuento
        private static List <RecProduct> generateListOfPromotionalProducts(List <Product> products)
        {
            List <RecProduct> promotional = new List <RecProduct>();

            foreach (Product product in products)
            {
                if (product.Discount > 0)
                {
                    RecProduct recP = new RecProduct(product.Name, product.Category);
                    recP.Discount       = product.Discount;
                    recP.DiscountedUnit = product.DiscountedUnit;
                    promotional.Add(recP);
                }
            }
            return(promotional);
        }
Example #2
0
        // Devuelve una lista con los productos consumidos por el cliente y el número de veces de cada uno
        private static List <RecProduct> generateListOfUsualProducts(List <Product> products, List <HistoricalOrder> clientHistory)
        {
            List <RecProduct> usual = new List <RecProduct>();

            foreach (HistoricalOrder order in clientHistory)
            {
                int i = usual.IndexOf(new RecProduct(order.Product));
                if (i == -1)
                {
                    RecProduct rp = new RecProduct(order.Product);
                    rp.Times = order.Amount;
                    usual.Add(rp);
                }
                else
                {
                    usual[i].Times += order.Amount;
                }
            }
            for (int i = 0; i < usual.Count; i++)
            {
                int j = products.IndexOf(new Product(usual[i].Name));
                if (j == -1)
                {
                    usual.RemoveAt(i); i--;
                }
                else
                {
                    if (!products[j].Visible)
                    {
                        usual.RemoveAt(i); i--;
                    }
                    else
                    {
                        usual[i].Category       = products[j].Category;
                        usual[i].Discount       = products[j].Discount;
                        usual[i].DiscountedUnit = products[j].DiscountedUnit;
                        usual[i].Description    = products[j].Description;
                    }
                }
            }
            return(usual);
        }