Example #1
0
        /// <summary>
        ///  Function for handling bids made
        /// </summary>
        ///  <remarks>
        ///  This function allows Buyers to make bids on auctions
        /// </remarks>
        ///
        public void makeBid()
        {
            //firstly check if a user is logged in
            if (tcurrent == null)
            {
                Console.WriteLine("Please Log In to make a bid.");
            }
            //display bidding options if user is logged in and is of type buyer

            else if (tcurrent.isLoggedIn() == true && tcurrent.GetType() == typeof(Buyer))
            {
                Console.WriteLine("Would you like to make a bid?(enter y or n)");
                string answer = Console.ReadLine();
                if (answer != "y")
                {
                    return;
                }

                Console.WriteLine("Which auction would you like to bid on(enter auction number):");
                int choice = int.Parse(Console.ReadLine());

                // loop through the auctions to find the auction we want to bid on
                foreach (Auction auc in Auctions)
                {
                    if (choice == auc.getID())
                    {
                        double bid;
                        Console.WriteLine("How much would you like to bid: ");
                        string s_bid = Console.ReadLine();

                        if (!double.TryParse(s_bid, out bid))
                        {
                            Console.WriteLine("Please enter correct data type.");
                        }

                        //double bid = double.Parse(Console.ReadLine());
                        DateTime ctime = DateTime.Now;

                        //create a new bid object with its new constructor details
                        Bid tbid = new Bid(bid, (Buyer)tcurrent, ctime);

                        if (DateTime.Now > auc.getCloseDate())
                        {
                            auc.setIsRunning(false);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Auction closed");
                        }
                        // checking bid is with 10% and 20% limit constraints
                        if (tbid.getAmount() > auc.getCurrentPrice() && tbid.getAmount() < (auc.getCurrentPrice() + auc.getCurrentPrice() / 100 * 20) &&
                            auc.getIsRunning() == true)
                        {
                            tcurrent.addBid(tbid);                           // add bid to buyer
                            auc.placeBid(tbid, bid, (Buyer)tcurrent, ctime); // add bid to auctions bids list

                            Console.WriteLine("Bid : {0}", tbid.getAmount());
                            auc.setCurrentPrice(bid);
                            auc.setBuyer((Buyer)tcurrent);
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Bid too small or big!");
                        }
                    }
                }
            }
        }
        //--------------------PUBLIC METHODS------------------------------

        public void addBid(Bid nbid)
        {
            tbids.Add(nbid);
        }