public ActionResult PlaceBidTest(long?id)
        {
            if (!id.HasValue) // return RedirectToAction("Category", "Auction");
            {
                id = 65414;
            }
            AuctionDetail auction = AuctionRepository.GetAuctionDetail(id.Value, AppHelper.CurrentUser == null ? -1 : AppHelper.CurrentUser.ID, true);

            if (auction == null)
            {
                return(RedirectToAction("Category", "Auction"));
            }
            BiddingResult br  = BidRepository.CurrentAuctionBiddingResult(id.Value, AppHelper.CurrentUser == null ? -1 : AppHelper.CurrentUser.ID, auction.Price);
            decimal       bid = br.MinBid == 0 ? auction.Price : (br.UsersTopBid == null || br.UsersTopBid.MaxBid < br.MinBid) ? br.MinBid : br.UsersTopBid.MaxBid;

            bid = bid + Consts.GetIncrement(bid);
            return(PlaceBid(auction.LinkParams.ID, false, bid, bid));
        }
Esempio n. 2
0
        //BiddingForSingleAuction
        /// <summary>
        /// Add bid, resolve proxy bidding situation
        /// </summary>
        /// <returns> 0 - winner, 1 - outbidder, 2 - update bid, 3 - wrong bid</returns>
        public byte BiddingForSingleAuction(AuctionDetail auction, BidCurrent currentBid, out BidCurrent previousBid, out BidCurrent loserBid, out BidCurrent winnerBid)
        {
            long?bid_id = -1;

            previousBid = loserBid = winnerBid = null;

            List <BidCurrent> allbids = dataContext.spBid_LotBids(auction.LinkParams.ID).ToList();

            // no bids
            if (!allbids.Any())
            {
                currentBid.Amount = currentBid.IsProxy ? auction.Price : currentBid.MaxBid;
                dataContext.spBid_PlaceBidsForSingleBidding(auction.LinkParams.ID, ref bid_id, currentBid.User_ID, currentBid.Amount,
                                                            currentBid.MaxBid, currentBid.DateMade, currentBid.IP,
                                                            currentBid.IsProxy, false, currentBid.IsActive, null, null, null,
                                                            null, null, null, null, null, null, null, null, currentBid.User_ID,
                                                            currentBid.Amount, currentBid.MaxBid);
                currentBid.ID = bid_id.GetValueOrDefault(-1);
                winnerBid     = new BidCurrent(currentBid);
                return(0);
            }

            previousBid = allbids.FirstOrDefault(q => q.User_ID == currentBid.User_ID);

            // the duplicate
            if (previousBid != null)
            {
                currentBid.ID = previousBid.ID;
                if (previousBid.IsProxy == currentBid.IsProxy && previousBid.MaxBid >= currentBid.Amount)
                {
                    return(3);
                }
            }

            BidCurrent topBid = allbids.First();

            // current is highbidder
            if (topBid.User_ID == currentBid.User_ID)
            {
                currentBid.Amount = (!currentBid.IsProxy && currentBid.Amount > topBid.Amount)
                              ? currentBid.Amount
                              : topBid.Amount;
                currentBid.MaxBid  = Math.Max(currentBid.MaxBid, topBid.MaxBid);
                currentBid.IsProxy = currentBid.Amount <= currentBid.MaxBid;
                bid_id             = topBid.ID;
                dataContext.spBid_PlaceBidsForSingleBidding(auction.LinkParams.ID, ref bid_id, currentBid.User_ID, currentBid.Amount,
                                                            currentBid.MaxBid, currentBid.DateMade, currentBid.IP,
                                                            currentBid.IsProxy, true, currentBid.IsActive, null, null, null,
                                                            null, null, null, null, null, null, null, null, currentBid.User_ID,
                                                            currentBid.Amount, currentBid.MaxBid);
                currentBid.ID = bid_id.GetValueOrDefault(-1);
                previousBid   = new BidCurrent(topBid);
                winnerBid     = new BidCurrent(currentBid);
                return(2);
            }

            decimal amount;
            bool    isautobid;

            // current max bid is bigger than the top bid
            if (topBid.MaxBid < currentBid.MaxBid)
            {
                amount            = currentBid.IsProxy ? Math.Min(topBid.Amount + Consts.GetIncrement(topBid.Amount), currentBid.MaxBid) : currentBid.MaxBid;
                isautobid         = topBid.Amount != topBid.MaxBid;
                topBid.Amount     = topBid.MaxBid;
                currentBid.Amount = !isautobid ? amount : (currentBid.IsProxy ? Math.Min(topBid.Amount + Consts.GetIncrement(topBid.Amount), currentBid.MaxBid) : currentBid.MaxBid);
                bid_id            = previousBid == null ? -1 : currentBid.ID;
                if (isautobid)
                {
                    dataContext.spBid_PlaceBidsForSingleBidding(auction.LinkParams.ID, ref bid_id, currentBid.User_ID, amount, currentBid.MaxBid, currentBid.DateMade, currentBid.IP,
                                                                currentBid.IsProxy, false, currentBid.IsActive, currentBid.Amount, currentBid.MaxBid, DateTime.Now,
                                                                topBid.ID, topBid.User_ID, topBid.Amount, topBid.MaxBid, topBid.DateMade, DateTime.Now, topBid.IP, topBid.IsProxy,
                                                                currentBid.User_ID, currentBid.Amount, currentBid.MaxBid);
                }
                else
                {
                    dataContext.spBid_PlaceBidsForSingleBidding(auction.LinkParams.ID, ref bid_id, currentBid.User_ID, currentBid.Amount,
                                                                currentBid.MaxBid, currentBid.DateMade, currentBid.IP,
                                                                currentBid.IsProxy, false, currentBid.IsActive, null, null, null, null, null, null, null, null, null, null, null,
                                                                currentBid.User_ID, currentBid.Amount, currentBid.MaxBid);
                }
                currentBid.ID = bid_id.GetValueOrDefault(-1);
                loserBid      = new BidCurrent(topBid);
                winnerBid     = new BidCurrent(currentBid);
                return(0);
            }

            amount            = currentBid.IsProxy ? Math.Min(topBid.Amount + Consts.GetIncrement(topBid.Amount), currentBid.MaxBid) : currentBid.MaxBid;
            isautobid         = amount < currentBid.MaxBid;
            currentBid.Amount = currentBid.MaxBid;
            bid_id            = previousBid == null ? -1 : currentBid.ID;

            if (topBid.Amount == topBid.MaxBid || (topBid.Amount > currentBid.Amount && topBid.MaxBid > currentBid.MaxBid))
            {
                dataContext.spBid_PlaceBidsForSingleBidding(auction.LinkParams.ID, ref bid_id, currentBid.User_ID, amount,
                                                            currentBid.MaxBid, currentBid.DateMade, currentBid.IP,
                                                            currentBid.IsProxy, false, currentBid.IsActive,
                                                            isautobid ? (decimal?)currentBid.Amount : null,
                                                            isautobid ? (decimal?)currentBid.MaxBid : null,
                                                            isautobid ? (DateTime?)DateTime.Now : null,
                                                            null, null, null, null, null, null, null, null, null, null, null);
            }
            else
            {
                topBid.Amount = Math.Min(currentBid.MaxBid + Consts.GetIncrement(currentBid.MaxBid), topBid.MaxBid);
                dataContext.spBid_PlaceBidsForSingleBidding(auction.LinkParams.ID, ref bid_id, currentBid.User_ID, amount,
                                                            currentBid.MaxBid, currentBid.DateMade, currentBid.IP,
                                                            currentBid.IsProxy, false, currentBid.IsActive,
                                                            isautobid ? (decimal?)currentBid.Amount : null,
                                                            isautobid ? (decimal?)currentBid.MaxBid : null,
                                                            isautobid ? (DateTime?)DateTime.Now : null,
                                                            topBid.ID, topBid.User_ID, topBid.Amount, topBid.MaxBid,
                                                            topBid.DateMade, DateTime.Now,
                                                            topBid.IP, topBid.IsProxy, topBid.User_ID, topBid.Amount, topBid.MaxBid);
            }
            currentBid.ID = bid_id.GetValueOrDefault(-1);
            loserBid      = new BidCurrent(currentBid);
            winnerBid     = new BidCurrent(topBid);
            return(1);
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        //PlaceSingleBid
        public BiddingObject PlaceSingleBid(long auction_id, bool isproxy, decimal amount, long user_id, int quantity, bool isproxyraise, decimal aprice, BidCurrent prevUsersBid, BidCurrent lastTop)
        {
            BidCurrent newBid;
            bool       isHighBidder = (lastTop != null) ? lastTop.User_ID == user_id : false;

            amount = (lastTop != null && ((long)amount == (long)lastTop.MaxBid || Math.Abs(lastTop.MaxBid - amount) < Consts.ErrorRangeAmount)) ? lastTop.MaxBid : amount;

            if (prevUsersBid != null)
            {
                newBid = prevUsersBid;
            }
            else
            {
                newBid = new BidCurrent();
                dataContext.BidCurrents.InsertOnSubmit(newBid);
            }
            if (!isproxy)
            {
                newBid.Amount = amount;
                if (newBid.MaxBid > amount)
                {
                    newBid.IsProxy = true;
                }
                else
                {
                    newBid.MaxBid  = amount;
                    newBid.IsProxy = false;
                }
            }
            else
            {
                decimal price = (lastTop == null) ? aprice : lastTop.Amount;
                newBid.MaxBid  = (newBid.MaxBid < amount) ? amount : newBid.MaxBid;
                newBid.Amount  = (price + Consts.GetIncrement(price) <= newBid.MaxBid) ? price : newBid.MaxBid;
                newBid.Amount += (lastTop != null && !isHighBidder && newBid.Amount + Consts.GetIncrement(price) <= newBid.MaxBid) ? Consts.GetIncrement(price) : 0;
                newBid.IsProxy = true;
            }
            newBid.Auction_ID = auction_id;
            newBid.User_ID    = user_id;
            newBid.Quantity   = quantity;
            newBid.DateMade   = DateTime.Now;
            newBid.IP         = Consts.UsersIPAddress;
            newBid.IsActive   = true;

            BidLogCurrent log = new BidLogCurrent();

            dataContext.BidLogCurrents.InsertOnSubmit(log);
            log.Quantity     = quantity;
            log.User_ID      = newBid.User_ID;
            log.IsProxy      = isproxy;
            log.MaxBid       = newBid.MaxBid;
            log.Amount       = newBid.Amount;
            log.IP           = newBid.IP;
            log.Auction_ID   = newBid.Auction_ID;
            log.DateMade     = DateTime.Now;
            log.IsProxyRaise = isproxyraise;

            SubmitChages();

            return(new BiddingObject {
                Bid = newBid, BidLog = log
            });
        }
        public ActionResult AuctionDetail(long?id, bool?ProxyBidding, decimal?BidAmount, decimal?OutBidAmount)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Category", "Auction"));
            }
            AuctionDetail auction = AuctionRepository.GetAuctionDetail(id.GetValueOrDefault(-1), true);

            if (auction == null)
            {
                return(RedirectToAction("Category", "Auction"));
            }
            if (!auction.IsCurrentEvent || auction.Status == Consts.AuctionStatus.Closed || auction.DateEnd.CompareTo(DateTime.Now) < 0 || (!ProxyBidding.HasValue || !BidAmount.HasValue))
            {
                return(RedirectToAction("AuctionDetail", "Auction", new { @id = auction.LinkParams.ID }));
            }

            PreviewBid previewBid = new PreviewBid
            {
                IsProxy    = ProxyBidding.Value,
                Amount     = BidAmount.Value,
                LinkParams = auction.LinkParams,
                Quantity   = 1
            };

            BidCurrent prevMaxBid = BidRepository.GetTopBidForItem(auction.LinkParams.ID);

            if (prevMaxBid != null)
            {
                previewBid.IsOutBid = previewBid.Amount <= prevMaxBid.Amount && previewBid.Amount <= prevMaxBid.MaxBid;
                if (prevMaxBid.User_ID == AppHelper.CurrentUser.ID)
                {
                    previewBid.IsUpdate       = true;
                    previewBid.PreviousAmount = prevMaxBid.Amount;
                    previewBid.PreviousMaxBid = prevMaxBid.MaxBid;
                    previewBid.RealAmount     = (previewBid.IsProxy) ? prevMaxBid.Amount : previewBid.Amount;
                    previewBid.Amount         = (previewBid.Amount < prevMaxBid.MaxBid) ? prevMaxBid.MaxBid : previewBid.Amount;
                }
                else
                {
                    previewBid.RealAmount = (!previewBid.IsProxy) ? previewBid.Amount : (((!OutBidAmount.HasValue) ? prevMaxBid.Amount : OutBidAmount.Value) + Consts.GetIncrement(prevMaxBid.Amount));
                }
            }
            else
            {
                previewBid.RealAmount = (previewBid.IsProxy) ? auction.Price : previewBid.Amount;
            }
            return(View("PreviewBid", previewBid));
        }
        public JsonResult UpdateAuctionResult(long id)
        {
            AuctionShort ashort = AuctionRepository.GetAuctionDetailResult(id, true);
            BidCurrent   bc     = BidRepository.GetTopBidForItem(id);

            return(JSON(new { currentbid = ashort.Bids > 0 ? ashort.CurrentBid.GetCurrency() : String.Empty, bids = ashort.Bids > 0 ? ashort.Bids.ToString() : String.Empty, minbid = ((bc == null ? ashort.Price : bc.Amount) + (bc == null ? 0 : Consts.GetIncrement(bc.Amount))).GetCurrency() }));
        }