コード例 #1
0
ファイル: AuctionRepository.cs プロジェクト: elbandit/PPPDDD
        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);
        }
        public WinningBidSnapshot GetSnapshot()
        {
            var snapshot = new WinningBidSnapshot();

            snapshot.AuctionId         = AuctionId;
            snapshot.BiddersId         = this.Bidder;
            snapshot.BiddersMaximumBid = this.MaximumBid.GetSnapshot().Value;
            snapshot.CurrentPrice      = this.CurrentAuctionPrice.Amount.GetSnapshot().Value;
            snapshot.TimeOfBid         = this.TimeOfBid;

            return(snapshot);
        }
 public static WinningBid CreateFrom(WinningBidSnapshot bidSnapShot)
 {
     return(new WinningBid(bidSnapShot.AuctionId, bidSnapShot.BiddersId, new Money(bidSnapShot.BiddersMaximumBid), new Money(bidSnapShot.CurrentPrice), bidSnapShot.TimeOfBid));
 }