Esempio n. 1
0
        //ResolveProxyBiddingSituation
        public void ResolveProxyBiddingSituation(long auction_id, long user_id, bool isproxy, BiddingObject placedBid, BidCurrent lastTop, decimal aprice, List <BidLogCurrent> newbidlogs)
        {
            if (placedBid.Bid == null || placedBid.BidLog == null || lastTop == null)
            {
                return;
            }
            //List<BidCurrent> bids = dataContext.BidCurrents.Where(B => B.Auction_ID == auction_id && B.ID != placedBid.Bid.ID && B.User_ID != user_id).OrderBy(B3 => B3.DateMade).OrderByDescending(B2 => B2.MaxBid).OrderByDescending(B1 => B1.Amount).ToList();
            List <BidCurrent> bids = dataContext.spBid_BidsExceptCurrent(auction_id, placedBid.Bid.ID, user_id).ToList();

            if (bids.Count() == 0)
            {
                return;
            }

            decimal price     = (lastTop == null) ? aprice : lastTop.Amount;
            decimal Increment = Consts.GetIncrement(price);

            BidCurrent queryBid = bids.FirstOrDefault();

            if (placedBid.Bid.IsProxy && placedBid.Bid.Amount <= (queryBid.MaxBid + Consts.ErrorRangeAmount))
            {
                if (queryBid.MaxBid + Increment >= (placedBid.Bid.MaxBid + Consts.ErrorRangeAmount))
                {
                    //Can't overBid
                    placedBid.BidLog.Amount = placedBid.Bid.Amount = placedBid.Bid.MaxBid;
                }
                else
                {
                    Increment = Consts.GetIncrement(queryBid.MaxBid);
                    if (Increment + queryBid.MaxBid + Consts.ErrorRangeAmount > placedBid.Bid.MaxBid)
                    {
                        placedBid.BidLog.Amount = placedBid.Bid.Amount = placedBid.Bid.MaxBid;
                    }
                    else if (placedBid.Bid.User_ID != lastTop.User_ID)
                    {
                        placedBid.BidLog.Amount = placedBid.Bid.Amount = queryBid.MaxBid + Increment;
                    }
                }
            }
            foreach (BidCurrent runner in bids)
            {
                if (!runner.IsProxy)
                {
                    continue;
                }
                if ((runner.MaxBid == placedBid.Bid.MaxBid) || (Math.Abs(runner.MaxBid - placedBid.Bid.MaxBid) < Consts.ErrorRangeAmount))
                {
                    runner.Amount = placedBid.Bid.MaxBid;
                }
                else
                {
                    Increment = Consts.GetIncrement(placedBid.Bid.MaxBid);
                    if (runner.MaxBid >= placedBid.Bid.MaxBid + Increment + Consts.ErrorRangeAmount)
                    {
                        runner.Amount = placedBid.Bid.MaxBid + Increment;
                    }
                    else
                    {
                        if (runner.Amount != runner.MaxBid)
                        {
                            BidLogCurrent log = new BidLogCurrent();
                            dataContext.BidLogCurrents.InsertOnSubmit(log);
                            log.Quantity     = runner.Quantity;
                            log.User_ID      = runner.User_ID;
                            log.IsProxy      = runner.IsProxy;
                            log.MaxBid       = runner.MaxBid;
                            log.Amount       = runner.MaxBid;
                            log.IP           = runner.IP;
                            log.Auction_ID   = runner.Auction_ID;
                            log.DateMade     = DateTime.Now;
                            log.IsProxyRaise = false;
                            newbidlogs.Add(log);
                        }
                        runner.Amount = runner.MaxBid;
                    }
                }
            }
            SubmitChages();
        }