Esempio n. 1
0
        public Product SelectAProduct()
        {
            Clear();
            Echo("Entrez un id ou un nom de produit : ");
            Input = Console.ReadLine();
            int            id;
            List <Product> products;

            if (int.TryParse(Input, out id))
            {
                var productViewer = new ProductViewer(id);
                AskKeyPress();
                var productRepository = new ProductsRepository();
                return(productRepository.GetProductById(id));
            }
            else
            {
                ProductsRepository productsRepository = new ProductsRepository();
                products = productsRepository.GetProductsByName(Input);

                if (products.Count == 0)
                {
                    Echo("Aucun produit trouvé.");
                    AskKeyPress();
                    return(null);
                }
                else
                {
                    var productBrowser = new ProductBrowser();
                    return(productBrowser.SelectFromListOfProducts(products));
                }
            }
        }
Esempio n. 2
0
        public void SearchProducts()
        {
            Clear();
            Echo("Entrez un id ou un nom de produit : ");
            Input = Console.ReadLine();
            int            id;
            List <Product> products;

            if (int.TryParse(Input, out id))
            {
                var productViewer = new ProductViewer(id);
                AskKeyPress();
            }
            else
            {
                ProductsRepository productsRepository = new ProductsRepository();
                products = productsRepository.GetProductsByName(Input);

                if (products.Count == 0)
                {
                    Echo("Aucun produit trouvé.");
                    AskKeyPress();
                }
                else
                {
                    var productBrowser = new ProductBrowser();
                    productBrowser.BrowseListOfProducts(products);
                }
            }
        }
Esempio n. 3
0
        public bool ValidateProduct(Product product, string date, int quantity)
        {
            var productViewer = new ProductViewer(product);
            var stockViewer   = new StockViewer(date, quantity);

            Echo("\n-------------------");
            Echo("\nConfirmez vous l'enregistrement de ce produit ? [oui/non]");

            return(AskYesNo());
        }
Esempio n. 4
0
        public KeyValuePair <string, object> SelectFromListOfProductsByCategory(List <Product> products)
        {
            ProductViewer productViewer = new ProductViewer();

            int    cursor = 0;
            string entry;

            int cursorMinimum = 0;
            int cursorMaximum = products.Count - 1;

            while (true)
            {
                Clear();
                productViewer.ShowProductProfile(products[cursor]);
                Echo("----------------");
                Echo("Produit " + (cursor + 1) + "/" + (cursorMaximum + 1));
                Echo("[p]récédent, [s]uivant, [c]hoisir, [r]evenir aux catégories, [q]uitter\n");

                entry = AskCommand();

                switch (entry.ToLower())
                {
                case "p":
                case "précédent":
                    if (cursorMinimum < cursor)
                    {
                        cursor = cursor - 1;
                    }
                    break;

                case "s":
                case "suivant":
                    if (cursor < cursorMaximum)
                    {
                        cursor = cursor + 1;
                    }
                    break;

                case "c":
                case "choisir":
                    return(new KeyValuePair <string, object>("product", products[cursor]));

                case "r":
                    return(new KeyValuePair <string, object>("action", "categories"));

                case "q":
                    return(new KeyValuePair <string, object>("action", "quit"));
                }
            }
        }
Esempio n. 5
0
        public Product SelectFromListOfProducts(List <Product> products)
        {
            ProductViewer productViewer = new ProductViewer();

            int    cursor = 0;
            string entry;

            int cursorMinimum = 0;
            int cursorMaximum = products.Count - 1;

            while (true)
            {
                Clear();
                productViewer.ShowProductProfile(products[cursor]);
                Echo("----------------");
                Echo("Produit " + (cursor + 1) + "/" + (cursorMaximum + 1));
                Echo("[p]récédent, [s]uivant, [c]hoisir, [q]uitter\n");

                entry = AskCommand();

                switch (entry)
                {
                case "p":
                case "précédent":
                    if (cursorMinimum < cursor)
                    {
                        cursor = cursor - 1;
                    }
                    break;

                case "s":
                case "suivant":
                    if (cursor < cursorMaximum)
                    {
                        cursor = cursor + 1;
                    }
                    break;

                case "c":
                case "choisir":
                    return(products[cursor]);

                case "q":
                    return(null);
                }
            }
        }
Esempio n. 6
0
        public void BrowseListOfProducts(List <Product> products)
        {
            ProductViewer productViewer = new ProductViewer();

            int    cursor = 0;
            string entry;

            int cursorMinimum = 0;
            int cursorMaximum = products.Count - 1;

            bool isBrowsing = true;

            while (isBrowsing)
            {
                Clear();
                productViewer.ShowProductProfile(products[cursor]);
                Echo("----------------");
                Echo("Produit " + (cursor + 1) + "/" + (cursorMaximum + 1));
                Echo("[p]récédent, [s]uivant, [q]uitter\n");

                entry = AskCommand();

                switch (entry.ToLower())
                {
                case "p":
                case "précédent":
                    if (cursorMinimum < cursor)
                    {
                        cursor = cursor - 1;
                    }
                    break;

                case "s":
                case "suivant":
                    if (cursor < cursorMaximum)
                    {
                        cursor = cursor + 1;
                    }
                    break;

                case "q":
                    isBrowsing = false;
                    break;
                }
            }
        }
Esempio n. 7
0
        public void DebugShowProduct()
        {
            var productViewer = new ProductViewer(5);

            AskKeyPress();
        }