Exemplo n.º 1
0
        string IProduct.DeleteRow(int id)
        {
            UserLog.Log("Function DELETE item called; ");
            string  deletedRow = "";
            int     ix         = 0;
            Product item       = Filler.GetRowFromList(id);

            deletedRow = item.ProductName + " " + item.Description + " " + item.ProductType + " " + item.CurrentPrice;
            Console.WriteLine("Row to be deleted: " + deletedRow);

            Filler.DeleteRowFromList(id);
            Console.WriteLine("Updated list of products: ");
            foreach (Product product in Filler.products)
            {
                Console.WriteLine(ix + ") " + product.ProductName + " " + product.Description + " " + product.ProductType + " " + product.CurrentPrice);
                ix++;
            }
            return(deletedRow);
        }
Exemplo n.º 2
0
        string IProduct.Read(string productType)
        {
            UserLog.Log("Function READ item called; ");
            string selectedData = "";

            if (String.IsNullOrEmpty(productType))
            {
                throw new ArgumentException("Product Type can't be null or empty.");
            }

            // Filler.AddSetOfProduct();

            foreach (Product product in Filler.products)
            {
                if (product.ProductType == productType)
                {
                    // selectedList.AddRange(new Product() { ProductName = product.ProductName, Description = product.Description, ProductType = product.ProductType, CurrentPrice = product.CurrentPrice });
                    selectedData += (product.ProductName + " " + product.Description + " " + product.ProductType + " " + product.CurrentPrice + System.Environment.NewLine);
                }
            }
            return(selectedData);
        }
Exemplo n.º 3
0
        public string ReadProduct(string typeOfProduct)
        {
            UserLog.Log("Function READ warehouse item called; ");
            string              productinfo = "";
            List <Juice>        resultsJ    = juiceList.FindAll(s => s.ProductType.Equals(typeOfProduct));
            List <SoftDrink>    resultsS    = softdrink.FindAll(s => s.ProductType.Equals(typeOfProduct));
            List <MineralWater> resultsM    = minwater.FindAll(s => s.ProductType.Equals(typeOfProduct));

            if (resultsJ.Count != 0)
            {
                foreach (var findProduct in resultsJ)
                {
                    Console.WriteLine(findProduct);
                }
            }
            else if (resultsS.Count != 0)
            {
                foreach (var findProduct in resultsS)
                {
                    Console.WriteLine(findProduct);
                }
            }
            else if (resultsM.Count != 0)
            {
                foreach (var findProduct in resultsM)
                {
                    Console.WriteLine(findProduct);
                }
            }
            else
            {
                Console.WriteLine("\nNo requested to read product found.");
            }

            return(productinfo);
        }
Exemplo n.º 4
0
        public string UpdateProduct(string typeOfProduct, string productName)
        {
            UserLog.Log("Function UPDATE warehouse item called; ");
            string updatedproduct = "";

            switch (typeOfProduct)
            {
            case "Soft Drink":
                var softDrinkToUpdate = softdrink.Where(s => s.SoftDrinkName == productName).FirstOrDefault();
                if (softDrinkToUpdate != null)
                {
                    softDrinkToUpdate.SoftDrinkName = "some value";
                }
                Console.WriteLine(softDrinkToUpdate);
                break;

            case "Juice":
                var juiceToUpdate = juiceList.Where(j => j.JuiceName == productName).FirstOrDefault();
                if (juiceToUpdate != null)
                {
                    juiceToUpdate.JuiceName = "some value";
                }
                Console.WriteLine(juiceToUpdate);
                break;

            case "Mineral Water":
                var minwaterToUpdate = minwater.Where(m => m.MinWaterName == productName).FirstOrDefault();
                if (minwaterToUpdate != null)
                {
                    minwaterToUpdate.MinWaterName = "some value";
                }
                Console.WriteLine(minwaterToUpdate);
                break;
            }
            return(updatedproduct);
        }
Exemplo n.º 5
0
        string IProduct.Create(string productName, string productType, string description, string currentPrice)
        {
            UserLog.Log("Function CREATE item called; ");
            string   newrow      = " ";
            bool     checkIsFail = false;
            IProduct iproduct    = new Product();

            if (String.IsNullOrEmpty(productName))
            {
                throw new ArgumentException("Product Name can't be null or empty.");
            }
            if (String.IsNullOrEmpty(productType))
            {
                throw new ArgumentException("Product type can't be null or empty.");
            }
            if (String.IsNullOrEmpty(description))
            {
                throw new ArgumentException("Description can't be null or empty.");
            }
            if (String.IsNullOrEmpty(currentPrice))
            {
                throw new ArgumentException("Price can't be null or empty.");
            }

            if (!EqualsCheck.Validation(productName))
            {
                Console.WriteLine("Please input product name: ");
                productName = Console.ReadLine();
                checkIsFail = true;
            }

            if (!EqualsCheck.NumberValidation(currentPrice))
            {
                Console.WriteLine("Please input product current price: ");
                currentPrice = Console.ReadLine();
                iproduct.Create(productName, productType, description, currentPrice);
                checkIsFail = true;
            }

            if (checkIsFail)
            {
                iproduct.Create(productName, productType, description, currentPrice);
            }
            productType = iproduct.TypeFinder(productType);
            int price = int.Parse(currentPrice);

            if (Filler.products.Capacity < 17)
            {
                Filler.products.Add(new Product()
                {
                    ProductName = productName, Description = description, ProductType = productType, CurrentPrice = price
                });
            }
            else
            {
                Console.WriteLine("There is no space to add new product. Capacity amount has been already reached.");
                Console.ReadKey();
                System.Environment.Exit(-1);
            }
            foreach (Product product in Filler.products)
            {
                newrow += (product.ProductName + " " + product.Description + " " + product.ProductType + " " + product.CurrentPrice + System.Environment.NewLine);
            }
            return(newrow);
        }