Esempio n. 1
0
        static void checkLab4()
        {
            ShopService logic = new ShopService();

            logic.InitializeDAO("dao2.ini");

            Shop shop1 = logic.AddShop("Пятерочка");
            Shop shop2 = logic.AddShop("Заря");
            Shop shop3 = logic.AddShop("Юнион");

            AProduct prod1 = logic.AddProduct("Шоколадка", "Аленка");
            AProduct prod2 = logic.AddProduct("Молоко", "Простоквашино");
            AProduct prod3 = logic.AddProduct("Колбаса", "Докторская");

            logic.SetProductPrice(shop2, prod2, 60);
            logic.SetProductPrice(shop3, prod2, 55);
            logic.SetProductPrice(shop1, prod1, 40);

            logic.SupplyShop(shop1, prod1, 20);
            logic.SupplyShop(shop3, prod2, 15);

            logic.SetProductPrice(shop3, prod1, 45);
            logic.SetProductPrice(shop1, prod2, 60);

            logic.SupplyShop(shop1, prod2, 10);
            logic.SupplyShop(shop3, prod1, 20);

            var pair = logic.FindCheapest(prod1);

            Console.WriteLine("{0}, {1}, {2}", pair.First.Name, pair.Second.Name, pair.Second.Price.ToString());
            pair = logic.FindCheapest(prod2);
            Console.WriteLine("{0}, {1}, {2}", pair.First.Name, pair.Second.Name, pair.Second.Price.ToString());

            List <AProduct> list = new List <AProduct>();

            list.Add(prod1);
            list.Add(prod2);
            List <int> amounts = new List <int>();

            amounts.Add(15);
            amounts.Add(5);
            check = true;
            logic.BuyProduct(shop1, list, amounts);

            list.RemoveAt(0);
            amounts.RemoveAt(0);
            Console.WriteLine("This {0}", logic.FindCheapestAmount(list, amounts).First.Name);
            logic.SupplyShop(shop1, prod2, 20);
            amounts[0] = 20;
            Console.WriteLine("This {0}", logic.FindCheapestAmount(list, amounts).First.Name);

            DataBase db = logic.GetData();

            logic.InitializeDAO("dao1.ini", db);
        }
Esempio n. 2
0
 public ActionResult BuyProduct(int userId, int id)
 {
     return(Json(shopService.BuyProduct(userId, id), JsonRequestBehavior.AllowGet));
 }