Ejemplo n.º 1
0
        /// <summary>
        /// Method appele a chaque commande. Elle permet de simuler la gestion des stockes
        /// </summary>
        /// <param name="recipe"></param>
        public static void ManageOrder(Recipe recipe, bool isOrder = false)
        {
            DDB ddB = new DDB(User.DataBase, User.Username, User.Password);

            List <ProductComposition> productCompositions = ddB.SelectProductComposition(new string[] { "nomRecette" }, new string[] { "'" + recipe.Name + "'" });

            List <Product> products = new List <Product>();

            productCompositions.ForEach(p => products.AddRange(ddB.SelectProduct(new string[] { "ref" }, new string[] { "'" + p.RefProduct + "'" })));

            products.ForEach(p => ConsumeProduct(p, productCompositions));

            if (isOrder)
            {
                recipe.Rating++; //equivalent à la notation de la recette à chaque fois que quelqu'un commande on l'incremente
                if (recipe.Rating == 10)
                {
                    recipe.Price += 2;
                }
                if (recipe.Rating == 50)
                {
                    recipe.Price     += 5;
                    recipe.IsTrending = true; //isTrending = true veut dire que la recette a été commandé plus de 50 fois
                }
                ddB.UpdateRecipe(recipe, new string[] { "nom" }, new string[] { $"'{recipe.Name}'" });
                PayingCDR(recipe);
            }

            ddB.Close();
        }