public static void BuyProducts(this IClient c, IProduct p, int count, IStore s, bool coins)
 {
     if (!coins)
     {
         c.Money -= p.Price * count;
         for (var i = 0; i < count; i++)
         {
             c.Coins = c.Coins + p.Price * 12.5;
             c.PurchasedProducts.Add(p);
         }
         IOCContainer.Get <IStoreService>().SellProduct(s, c, p, count);
     }
     else
     {
         if (c.Coins > p.Price * 100 * count)
         {
             c.Coins -= p.Price * 100 * count;
         }
         else
         {
             var tmp = p.Price * count;
             tmp     -= c.Coins / 100;
             c.Coins  = 0;
             c.Money -= tmp;
         }
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            IOCContainer.AddAsSingleton <IStoreService>(() => new StoreService());
            var giorgi = new Client()
            {
                Money = 1000
            };

            var Store = new Store();

            giorgi.BuyProducts(new Product()
            {
                Name = "Apple"
            }, 20, Store, false);
            Console.WriteLine(giorgi.Coins + " " + giorgi.Money);
            giorgi.BuyProducts(new Product()
            {
                Name = "Apple"
            }, 20, Store, true);
            Console.WriteLine(giorgi.Coins + " " + giorgi.Money);

            Console.ReadKey();
        }