コード例 #1
0
 public void AddBid(Guid auctionId, Bid bid)
 {
     var auction = Get(auctionId);
     if (auction != null)
     {
         auction.Bids.Add(bid);
     }
 }
コード例 #2
0
        public void PlaceBid(Guid bidId, Guid auctionId, decimal amount, DateTime bidTime, Customer customer)
        {
            var auction = Get(auctionId);
            if (customer == null) throw new CustomerNotExistException("Customer does not exist");
            if (auction == null) throw new AuctionNotExistException();

            if (bidTime < auction.StartTime || bidTime > auction.EndTime)
                throw new BidTimeToEarlyOrToLateException();

            if (amount < auction.Product.GetStartPrice())
                throw new BidAmountToSmallException(amount, auction.Product.GetStartPrice());

            var lastestBid = auction.Bids.OrderBy(b => b.Amount).LastOrDefault();
            if (lastestBid != null && amount < lastestBid.Amount)
                throw new BidAmountToSmallException(amount, lastestBid.Amount);

            var bid = new Bid { Id = bidId, Customer = customer, Amount = amount, Time = bidTime };
            _auctionRespository.AddBid(auction.Id, bid);
            if (bid.Amount >= auction.AcceptedPrice)
            {
                EndAuction(auction.Id);
            }
        }