Example #1
0
        /// <summary>
        /// Updates the fields of the auction with the specified rules:
        /// • if this is the first bid, then the maximum offer is set to offer , the current price is not changed (that is, it
        /// remains the starting price), and the bidder becomes the current winner;
        /// • if the bidder was already winning this auction, the maximum offer is set to offer , current price and current
        /// winner are unchanged;
        /// • if this is NOT the first bid, the bidder is NOT the current winner, and offer is higher than the current
        /// maximum offer, in the following denoted by CMO, then the current price is set to the minimum between
        /// offer and CMO+minimumBidIncrement, the maximum offer is set to offer , and the bidder becomes the
        /// current winner;
        /// • if this is NOT the first bid, the bidder is NOT the current winner, and offer is NOT higher than the current
        /// maximum offer, in the following denoted by CMO, then the current price is set to the minimum between
        /// CMO and offer +minimumBidIncrement, and the current winner does not change.
        /// </summary>
        /// <exception cref="UnavailableDbException"></exception>
        /// <param name="auct"></param>
        /// <param name="bidderSess"></param>
        /// <param name="offer"></param>
        private static void UpdateAuctionBid(AuctionEntity auct, SessionEntity bidderSess, double offer)
        {
            try
            {
                if (auct.Cmo == 0 || (auct.Cmo > 0 && auct.CurrentWinner == bidderSess.User))
                {
                    auct.Cmo           = offer;
                    auct.CurrentWinner = bidderSess.User;
                }

                if (!(auct.Cmo > 0) || auct.CurrentWinner.Equals(bidderSess.User))
                {
                    return;
                }
                if (offer > auct.Cmo)
                {
                    auct.CurrentWinner = bidderSess.User;
                    auct.CurrentPrice  = Math.Min(offer, auct.Cmo + auct.Site.MinBidIncr);
                }
                else if (offer < auct.Cmo)
                {
                    auct.CurrentPrice = Math.Min(auct.Cmo, offer + auct.Site.MinBidIncr);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                throw new UnavailableDbException("Connection error!");
            }
        }
        public IEnumerable <IAuction> BuildAll(IEnumerable <AuctionEntity> enumerable)
        {
            var auctionEntities = enumerable.ToList();

            if (auctionEntities.Count == 0)
            {
                yield break;
            }

            foreach (var auctionEntity in auctionEntities)
            {
                AuctionEntity = auctionEntity;
                yield return(Build());
            }
        }
Example #3
0
 /// <summary>
 /// Return false  if :
 ///• the bidder is (already) the current winner and offer is lower than the maximum offer increased by
 ///minimumBidIncrement
 ///• the bidder is not the current winner and offer is lower than the current price
 ///• the bidder is not the current winner and offer is lower than the current price increased by minimumBid - Increment AND this is not the first bid
 /// </summary>
 /// <exception cref="UnavailableDbException"></exception>
 /// <param name="auct"></param>
 /// <param name="bidder"></param>
 /// <param name="offer"></param>
 /// <returns></returns>
 private bool ControlBidder(AuctionEntity auct, User bidder, double offer)
 {
     try
     {
         return((!bidder.Equals(CurrentWinner()) ||
                 !(offer < auct.Cmo + auct.Site.MinBidIncr)) && (bidder.Equals(CurrentWinner()) ||
                                                                 !(offer < auct.CurrentPrice)) &&
                ((bidder.Equals(CurrentWinner()) ||
                  !(offer < auct.CurrentPrice + auct.Site.MinBidIncr) ||
                  !(auct.Cmo > 0))));
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
         throw new UnavailableDbException("Connection error!");
     }
 }
Example #4
0
        public async Task <IActionResult> AddAuction(AuctionModel auction)
        {
            var    file    = HttpContext.Request.Form.Files[0];
            string uploads = Path.Combine(_hostingEnvironment.WebRootPath, "img/auctionThumbs");

            string filePath = Path.Combine(uploads, file.FileName);

            using (Stream fileStream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(fileStream);
            }



            var viewEntity = new AuctionEntity
            {
                Name        = auction.Name,
                Description = auction.Description,
                StartPrice  = auction.StartPrice,
                Price       = auction.StartPrice,
                Category    = auction.Category,
                Auctioner   = null,
                EndDate     = auction.EndDate,
                fileName    = file.FileName
            };



            var viewModel = new AuctionAddedViewModel
            {
                Name        = auction.Name,
                Description = auction.Description,
                StartPrice  = auction.StartPrice,
                Category    = auction.Category,
                fileName    = file.FileName
            };

            ;

            _dbContext.Auctions.Add(viewEntity);
            _dbContext.SaveChanges();

            return(View("AuctionAdded", viewModel));
        }
Example #5
0
        public IAuction CreateAuction(string description, DateTime endsOn, double startingPrice)
        {
            CheckIsValid(this);
            CheckNull(description, "description");
            CheckIsNotEmpty(description, "description");
            CheckDouble(startingPrice, "startingPrice");
            CheckEndsOn(endsOn, _alarmClock.Now, true);
            try {
                using (var c = new TotalContext(_connectionString))
                {
                    var session = c.Sessions.Find(Id);
                    var site    = c.Users.Find(session.UserId).Site;
                    var user    = c.Users.Find(session.UserId);

                    var dbAuction = new AuctionEntity()
                    {
                        SellerId         = user.Id,
                        SiteName         = site.Name,
                        CurrentPrice     = startingPrice,
                        ShortDescription = description,
                        EndsOn           = endsOn,
                    };
                    c.Auctions.Add(dbAuction);

                    session.ValidUntil = _alarmClock.Now.AddSeconds(site.SessionExp);
                    c.SaveChanges();

                    ValidUntil = _alarmClock.Now.AddSeconds(site.SessionExp);
                    return(new Auction(dbAuction.Id, User, description, endsOn, _alarmClock, _connectionString));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                throw new UnavailableDbException("connection failed!", e);
            }
        }
 public AuctionBuilder SetAuctionEntity(AuctionEntity auctionEntity)
 {
     AuctionEntity = auctionEntity;
     return(this);
 }