Esempio n. 1
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;
            }
        }
    }