Ejemplo n.º 1
0
        public Auction FindBy(Guid Id)
        {
            AuctionDTO auctionDTO;

            using (var connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["AuctionDB"].ConnectionString))
            {
                auctionDTO = connection.Query<AuctionDTO>("Select * From Auctions Where Id = CAST(@Id AS uniqueidentifier)", new { Id = Id }).FirstOrDefault();
            }

            var auctionSnapshot = new AuctionSnapshot();

            auctionSnapshot.Id = auctionDTO.Id;
            auctionSnapshot.EndsAt = auctionDTO.AuctionEnds;
            auctionSnapshot.StartingPrice = auctionDTO.StartingPrice;
            auctionSnapshot.Version = auctionDTO.Version;

            if (auctionDTO.BidderMemberId.HasValue)
            {
                var bidSnapshot = new WinningBidSnapshot();

                bidSnapshot.AuctionId = auctionDTO.Id;
                bidSnapshot.BiddersMaximumBid = auctionDTO.MaximumBid.Value;
                bidSnapshot.CurrentPrice = auctionDTO.CurrentPrice.Value;
                bidSnapshot.BiddersId = auctionDTO.BidderMemberId.Value;
                bidSnapshot.TimeOfBid = auctionDTO.TimeOfBid.Value;
                auctionSnapshot.WinningBid = bidSnapshot;
            }
           
            return Auction.CreateFrom(auctionSnapshot);
        }
        private Auction(AuctionSnapshot snapshot)
        {
            this.Id            = snapshot.Id;
            this.StartingPrice = new Money(snapshot.StartingPrice);
            this.EndsAt        = snapshot.EndsAt;
            this.Version       = snapshot.Version;

            if (snapshot.WinningBid != null)
            {
                CurrentWinningBid = WinningBid.CreateFrom(snapshot.WinningBid);
            }
        }
        public AuctionSnapshot GetSnapshot()
        {
            var snapshot = new AuctionSnapshot();

            snapshot.Id            = this.Id;
            snapshot.StartingPrice = this.StartingPrice.GetSnapshot().Value;
            snapshot.EndsAt        = this.EndsAt;
            snapshot.Version       = this.Version;

            if (HasACurrentBid())
            {
                snapshot.WinningBid = CurrentWinningBid.GetSnapshot();
            }

            return(snapshot);
        }
Ejemplo n.º 4
0
        public AuctionStatus ConvertToStatus(AuctionSnapshot snapshot)
        {
            var status = new AuctionStatus();

            status.AuctionEnds = snapshot.EndsAt;            
            status.Id = snapshot.Id;
            status.TimeRemaining = TimeRemaining(snapshot.EndsAt);

            if (snapshot.WinningBid != null)
            {
                status.NumberOfBids = _bidHistory.NoOfBidsFor(snapshot.Id);
                status.WinningBidderId = snapshot.WinningBid.BiddersId;
                status.CurrentPrice = snapshot.WinningBid.CurrentPrice;
            }
            
            return status;
        }
Ejemplo n.º 5
0
 public void Map(AuctionDTO auctionDTO, AuctionSnapshot snapshot)
 {
     auctionDTO.Id = snapshot.Id;
     auctionDTO.StartingPrice = snapshot.StartingPrice;
     auctionDTO.AuctionEnds = snapshot.EndsAt;
     auctionDTO.Version = snapshot.Version;
     
     if (snapshot.WinningBid != null)
     {
         auctionDTO.BidderMemberId = snapshot.WinningBid.BiddersId;
         auctionDTO.CurrentPrice = snapshot.WinningBid.CurrentPrice;
         auctionDTO.MaximumBid = snapshot.WinningBid.BiddersMaximumBid;
         auctionDTO.TimeOfBid = snapshot.WinningBid.TimeOfBid;
     }
 }
 public static Auction CreateFrom(AuctionSnapshot snapshot)
 {
     return(new Auction(snapshot));
 }