Beispiel #1
0
        public void TestCreateBillBL()
        {
            //Pass
            BillBL billBL = new BillBL();
            Bill   bill   = new Bill()
            {
                App       = ApplicationDAL.GetApplicationById(6),
                User      = UserDAL.GetUserById(2),
                UnitPrice = ApplicationDAL.GetApplicationById(6).Price
            };

            Assert.True(billBL.CreateBill(bill));

            //fail
            //this app not exist!
            Bill bill2 = new Bill()
            {
                App       = ApplicationDAL.GetApplicationById(10000),
                User      = UserDAL.GetUserById(2),
                UnitPrice = ApplicationDAL.GetApplicationById(1).Price
            };

            Assert.False(billBL.CreateBill(bill2));

            //this user not exists!
            bill = new Bill()
            {
                App       = ApplicationDAL.GetApplicationById(8),
                User      = UserDAL.GetUserById(200000),
                UnitPrice = ApplicationDAL.GetApplicationById(8).Price
            };
            Assert.False(billBL.CreateBill(bill));

            //this user has bought this app!
            bill = new Bill()
            {
                App       = ApplicationDAL.GetApplicationById(1),
                User      = UserDAL.GetUserById(1),
                UnitPrice = ApplicationDAL.GetApplicationById(1).Price
            };
            Assert.False(billBL.CreateBill(bill));
        }
Beispiel #2
0
    void BuyApp(Application app)
    {
        while (true)
        {
            bool isExit = false;
            int  ichoice;
            Console.Clear();
            Console.WriteLine("===Buy Application===");
            Console.WriteLine($"Application Name : {app.Name}");
            Console.WriteLine($"Pay:             : {app.Price} VND");
            Console.WriteLine("Payment Method:\n");
            userOnline.ListPayment = PaymentBl.GetPayments(userOnline.User_ID);
            for (int i = 0; i < userOnline.ListPayment.Count; i++)
            {
                int p = i + 1;
                Console.WriteLine(p + ". " + userOnline.ListPayment[i].Name);
            }

            Console.WriteLine("0. Return");
            Console.Write("#Choice: ");
            string schoice = Console.ReadLine();
            if (schoice == "0")
            {
                isExit = true;
            }
            else if (int.TryParse(schoice, out ichoice))
            {
                if (ichoice >= 1 && ichoice <= userOnline.ListPayment.Count)
                {
                    Console.Clear();
                    if (userOnline.ListPayment[ichoice - 1].Name == "By Store")
                    {
                        if (PaymentBl.CheckPayment(userOnline.ListPayment[ichoice - 1], app.Price))
                        {
                            Console.Write("We are checkking payment account...");
                            Bill bill = new Bill()
                            {
                                App       = app,
                                User      = userOnline,
                                Payment   = userOnline.ListPayment[ichoice - 1],
                                UnitPrice = app.Price
                            };
                            try
                            {
                                bool checkCreate = BillBl.CreateBill(bill);
                                if (checkCreate)
                                {
                                    Console.Clear();
                                    Console.WriteLine($"Buy {app.Name} !\nSuccessful\n\nPress anykey to return...");
                                    Console.ReadKey();
                                    isExit = true;
                                }
                            }
                            catch
                            {
                                Console.Clear();
                                Console.WriteLine("Not Successful\n\nPress anykey to return...");
                                Console.ReadKey();
                            }
                        }
                        else
                        {
                            Console.Clear();
                            Console.WriteLine("Not Successful\n\nPress anykey to return...");
                            Console.ReadKey();
                        }
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("This payment havent been updated!\n\nPress anykey to return...");
                        Console.ReadKey();
                    }
                }
            }

            if (isExit == true)
            {
                break;
            }
        }
    }