コード例 #1
0
		Task IUserNotifier.NotifyOfferAdded(User user, BuyOffer offer, Auctions.Auction auction)
		{
			Contract.Requires(user != null);
			Contract.Requires(offer != null);
			Contract.Requires(auction != null);

			throw new NotImplementedException();
		}
コード例 #2
0
ファイル: BuyOfferTests.cs プロジェクト: Strachu/Auctioneer
		public void BuyOfferIsBuyoutOfferIfItIsEqualToAuctionBuyoutPrice()
		{
			var offer = new BuyOffer
			{
				Auction = new TestAuction { BuyoutPrice = new Money(100.0m, new TestCurrency()) },
				Amount  = 100.0m,
			};

			Assert.That(offer.IsBuyout, Is.True);
		}
コード例 #3
0
ファイル: BuyOfferTests.cs プロジェクト: Strachu/Auctioneer
		public void BuyOfferIsNotBuyoutOfferWhenBuyoutIsNotEnabled()
		{
			var offer = new BuyOffer
			{
				Auction = new TestAuction(),
				Amount  = 100.0m,
			};

			Assert.That(offer.IsBuyout, Is.False);
		}
コード例 #4
0
ファイル: BuyOfferTests.cs プロジェクト: Strachu/Auctioneer
		public void BuyOfferIsNotBuyoutOfferIfItIsLessThanAuctionBuyoutPrice()
		{
			var offer = new BuyOffer
			{
				Auction = new TestAuction { BuyoutPrice = new Money(100.0m, new TestCurrency()) },
				Amount  = 75.0m,
			};

			Assert.That(offer.IsBuyout, Is.False);
		}
コード例 #5
0
		public async Task NotifyOfferAdded(User user, BuyOffer offer, Auction auction)
		{
			await mMailService.SendAsync(new OfferAddedMail
			{
				UserMail       = user.Email,
				UserFirstName  = user.FirstName,

				AuctionId      = auction.Id,
				AuctionTitle   = auction.Title,

				OfferMoney     = offer.Money
			});
		}
コード例 #6
0
ファイル: AuctionService.cs プロジェクト: Strachu/Auctioneer
		public async Task Bid(int auctionId, string buyerId, decimal bidAmount, IValidationErrorNotifier errors)
		{
			var auction = await GetById(auctionId);
			if(!auction.IsBiddingEnabled)
			{
				errors.AddError(Lang.Buy.BiddingNotEnabled);
				return;
			}

			if(!CanBeBought(auction, buyerId, errors))
				return;

			if(bidAmount < auction.MinBidAllowed)
			{
				errors.AddError(String.Format(Lang.Buy.TooLowBid, new Money(auction.MinBidAllowed, auction.MinimumPrice.Currency)));
				return;
			}

			var previouslyBestOffer = auction.BestOffer;
			var userOffer           = new BuyOffer
			{
				UserId = buyerId,
				Date   = DateTime.Now,
				Amount = bidAmount,
			};

			auction.Offers.Add(userOffer);

			await mContext.SaveChangesAsync();

			await mUserNotifier.NotifyOfferAdded(userOffer.User, userOffer, auction);

			if(previouslyBestOffer != null)
			{
				await mUserNotifier.NotifyOutbid(previouslyBestOffer.User, auction);
			}
		}
コード例 #7
0
ファイル: Auctions.cs プロジェクト: Strachu/Auctioneer
        public static void Add(AuctioneerDbContext context)
        {
            var rndGenerator     = new Random(Seed: 746293114);
            var imageInitializer = new AuctionImageInitializer();
            var categoryCount    = context.Categories.Count();
            var userIds          = context.Users.Select(x => x.Id).ToList();
            var currencies       = context.Currencies.ToList();

            var auctions = new Auction[100000];
            for(int i = 0; i < auctions.Length; ++i)
            {
                var creationDate = new DateTime
                (
                    day    : rndGenerator.Next(1, 29),
                    month  : rndGenerator.Next(1, 13),
                    year   : rndGenerator.Next(2010, 2016),
                    hour   : rndGenerator.Next(0, 24),
                    minute : rndGenerator.Next(0, 60),
                    second : rndGenerator.Next(0, 60)
                );

                if(creationDate > DateTime.Now)
                    creationDate = DateTime.Now;

                auctions[i] = new Auction
                {
                    CategoryId   = rndGenerator.Next(categoryCount) + 1,
                    Title        = "The auction #" + (i + 1),
                    Description  = "The description of auction number " + (i + 1),
                    SellerId     = userIds[rndGenerator.Next(userIds.Count)],
                    CreationDate = creationDate,
                    EndDate      = creationDate.AddDays(rndGenerator.NextDouble() * 14),
                    PhotoCount   = 0
                };

                bool hasBuyoutPrice = (rndGenerator.Next(100) + 1) < 90;
                if(hasBuyoutPrice)
                {
                    auctions[i].BuyoutPrice = new Money(rndGenerator.Next(1, 1000), currencies[rndGenerator.Next(currencies.Count)]);
                }

                bool isBiddingEnabled = !hasBuyoutPrice || ((rndGenerator.Next(100) + 1) < 30 && (auctions[i].BuyoutPrice.Amount >= 10.0m));
                if(isBiddingEnabled)
                {
                    auctions[i].MinimumPrice = new Money(rndGenerator.Next(1, 1000), currencies[rndGenerator.Next(currencies.Count)]);
                }

                if(isBiddingEnabled && hasBuyoutPrice)
                {
                    var fixedAmount = Math.Min(auctions[i].MinimumPrice.Amount, auctions[i].BuyoutPrice.Amount * 0.5m);

                    auctions[i].MinimumPrice = new Money(fixedAmount, auctions[i].BuyoutPrice.Currency);
                }

                bool hasBidOffer = (rndGenerator.Next(100) + 1) < 90;
                if(isBiddingEnabled && hasBidOffer)
                {
                    var offerCountProbability = new int[100];
                    for(int x =  0; x <  30; ++x) offerCountProbability[x] = 1;
                    for(int x = 30; x <  60; ++x) offerCountProbability[x] = 2;
                    for(int x = 60; x <  80; ++x) offerCountProbability[x] = 3;
                    for(int x = 80; x <  95; ++x) offerCountProbability[x] = 4;
                    for(int x = 95; x < 100; ++x) offerCountProbability[x] = 5;

                    var offerCount          = offerCountProbability[rndGenerator.Next(offerCountProbability.Length)];
                    var previousOfferDate   = auctions[i].CreationDate.AddDays(1);
                    var previousOfferAmount = 0.0m;
                    for(int x = 0; x < offerCount; ++x)
                    {
                        var minimumPossibleOffer = Math.Max(Math.Ceiling(auctions[i].MinimumPrice.Amount), previousOfferAmount + 1);
                        var maximumPossibleOffer = Math.Floor(hasBuyoutPrice ? auctions[i].BuyoutPrice.Amount * 0.9m : 1000.0m);
                        if(minimumPossibleOffer >= maximumPossibleOffer)
                            break;

                        var offer = new BuyOffer
                        {
                            AuctionId = i + 1,
                            UserId    = userIds[rndGenerator.Next(userIds.Count)],
                            Date      = previousOfferDate.AddHours(rndGenerator.Next(1, 24)),
                            Amount    = rndGenerator.Next((int)minimumPossibleOffer, (int)maximumPossibleOffer)
                        };

                        previousOfferDate   = offer.Date;
                        previousOfferAmount = offer.Amount;

                        auctions[i].Offers.Add(offer);
                    }
                }

                bool hasBeenBoughtOut = (rndGenerator.Next(100) + 1) < 75;
                if(hasBeenBoughtOut && hasBuyoutPrice)
                {
                    var lastOfferDate = (auctions[i].Offers.Any()) ? auctions[i].Offers.Last().Date : auctions[i].CreationDate;

                    var buyoutOffer = new BuyOffer
                    {
                        AuctionId = i + 1,
                        UserId    = userIds[rndGenerator.Next(userIds.Count)],
                        Date      = lastOfferDate.AddHours(rndGenerator.Next(1, 24)),
                        Amount    = auctions[i].BuyoutPrice.Amount
                    };

                    auctions[i].Offers.Add(buyoutOffer);
                }

                if(auctions[i].Status == AuctionStatus.Active)
                {
                    imageInitializer.CopyRandomThumbnailForAuction(i + 1);
                    imageInitializer.CopyRandomPhotosForAuction(i + 1);

                    auctions[i].PhotoCount = imageInitializer.GetAuctionPhotoCount(i + 1);
                }
            }

            InsertAuctions(context, auctions);
        }