Exemplo n.º 1
0
        public void DisplayProducts()
        {
            Console.WriteLine("Chargement...");
            ProductsRepository productsRepository = new ProductsRepository();
            var listProduct = productsRepository.GetAllProducts();

            Clear();
            Echo("Liste des produits : \n");

            PrintTableHeader(true, "Id", "CategoryId", "Name", "Description", "Price", "Stock", "Date d'expiration");
            foreach (Product aProduct in listProduct)
            {
                StocksRepository stocksRepository = new StocksRepository();
                var stockOfProduct = stocksRepository.GetStockByProductId(aProduct.Id);
                var dateTime       = stocksRepository.ConvertTimeStampToStringDate(stockOfProduct.Expiry);

                PrintLineCells(true, $"{aProduct.Id}", $"{aProduct.CategoryId}", aProduct.Name, aProduct.Description, $"{aProduct.Price}", $"{stockOfProduct.Quantity}", dateTime);
            }
            Echo(PrintLine());
        }
Exemplo n.º 2
0
        public SearchShortDates()
        {
            Clear();

            string dateSearch         = AskForDate();
            bool   isProductValidated = ValidateProduct(dateSearch);

            if (isProductValidated)
            {
                Clear();
                Echo("Liste des produits dont la date de consommation se terminant avant ou le " + dateSearch + " : \n");
                PrintTableHeader(true, "Id", "Name", "Prix", "Stock", "Date d'expiration");

                StocksRepository   stocksRepository   = new StocksRepository();
                ProductsRepository productsRepository = new ProductsRepository();

                var stringDateSearch = stocksRepository.ConvertStringDateToTimeStamp(dateSearch);
                var listProducts     = productsRepository.GetAllProducts();

                foreach (Product aProduct in listProducts)
                {
                    var stockProduct = stocksRepository.GetStockByProductId(aProduct.Id);
                    var stringExpiry = stocksRepository.ConvertTimeStampToStringDate(stockProduct.Expiry);
                    int result       = stringDateSearch.CompareTo(stockProduct.Expiry);

                    if (result >= 0)
                    {
                        PrintLineCells(true, $"{aProduct.Id}", aProduct.Name, $"{aProduct.Price}", $"{stockProduct.Quantity}", stringExpiry);
                    }
                    else
                    {
                    }
                }
                Echo(PrintLine());
                WaitForKeyPress();
            }
        }