/// <summary> /// If the store is open and there is products for sale a customer buys it. /// </summary> /// <param name="socialSecurityNumber"> /// socialSecurityNumber is a unique identicator for each customer /// </param> /// <param name="name"> /// name the customer who is buying a product /// </param> /// <returns> /// IStatue returns product if transaction was true /// </returns> public IStatue SellProduct(int socialSecurityNumber, string name) { var bank = Bank.BankFlyweight.BankFactory.GetBank("DNB"); lock (ProductsForSale) lock (ProductsSold) { CheckIfStoreShouldClose(); if (StoreIsOpen && ProductsForSale.Count > 0) { var product = ProductsForSale[0]; var price = product.GetPrice(); if (bank.Transaction(price, socialSecurityNumber)) { ProductsSold.Add(product); ProductsForSale.Remove(product); CheckIfStoreShouldClose(); Console.WriteLine("Following product was sold to {0} for {1} kr from {2}.{3}{4}{5}", name, price, Name, System.Environment.NewLine, Client.PrintProduct.SortAndRetrieveProductDescription(product), System.Environment.NewLine); return(product); } Console.WriteLine("{0} tried to buy a product at {1} for {2} kr. Withdrawal rejected. Insufficient funds.{3}", name, Name, price, System.Environment.NewLine); } } return(null); }
/// <summary> /// Makes backroom create a product and adds it to _productsForSale /// </summary> /// <param name="numberOfDecorations"> /// number of times a random decoration should be added to the statue /// </param> private void RecieveProductsForSaleFromBackroom(int numberOfDecorations) { if (ProductsForSale.Count + ProductsSold.Count < Quota) { var result = Backroom.CreateProduct(numberOfDecorations); ProductsForSale.Add(result); } }