public BuyTransaction(User currentUser, Product selectedProduct)
 {
     _transactionID = ++_transactionIDCounter;
     _currentUser = currentUser;
     _date = DateTime.Now;
     _selectedProduct = selectedProduct;
     _amount = selectedProduct.price;
 }
Esempio n. 2
0
 public void BuyProduct(User currentUser, Product chosenProduct)
 {
     BuyTransaction transaction = new BuyTransaction(currentUser, chosenProduct);
     ExecuteTransaction(transaction);
 }
Esempio n. 3
0
        public List<Product> LoadProductList()
        {
            List<Product> productsFound = new List<Product>();
            List<string[]> dataFound = new List<string[]>();
            string path = "products.csv";
            if (!(File.Exists(path)))
            {
                throw new GeneralErrorException("produktfilen er væk");
            }
            else
            {
                using (StreamReader reader = new StreamReader(path, Encoding.Default))
                {
                    reader.ReadLine(); //Smider første linje væk.
                    string line;
                    string[] column;
                    while ((line = reader.ReadLine()) != null)
                    {
                        column = line.Split(';');
                        dataFound.Add(column);
                    }
                }

                foreach (var item in dataFound)
                {
                    Product product = new Product();
                    uint iD;
                    UInt32.TryParse(item[0], out iD);
                    product.productID = iD;
                    product.name = item[1];

                    //De næste 4 if-sætninger fjerner alle uønskede dele fra produktnavnene.
                    if (product.name.Contains("<b>"))
                    {
                        product.name = product.name.Replace("<b>", "");
                        product.name = product.name.Replace("</b>", "");
                    }

                    if (product.name.Contains("<h1>"))
                    {
                        product.name = product.name.Replace("<h1>", "");
                        product.name = product.name.Replace("</h1>", "");
                    }

                    if (product.name.Contains("<h2>"))
                    {
                        product.name = product.name.Replace("<h2>", "");
                        product.name = product.name.Replace("</h2>", "");
                    }

                    if (product.name.Contains("\""))
                    {
                        product.name = product.name.Replace("\"", "");
                    }

                    decimal productPrice;
                    Decimal.TryParse((item[2]), out productPrice);
                    product.price = productPrice / 100; //divideres med 100, da prisen er angivet i ører.

                    switch (item[3])
                    {
                        case "0":
                            product.active = false;
                            break;
                        case "1":
                            product.active = true;
                            break;
                    }

                    productsFound.Add(product);

                    //Delen med deactivate_date ignoreres ved ikke at bearbejde item[4].
                }
            }

            return productsFound;
        }
 public void DisplayUserBuysProduct(string currentUser, int howMany, Product chosenProduct)
 {
     Console.Clear();
     Console.WriteLine("Brugeren {0} har købt {1} af {2}", currentUser, howMany, chosenProduct.name);
 }