Пример #1
0
        //Loading products from CSV and storing them to LIST
        public static List <Product> LoadProductList(string filename)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentNullException(nameof(filename));
            }

            var fileRows = File.ReadAllLines(filename);

            foreach (var s in fileRows)
            {
                if (string.IsNullOrWhiteSpace(s))
                {
                    throw new ArgumentNullException(nameof(s));
                }
            }

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

            for (var i = 0; i < fileRows.Length; i++)
            {
                var rowSplit = fileRows[i].Split(';');
                ListOfProducts.Add(new Product(rowSplit[0], rowSplit[1]));
            }

            ListOfProducts = ListOfProducts.Distinct(new ProductComparer()).ToList();

            PrintingMessages.PrintMsg("PRODUCT LIST");

            for (var i = 0; i < ListOfProducts.Count; i++)
            {
                Console.WriteLine($" ID: {ListOfProducts[i].ProductId}, Price: {ListOfProducts[i].ProductPrice} Euros ");
            }
            return(ListOfProducts);
        }
Пример #2
0
        //Get a list of products and select "num " of them and and return them as newList
        public static List <Product> MakeRandomList(List <Product> list1, int num)
        {
            if (list1 == null)
            {
                throw new ArgumentNullException("The list parameter is null");
            }

            if (num < 0 || num > list1.Count())
            {
                throw new ArgumentException("The num you provided is either greater than list's size or negative");
            }

            Random randomItem = new Random();
            var    newList    = new List <Product>();

            PrintingMessages.PrintMsg("CUSTOMERS'S LIST");

            for (var i = 0; i < num; i++)
            {
                newList.Add(list1[randomItem.Next(0, list1.Count)]);
                Console.WriteLine($"The product {newList[i].ProductId} costs {newList[i].ProductPrice} Euros");
            }

            return(newList);
        }
Пример #3
0
        //Printing 10 most popular products
        public static void FindPopularProducts(List <Product> list1, List <Product> list2, int num)
        {
            if (list1 == null)
            {
                throw new ArgumentNullException($" The {list1} parameter is null ");
            }

            if (list2 == null)
            {
                throw new ArgumentNullException($" The {list2} parameter is null ");
            }

            var newList = new List <Product>();

            newList = list1.Concat(list2).ToList();

            PrintingMessages.PrintMsg(" PRODUCTS FROM EVERY ORDER ");
            for (var i = 0; i < newList.Count; i++)
            {
                Console.WriteLine($" {newList[i].ProductId}");
            }

            var popularList = (newList.GroupBy(p => p.ProductId).OrderByDescending(grp => grp.Count())).ToList();

            PrintingMessages.PrintMsg(" POPULAR PRODUCTS ");
            for (var i = 0; i < num; i++)
            {
                Console.WriteLine($" {popularList[i].Key}");
            }
        }
Пример #4
0
 //Finds the best customer comparing the total costs from every order
 public static void BestCustomer(Customer customer1, Customer customer2)
 {
     PrintingMessages.PrintMsg("BEST CUSTOMER");
     if (customer1 == customer2)
     {
         Console.WriteLine($"{customer1} and {customer2} spent the same amount");
     }
     else if (customer1 < customer2)
     {
         Console.WriteLine($"{customer2.LastName} spent {customer2.FinalCost} Euros");
     }
     else
     {
         Console.WriteLine($"{customer1.LastName} spent {customer1.FinalCost} Euros");
     }
 }
Пример #5
0
        public Order(List <Product> productList)
        {
            if (productList == null)
            {
                throw new ArgumentNullException("The list parameter is null");
            }

            TotalAmount = 0;
            Products    = new List <Product>(productList);

            for (var i = 0; i < Products.Count; i++)
            {
                TotalAmount = TotalAmount + Products[i].ProductPrice;
            }

            PrintingMessages.PrintMsg("The cost of the order is:");
            Console.WriteLine($"{TotalAmount} Euros");
        }