示例#1
0
        public bool AcceptBid(Seller inputSeller, Buyer inputBuyer, int auctionNo)
        {
            if(ForSale.ContainsKey(auctionNo) && inputSeller == ForSale[auctionNo].VehicleSeller) {
                int key = inputBuyer.GetHashCode();
                int fee = 0;
                //The chosen biders balance is reduced and all the bidders reserved balance is decreased
                inputBuyer.Balance -= ForSale[auctionNo].Bids[key];
                foreach(Buyer b in ForSale[auctionNo].Biders) {
                    b.ReservedBalance -= ForSale[auctionNo].Bids[b.GetHashCode()];
                }

                if(ForSale[auctionNo].Bids[key] < 10000)
                    fee = 1900;
                else if(ForSale[auctionNo].Bids[key] < 50000)
                    fee = 2250;
                else if(ForSale[auctionNo].Bids[key] < 100000)
                    fee = 2550;
                else if(ForSale[auctionNo].Bids[key] < 150000)
                    fee = 2850;
                else if(ForSale[auctionNo].Bids[key] < 200000)
                    fee = 3400;
                else if(ForSale[auctionNo].Bids[key] < 300000)
                    fee = 3700;
                else
                    fee = 4400;

                _balance += fee;
                ForSale[auctionNo].VehicleSeller.Balance += ForSale[auctionNo].Bids[key] - fee;
                Sold.Add(ForSale[auctionNo]);
                ForSale.Remove(auctionNo);
                return true;
            }
            return false;
        }
示例#2
0
 public bool RecieveBid(Buyer b, int auctionNo, decimal bid)
 {
     //If the list contains the car and the balance can be reserved
     if(ForSale.ContainsKey(auctionNo) && b.reserveBalance(bid, auctionNo, this)) {
         //If the car does not have any bids and the bid is higher then the minimum price or if there are bids and the new bid is higher
         if((!ForSale[auctionNo].Bids.Any() && ForSale[auctionNo].MinPrice <= bid)
             || (ForSale[auctionNo].MinPrice <= bid && ForSale[auctionNo].Bids.Max(x => x.Value) < bid)) {
             ForSale[auctionNo].notify(ForSale[auctionNo], bid);
         }
         //If the bids already contains the buyer the bid is changed else the buyer and bid is added
         if(ForSale[auctionNo].Bids.ContainsKey(b.GetHashCode())) {
             ForSale[auctionNo].Bids[b.GetHashCode()] = bid;
         } else {
             ForSale[auctionNo].Bids.Add(b.GetHashCode(), bid);
             ForSale[auctionNo].Biders.Add(b);
         }
         return true;
     }
     return false;
 }