예제 #1
0
 public BidCurrent(BidCurrent bc)
 {
     Amount = bc.Amount;
       Auction_ID = bc.Auction_ID;
       DateMade = bc.DateMade;
       ID = bc.ID;
       IP = bc.IP;
       IsActive = bc.IsActive;
       IsProxy = bc.IsProxy;
       MaxBid = bc.MaxBid;
       Quantity = bc.Quantity;
       User_ID = bc.User_ID;
 }
예제 #2
0
 public BidCurrent(BidCurrent bc)
 {
     Amount     = bc.Amount;
     Auction_ID = bc.Auction_ID;
     DateMade   = bc.DateMade;
     ID         = bc.ID;
     IP         = bc.IP;
     IsActive   = bc.IsActive;
     IsProxy    = bc.IsProxy;
     MaxBid     = bc.MaxBid;
     Quantity   = bc.Quantity;
     User_ID    = bc.User_ID;
 }
        //public string Bidder { get; set; }

        public BidCurrent(BidCurrent bc)
        {
            Amount     = bc.Amount;
            Auction_ID = bc.Auction_ID;
            Bidder     = bc.Bidder;
            Comments   = bc.Comments;
            DateMade   = bc.DateMade;
            ID         = bc.ID;
            IP         = bc.IP;
            IsActive   = bc.IsActive;
            IsProxy    = bc.IsProxy;
            ItemNumber = bc.ItemNumber;
            MaxBid     = bc.MaxBid;
            Quantity   = bc.Quantity;
            User_ID    = bc.User_ID;
        }
예제 #4
0
 //TestBiddingResult
 public void TestBiddingResult(long auction_id, BidCurrent current, BidCurrent opponent, BidCurrent winner, byte result, long etickes, long emilisec, ref long?parent_id)
 {
     if (opponent != null)
     {
         dataContext.spTest_BiddingResult(auction_id, current.ID, current.User_ID, current.Amount, current.MaxBid,
                                          current.IsProxy, current.DateMade, opponent.ID, opponent.User_ID, opponent.Amount,
                                          opponent.MaxBid, opponent.IsProxy, opponent.DateMade, result, winner.User_ID,
                                          winner.Amount, winner.MaxBid, etickes, emilisec, ref parent_id);
     }
     else
     {
         dataContext.spTest_BiddingResult(auction_id, current.ID, current.User_ID, current.Amount, current.MaxBid,
                                          current.IsProxy, current.DateMade, null, null, null, null, null, null, result, winner.User_ID,
                                          winner.Amount, winner.MaxBid, etickes, emilisec, ref parent_id);
     }
 }
예제 #5
0
        //GetTopBidForItem
        public BidCurrent GetTopBidForItem(long auction_id, bool fromcache = true)
        {
            DataCacheObject dco    = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.BIDS, "GETTOPBIDFORITEM", new object[] { auction_id }, CachingExpirationTime.Hours_01);
            BidCurrent      result = CacheRepository.Get(dco) as BidCurrent;

            if (result != null && fromcache)
            {
                return(new BidCurrent(result));
            }
            dataContext.CommandTimeout = 600000;
            result = dataContext.spBid_WinningBid(auction_id).FirstOrDefault();
            if (result != null)
            {
                dco.Data = result;
                CacheRepository.Add(dco);
            }
            return(result != null ? new BidCurrent(result) : null);
        }
        //GetUsersTopBidForItem
        public BidCurrent GetUserTopBidForItem(long auction_id, long user_id, bool iscaching)
        {
            DataCacheObject dco    = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.BIDS, "GETUSERTOPBIDFORITEM", new object[] { auction_id, user_id }, CachingExpirationTime.Hours_01);
            BidCurrent      result = CacheRepository.Get(dco) as BidCurrent;

            if (result != null && iscaching)
            {
                return(result);
            }
            dataContext.CommandTimeout = 600000;
            result = dataContext.spBid_UserTopBid(user_id, auction_id).FirstOrDefault();
            if (result != null)
            {
                dco.Data = result;
                CacheRepository.Add(dco);
            }
            return(result != null ? new BidCurrent(result) : null);
        }
 //Update
 public bool Update(BidCurrent updBid)
 {
     try
     {
         //BidCurrent b = dataContext.BidCurrents.Where(B => B.ID == updBid.ID).SingleOrDefault();
         //if (b == null) return false;
         //b.Amount = updBid.Amount;
         //b.User_ID = updBid.User_ID;
         //b.DateMade = updBid.DateMade;
         //b.IP = updBid.IP;
         //b.IsProxy = updBid.IsProxy;
         //b.MaxBid = updBid.MaxBid;
         //b.Quantity = updBid.Quantity;
         SubmitChages();
     }
     catch (Exception ex)
     {
         Logger.LogException("[bidlogcurrent_id=" + updBid.ID + "]", ex);
         return(false);
     }
     return(true);
 }
예제 #8
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;
    }
예제 #9
0
 //UpdateCurrentBid
 public bool UpdateCurrentBid(BidCurrent b)
 {
   try
   {
     //BidCurrent b = dataContext.BidCurrents.Where(B => B.ID == updBid.ID).SingleOrDefault();
     //if (b == null) return false;
     //b.Amount = updBid.Amount;
     //b.User_ID = updBid.User_ID;
     //b.DateMade = updBid.DateMade;
     //b.IP = updBid.IP;
     //b.IsProxy = updBid.IsProxy;
     //b.IsReserveBid = updBid.IsReserveBid;
     //b.MaxBid = updBid.MaxBid;
     //b.Quantity = updBid.Quantity;
     SubmitChages();
   }
   catch (Exception ex)
   {
     Logger.LogException("[bidlogcurrent_id=" + b.ID + "]", ex);
     return false;
   }
   return true;
 }
예제 #10
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();
    }
예제 #11
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 };
    }
예제 #12
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
            });
        }
예제 #13
0
        public JsonExecuteResult PlaceBid(long auction_id, long UserID, decimal Amount, decimal MaxBid, int Quantity,
            DateTime DateMade, bool IsProxy, string Comments, string IP, long bid_id)
        {
            try
            {
                var auction = GetAuctionDetail(auction_id);
                if (auction == null)
                {
                    throw new Exception("The auction doesn't exist.");
                }
                if (!auction.IsCurrentEvent || auction.CloseStep == 2)
                {
                    throw new Exception("You can't place this bid. The auction is not open.");
                }
                //add to bidwatch
                if (bid_id == 0)
                {
                    var bw =
                        dataContext.BidWatchCurrents.SingleOrDefault(
                            bidWatch => bidWatch.Auction_ID == auction_id && bidWatch.User_ID == UserID);
                    if (bw == null)
                    {
                        dataContext.BidWatchCurrents.InsertOnSubmit(new BidWatchCurrent
                        {
                            Auction_ID = auction_id,
                            User_ID = UserID
                        });
                        GeneralRepository.SubmitChanges(dataContext);
                    }
                }

                byte result;
                var currentBid = new BidCurrent
                {
                    Amount = Amount,
                    Auction_ID = auction_id,
                    DateMade = DateMade,
                    IP = IP,
                    IsActive = true,
                    IsProxy = IsProxy || Amount < MaxBid,
                    MaxBid = MaxBid,
                    Quantity = Quantity,
                    User_ID = UserID
                };
                BidCurrent previousBid, loserBid, winnerBid;

                lock (auction)
                {
                    result = BiddingForSingleAuction(auction, currentBid, out previousBid, out loserBid, out winnerBid);
                    if (result == 3)
                    {
                        throw new Exception("The error had happen.");
                    }

                    CacheRepository.Remove(new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.AUCTIONS,
                        "GETAUCTIONRESULTCURRENT", new object[] {auction_id}));
                    CacheRepository.Remove(new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.BIDS,
                        "GETTOPBIDFORITEM", new object[] {auction_id}));
                    CacheRepository.Put(new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.BIDS,
                        "GETUSERTOPBIDFORITEM", new object[] {auction_id, UserID}, CachingExpirationTime.Hours_01,
                        currentBid));
                }
            }
            catch (Exception ex)
            {
                return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message);
            }
            return new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS);

            //try
            //{
            //  Auction auction = dataContext.Auctions.Where(A => A.ID == auction_id).SingleOrDefault();
            //  Event evnt = auction.Event;
            //  if (auction == null) throw new Exception("The auction doesn't exist.");
            //  if (!evnt.IsCurrent || evnt.CloseStep==2) throw new Exception("You can't place this bid. The auction is not open.");
            //  //if (auction.Quantity < Quantity) throw new Exception("The auction quantity is less than " + Quantity.ToString() + ". You can't place this bid.");

            //  if (bid_id == 0)
            //  {
            //    BidWatch bw = dataContext.BidWatches.Where(BW => BW.Auction_ID == auction_id && BW.User_ID == UserID).SingleOrDefault();
            //    if (bw == null)
            //    {
            //      bw = new BidWatch();
            //      bw.Auction_ID = auction_id;
            //      bw.User_ID = UserID;
            //      dataContext.BidWatches.InsertOnSubmit(bw);
            //    }
            //  }

            //  BidCurrent prevBid = GetUserTopBidForItem(auction_id, UserID);
            //  BidCurrent LastTop = GetTopBidForItem(auction_id);
            //  bool isfirstbid = LastTop == null;
            //  decimal lastMaxBid = (LastTop == null) ? 0 : LastTop.MaxBid;
            //  decimal lastamount = (LastTop == null) ? 0 : LastTop.Amount;

            //  BiddingObject placedBid = PlaceSingleBid(auction_id, IsProxy, MaxBid, UserID, Quantity, (LastTop != null && LastTop.User_ID == UserID && IsProxy), auction.Price, prevBid, LastTop);

            //  List<BidLogCurrent> newblogs = new List<BidLogCurrent>();
            //  ResolveProxyBiddingSituation(auction_id, UserID, IsProxy, placedBid, LastTop, auction.Price, newblogs);

            //  BidCurrent CurrentTop = GetTopBidForItem(auction_id);
            //  bool IsOutBidden = (LastTop != null && CurrentTop.MaxBid <= LastTop.MaxBid && CurrentTop.User_ID != UserID);
            //  if (IsOutBidden)
            //  {
            //    if (placedBid.Bid.Amount >= CurrentTop.Amount)
            //    {
            //      CurrentTop.Amount = placedBid.Bid.Amount;
            //      GeneralRepository.SubmitChanges(dataContext);
            //    }
            //    if (lastamount < CurrentTop.Amount && newblogs.Where(BL => BL.User_ID == CurrentTop.User_ID && BL.Amount == CurrentTop.Amount && BL.MaxBid == CurrentTop.MaxBid && BL.IsProxy == CurrentTop.IsProxy).Count() == 0)
            //      AddBidLogCurrent(auction_id, CurrentTop.Quantity, CurrentTop.User_ID, CurrentTop.IsProxy, CurrentTop.Amount, CurrentTop.MaxBid, false, CurrentTop.IP);
            //    UpdateAuctionBiddingResult(auction_id, CurrentTop.User_ID, CurrentTop.Amount, CurrentTop.MaxBid);
            //  }
            //  else
            //  {
            //    UpdateAuctionBiddingResult(auction_id, CurrentTop.User_ID, CurrentTop.Amount, CurrentTop.MaxBid);
            //  }
            //}
            //catch (Exception ex)
            //{
            //  return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message);
            //}
            //return new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS);
        }
 //UpdateTopBidForItemCache
 public void UpdateTopBidForItemCache(long auction_id, BidCurrent bid)
 {
     CacheRepository.Put(new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.BIDS, "GETTOPBIDFORITEM", new object[] { auction_id }, CachingExpirationTime.Hours_01, bid));
 }
    [VauctionAuthorize, Compress, HttpPost, ValidateAntiForgeryTokenWrapper(HttpVerbs.Post)] // AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)
    public ActionResult PlaceBid(long? id, bool? ProxyBidding, decimal? BidAmount, decimal? RealBidAmount)
    {
      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 });

      SessionUser cuser = AppHelper.CurrentUser;

      if (!AuctionRepository.IsUserWatchItem(cuser.ID, auction.LinkParams.ID))
        AuctionRepository.AddItemToWatchList(cuser.ID, auction.LinkParams.ID);

      PreviewBid previewBid = new PreviewBid
                                {
                                  LinkParams = auction.LinkParams,
                                  IsProxy = ProxyBidding.Value,
                                  Amount = BidAmount.Value,
                                  Quantity = 1,
                                  RealAmount = RealBidAmount.GetValueOrDefault(0)
                                };

      byte result;
      BidCurrent currentBid = new BidCurrent
      {
        Amount = BidAmount.GetValueOrDefault(0),
        Auction_ID = id.Value,
        DateMade = DateTime.Now,
        IP = Consts.UsersIPAddress,
        IsActive = true,
        IsProxy = ProxyBidding.GetValueOrDefault(false),
        MaxBid = BidAmount.GetValueOrDefault(0),
        Quantity = 1,
        User_ID = cuser.ID
      };
      BidCurrent previousBid, loserBid, winnerBid;

      result = BidRepository.BiddingForSingleAuction(auction, currentBid, out previousBid, out loserBid, out winnerBid);

      if (result == 3) return RedirectToAction("AuctionDetail", new { id.Value });

      AuctionRepository.RemoveAuctionResultsCache(id.Value);

      BidRepository.RemoveTopBidForItemCache(id.Value);

      BidRepository.UpdateUsersTopBidCache(id.Value, cuser.ID, currentBid);

      if (result == 1)
      {
        previewBid.Amount = winnerBid.Amount;
        if (cuser.IsRecievingOutBidNotice && !String.IsNullOrEmpty(cuser.Email) && !cuser.IsHouseBidder)
          Mail.SendOutBidLetter(cuser.FirstName, cuser.LastName, cuser.Email, auction.LinkParams.Lot.ToString(), auction.LinkParams.Title, winnerBid.Amount.GetCurrency(), auction.EventDateEnd > DateTime.Now ? auction.EventDateEnd.ToString() : DateTime.Now.Date.ToShortDateString(), auction.LinkParams.AuctionDetailUrl);
        return View("OutBid", previewBid);
      }

      if (cuser.IsRecievingBidConfirmation && !String.IsNullOrEmpty(cuser.Email) && !cuser.IsHouseBidder)
      {
        if (result == 2)
          Mail.SendSuccessfulBidUpdateLetter(cuser.FirstName, cuser.LastName, cuser.Email, auction.LinkParams.Lot.ToString(), auction.LinkParams.Title, currentBid.Amount.GetCurrency(), currentBid.MaxBid.GetCurrency(), auction.EventDateEnd > DateTime.Now ? auction.EventDateEnd.ToString() : DateTime.Now.Date.ToShortDateString(), auction.LinkParams.AuctionDetailUrl, currentBid.MaxBid > previousBid.MaxBid);
        else
          Mail.SendSuccessfulBidLetter(cuser.FirstName, cuser.LastName, cuser.Email, auction.LinkParams.Lot.ToString(), auction.LinkParams.Title, currentBid.Amount.GetCurrency(), BidAmount.GetCurrency(), auction.EventDateEnd > DateTime.Now ? auction.EventDateEnd.ToString() : DateTime.Now.Date.ToShortDateString(), auction.LinkParams.AuctionDetailUrl);
      }

      if (loserBid != null && loserBid.User_ID != cuser.ID)
      {
        User usr = dataProvider.UserRepository.GetUser(loserBid.User_ID, true);
        if (usr.IsRecievingOutBidNotice && !String.IsNullOrEmpty(usr.Email) && !usr.IsHouseBidder)
        {
          AddressCard ac = dataProvider.UserRepository.GetAddressCard(usr.Billing_AddressCard_ID.GetValueOrDefault(-1), true);
          Mail.SendOutBidLetter(ac.FirstName, ac.LastName, usr.Email, auction.LinkParams.Lot.ToString(), auction.LinkParams.Title, winnerBid.Amount.GetCurrency(), auction.EventDateEnd > DateTime.Now ? auction.EventDateEnd.ToString() : DateTime.Now.Date.ToShortDateString(), auction.LinkParams.AuctionDetailUrl);
        }
      }
      /*

      BidCurrent prevBid = BidRepository.GetUserTopBidForItem(id.Value, cuser.ID, false);
      if (prevBid != null && (prevBid.IsProxy == ProxyBidding) && prevBid.MaxBid >= BidAmount) return RedirectToAction("AuctionDetail", "Auction", new { @id = id });
      
      BidCurrent lastTop = BidRepository.GetTopBidForItem(id.Value);
      decimal lastMaxBid = (lastTop == null) ? 0 : lastTop.MaxBid;
      decimal lastamount = (lastTop == null) ? 0 : lastTop.Amount;

      BiddingObject placedBid = BidRepository.PlaceSingleBid(id.Value, ProxyBidding.Value, BidAmount.Value, cuser.ID, 1, (lastTop != null && lastTop.User_ID == cuser.ID && ProxyBidding.Value), auction.Price, prevBid, lastTop);      

      List<BidLogCurrent> newblogs = new List<BidLogCurrent>();
      BidRepository.ResolveProxyBiddingSituation(id.Value, cuser.ID, ProxyBidding.Value, placedBid, lastTop, auction.Price, newblogs);

      BidCurrent currentTop = BidRepository.GetTopBidForItem(id.Value);      
      BidRepository.UpdateUsersTopBid(id.Value, AppSession.CurrentUser.ID, placedBid.Bid);
      bool IsOutBidden = (lastTop != null && currentTop.MaxBid <= lastTop.MaxBid && currentTop.User_ID != cuser.ID);
      if (IsOutBidden)
      {
        if (placedBid.Bid.Amount >= currentTop.Amount)
        {
          currentTop.Amount = placedBid.Bid.Amount;
          BidRepository.UpdateCurrentBid(currentTop);
        }        
        if (lastamount < currentTop.Amount && newblogs.Where(BL=>BL.User_ID ==currentTop.User_ID && BL.Amount ==currentTop.Amount && BL.MaxBid==currentTop.MaxBid && BL.IsProxy == currentTop.IsProxy).Count()==0)
          BidRepository.AddBidLogCurrent(id.Value, currentTop.Quantity, currentTop.User_ID, currentTop.IsProxy, currentTop.Amount, currentTop.MaxBid, false, currentTop.IP);
        previewBid.Amount = currentTop.Amount;
        try
        {
          if (cuser.IsRecievingOutBidNotice && !String.IsNullOrEmpty(cuser.Email) && !cuser.IsHouseBidder)
            Mail.SendOutBidLetter(cuser.FirstName, cuser.LastName, cuser.Email, auction.LinkParams.Lot.ToString(), auction.LinkParams.Title, currentTop.Amount.GetCurrency(), auction.EventDateEnd > DateTime.Now ? auction.EventDateEnd.ToString() : DateTime.Now.Date.ToShortDateString(), auction.LinkParams.AuctionDetailUrl);
        }
        catch (Exception ex)
        {
          Utils.Lib.Logger.LogException(ex);
        }
        AuctionRepository.UpdateAuctionBiddingResult(id.Value, currentTop.User_ID, currentTop.Amount, currentTop.MaxBid);
        return View("OutBid", previewBid);
      }
      AuctionRepository.UpdateAuctionBiddingResult(id.Value, currentTop.User_ID, currentTop.Amount, currentTop.MaxBid);
      if (lastTop != null && lastTop.User_ID!=cuser.ID)
      {
        User usr = dataProvider.UserRepository.GetUser(lastTop.User_ID, true);
        AddressCard ac = dataProvider.UserRepository.GetAddressCard(usr.Billing_AddressCard_ID.GetValueOrDefault(-1), true);
        if (usr.IsRecievingOutBidNotice && !String.IsNullOrEmpty(usr.Email) && !usr.IsHouseBidder)
        {
          try
          {
            Mail.SendOutBidLetter(ac.FirstName, ac.LastName, usr.Email, auction.LinkParams.Lot.ToString(), auction.LinkParams.Title, placedBid.Bid.Amount.GetCurrency(), auction.EventDateEnd > DateTime.Now ? auction.EventDateEnd.ToString() : DateTime.Now.Date.ToShortDateString(), auction.LinkParams.AuctionDetailUrl);
          }
          catch (Exception ex)
          {
            Utils.Lib.Logger.LogException(ex);
          }
        }
      }

      try
      {
        if (cuser.IsRecievingBidConfirmation && !String.IsNullOrEmpty(cuser.Email) && !cuser.IsHouseBidder)
        {
          if (lastTop == null || lastTop.User_ID != cuser.ID)
          {
            Mail.SendSuccessfulBidLetter(cuser.FirstName, cuser.LastName, cuser.Email, auction.LinkParams.Lot.ToString(), auction.LinkParams.Title, placedBid.Bid.Amount.GetCurrency(), BidAmount.GetCurrency(), auction.EventDateEnd > DateTime.Now ? auction.EventDateEnd.ToString() : DateTime.Now.Date.ToShortDateString(), auction.LinkParams.AuctionDetailUrl);
          }
          else
          {
            Mail.SendSuccessfulBidUpdateLetter(cuser.FirstName, cuser.LastName, cuser.Email, auction.LinkParams.Lot.ToString(), auction.LinkParams.Title, currentTop.Amount.GetCurrency(), currentTop.MaxBid.GetCurrency(), auction.EventDateEnd > DateTime.Now ? auction.EventDateEnd.ToString() : DateTime.Now.Date.ToShortDateString(), auction.LinkParams.AuctionDetailUrl, (lastMaxBid < currentTop.MaxBid));
          }
        }
      }
      catch (Exception ex)
      {
        Utils.Lib.Logger.LogException(ex);
      }*/
      return View("SuccessfulBid", auction);
    }
예제 #16
0
 //UpdateUsersTopBid
 public void UpdateUsersTopBid(long auction_id, long user_id, BidCurrent bid)
 {
     CacheRepository.Put(new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.BIDS, "GETUSERTOPBIDFORITEM",
                                             new object[] { auction_id, user_id }, CachingExpirationTime.Minutes_05, bid));
 }
예제 #17
0
        //ResolveProxyBiddingSituation
        private 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;
            }
            var bids = dataContext.spBid_BidsExceptCurrent(auction_id, placedBid.Bid.ID, user_id).ToList();
            if (bids.Count() == 0)
            {
                return;
            }

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

            var 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 (var 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)
                        {
                            var 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;
                    }
                }
            }
            GeneralRepository.SubmitChanges(dataContext);
        }
예제 #18
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();
        }
예제 #19
0
 //UpdateUsersTopBid
 public void UpdateUsersTopBid(long auction_id, long user_id, BidCurrent bid)
 {
   CacheRepository.Put(new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.BIDS, "GETUSERTOPBIDFORITEM",
                                             new object[] { auction_id, user_id }, CachingExpirationTime.Minutes_05, bid));
 }
예제 #20
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);
        }
        //AddWinnerToAuction
        public JsonExecuteResult AddWinnerToAuction(long auction_id, long user_id)
        {
            try
            {
                Auction auction = GetAuction(auction_id);
                if (auction.Status != (byte)Consts.AuctionStatus.Closed) throw new Exception("This lot is not closed.");
                if (auction.Event.CloseStep != 1) throw new Exception("You can't use this functionality to add the winner on this lot.");
                if (auction.Bids.Any()) throw new Exception("You can't add the winner for this lot, because this lot has already a winner");
                User user = dataContext.Users.SingleOrDefault(U => U.ID == user_id);
                if (user == null) throw new Exception("This user doesn't exists");
                if (user.UserStatus_ID != (byte)Consts.UserStatus.Active) throw new Exception("This user can't be a winner because his status is not active.");
                if (user.UserType_ID != (byte)Consts.UserTypes.Buyer && user.UserType_ID != (byte)Consts.UserTypes.SellerBuyer) throw new Exception("This user can't be a winner because his isn't a buyer.");

                Bid bid = new Bid();
                bid.Amount = bid.MaxBid = auction.Price;
                bid.Auction_ID = auction_id;
                bid.DateMade = auction.EndDate.AddMinutes(-1);
                bid.IP = Consts.UsersIPAddress;
                bid.IsProxy = false;
                bid.Quantity = auction.Quantity;
                bid.User_ID = user_id;
                dataContext.Bids.InsertOnSubmit(bid);

                BidCurrent bidcur = new BidCurrent();
                bidcur.Amount = bidcur.MaxBid = auction.Price;
                bidcur.Auction_ID = auction_id;
                bidcur.DateMade = auction.EndDate.AddMinutes(-1);
                bidcur.IP = Consts.UsersIPAddress;
                bidcur.IsProxy = false;
                bidcur.Quantity = auction.Quantity;
                bidcur.User_ID = user_id;
                bidcur.IsActive = true;
                dataContext.BidCurrents.InsertOnSubmit(bidcur);

                BidLog blog = new BidLog
                  {
                      Amount = bid.Amount,
                      Auction_ID = bid.Auction_ID,
                      DateMade = bid.DateMade,
                      IP = bid.IP,
                      IsProxy = bid.IsProxy,
                      IsProxyRaise = false,
                      MaxBid = bid.MaxBid,
                      Quantity = bid.Quantity,
                      User_ID = bid.User_ID
                  };
                dataContext.BidLogs.InsertOnSubmit(blog);

                BidLogCurrent blogcur = new BidLogCurrent
                  {
                      Amount = bid.Amount,
                      Auction_ID = bid.Auction_ID,
                      DateMade = bid.DateMade,
                      IP = bid.IP,
                      IsProxy = bid.IsProxy,
                      IsProxyRaise = false,
                      MaxBid = bid.MaxBid,
                      Quantity = bid.Quantity,
                      User_ID = bid.User_ID
                  };
                dataContext.BidLogCurrents.InsertOnSubmit(blogcur);

                BidWatchCurrent bw = new BidWatchCurrent { Auction_ID = auction_id, User_ID = user_id };
                dataContext.BidWatchCurrents.InsertOnSubmit(bw);

                EventRegistration er = dataContext.spSelect_EventRegistration(auction.Event_ID, user_id).SingleOrDefault();
                if (er == null)
                    dataContext.EventRegistrations.InsertOnSubmit(new EventRegistration { Event_ID = auction.Event_ID, User_ID = user_id });

                GeneralRepository.SubmitChanges(dataContext);

                UpdateAuctionBiddingResult(bid.Auction_ID, bid.User_ID, bid.Amount, bid.MaxBid);

                try
                {
                    System.Net.WebClient client = new System.Net.WebClient();
                    client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                    client.OpenRead(Consts.CacheClearFrontendIP + Consts.FrontEndClearARPMethod + "/" + auction_id.ToString());
                }
                catch (Exception ex)
                {
                    Logger.LogException("[" + Consts.CacheClearFrontendIP + Consts.FrontEndClearARPMethod + "/" + auction_id.ToString() + "]", ex);
                }
            }
            catch (Exception ex)
            {
                return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message);
            }
            return new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS);
        }