Task<bool> IAuctionService.CanBeRemoved(Auction auction, string userId)
        {
            Contract.Requires(auction != null);
            Contract.Requires(userId != null);

            throw new NotImplementedException();
        }
        Task IAuctionService.AddAuction(Auction newAuction, IEnumerable<System.IO.Stream> photosData)
        {
            Contract.Requires(newAuction != null);
            Contract.Requires(photosData != null);

            throw new NotImplementedException();
        }
Example #3
0
		public async Task NotifyAuctionExpired(User user, Auction auction)
		{
			await mMailService.SendAsync(new AuctionExpiredMail
			{
				UserMail             = user.Email,
				UserFirstName        = user.FirstName,

				AuctionId            = auction.Id,
				AuctionTitle         = auction.Title
			});
		}
Example #4
0
        public IBreadcrumbBuilder WithAuctionLink(Auction auction)
        {
            mItems.Add(new BreadcrumbViewModel.Item
            {
                Name      = auction.Title,
                TargetUrl = mUrlHelper.Action(controllerName: "Auction", actionName: "Show", routeValues: new
                {
                    id   = auction.Id,
                    slug = SlugGenerator.SlugFromTitle(auction.Title)
                })
            });

            return this;
        }
        public static AuctionViewModel FromAuction(Auction auction)
        {
            Contract.Requires(auction != null);

            return new AuctionViewModel
            {
                Id          = auction.Id,
                Title       = auction.Title,
                BuyoutPrice = auction.BuyoutPrice,
                BestBid     = auction.BestOffer != null ? auction.BestOffer.Money : auction.MinimumPrice,
                TimeTillEnd = auction.EndDate - DateTime.Now,
                Slug        = SlugGenerator.SlugFromTitle(auction.Title)
            };
        }
Example #6
0
		public void WhenOfferHasAlreadyBeenRaised_MinBidAllowedIsOnePercentHigherThanHighestOfferAndRoundedToInteger()
		{
			var auction = new Auction
			{
				MinimumPrice = new Money(50.0m, new TestCurrency()),
				Offers       = new BuyOffer[]
				{
					new TestBuyOffer { Amount = 125.0m },
					new TestBuyOffer { Amount =  75.0m }
				}
			};

			Assert.That(auction.MinBidAllowed, Is.EqualTo(127.0m));
		}
Example #7
0
		public async Task NotifyAuctionWon(User user, Auction auction)
		{
			await mMailService.SendAsync(new AuctionWonMail
			{
				UserMail       = user.Email,
				UserFirstName  = user.FirstName,

				AuctionId      = auction.Id,
				AuctionTitle   = auction.Title,
				AuctionPrice   = auction.BestOffer.Money,

				SellerEmail    = auction.Seller.Email,
				SellerUserName = auction.Seller.UserName,
				SellerFullName = auction.Seller.FirstName + " " + auction.Seller.LastName,
			});
		}
Example #8
0
		public async Task NotifyAuctionSold(User user, Auction auction)
		{
			await mMailService.SendAsync(new AuctionSoldMail
			{
				UserMail             = user.Email,
				UserFirstName        = user.FirstName,

				AuctionId            = auction.Id,
				AuctionTitle         = auction.Title,
				AuctionPrice         = auction.BestOffer.Money,

				BuyerEmail           = auction.Buyer.Email,
				BuyerUserName        = auction.Buyer.UserName,
				BuyerFullName        = auction.Buyer.FirstName + " " + auction.Buyer.LastName,
				BuyerShippingAddress = auction.Buyer.Address,
			});
		}
		public static AuctionShowViewModel FromAuction(Auction auction, IEnumerable<string> photoUrls)
		{
			Contract.Requires(auction != null);

			return new AuctionShowViewModel
			{
				Id               = auction.Id,
				Title            = auction.Title,
				Description      = auction.Description,
				Status           = auction.Status,
				EndDate          = auction.EndDate,
				IsBiddingEnabled = auction.IsBiddingEnabled,
				BestOffer        = auction.BestOffer != null ? auction.BestOffer.Money : null,
				MinPrice         = auction.MinimumPrice,
				MinAllowedBid    = auction.MinBidAllowed,
				MaxAllowedBid    = auction.IsBuyoutEnabled ? auction.BuyoutPrice.Amount : (decimal?)null,
				IsBuyoutEnabled  = auction.IsBuyoutEnabled,
				BuyoutPrice      = auction.BuyoutPrice,
				SellerUserName   = auction.Seller.UserName,
				BuyerUserName    = (auction.Buyer != null) ? auction.Buyer.UserName : null,
				Photos           = photoUrls.Select(x => new AuctionShowViewModel.Photo { Url = x })
			};
		}
Example #10
0
		private async Task AddAuctionToDatabase(Auction newAuction)
		{
			var sanitizer = new HtmlSanitizer();
			
			newAuction.Description = sanitizer.Sanitize(newAuction.Description);

			await InsertAuction(newAuction);
		}
Example #11
0
		public Task<bool> CanBeMoved(Auction auction, string userId)
		{
			return mUserService.IsUserInRole(userId, "Admin");
		}
        bool IAuctionService.CanBeBought(Auction auction, string buyerId)
        {
            Contract.Requires(auction != null);

            throw new NotImplementedException();
        }
Example #13
0
		private bool CanBeBought(Auction auction, string buyerId, IValidationErrorNotifier errors)
		{
			if(auction.Status != AuctionStatus.Active)
			{
				errors.AddError(Lang.Buy.AuctionIsInactive);
				return false;
			}

			if(auction.SellerId == buyerId)
			{
				errors.AddError(Lang.Buy.CannotBuyOwnAuctions);
				return false;
			}

			return true;
		}
Example #14
0
		public bool CanBeBought(Auction auction, string buyerId)
		{
			return CanBeBought(auction, buyerId, new ErrorCollection());
		}
Example #15
0
        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);
        }
		private Auction AddAuctionToDatabase(Auction auction)
		{
			mDbContext.Auctions.Add(auction);
			mDbContext.SaveChanges();

			return auction;
		}
Example #17
0
		public async Task AddAuction(Auction newAuction, IEnumerable<Stream> photosData)
		{
			using(var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
			{
				await AddAuctionToDatabase(newAuction);
				await SaveAuctionPhotosToFileSystem(newAuction.Id, photosData);

				transaction.Complete();
			}
		}
Example #18
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
			});
		}
Example #19
0
		private async Task InsertAuction(Auction auction)
		{
			// Do not insert new currencies
			if(auction.MinimumPrice != null)
			{
				mContext.Entry(auction.MinimumPrice.Currency).State = EntityState.Unchanged; 
			}

			if(auction.BuyoutPrice != null)
			{
				mContext.Entry(auction.BuyoutPrice.Currency).State = EntityState.Unchanged;
			}

			mContext.Auctions.Add(auction);
			await mContext.SaveChangesAsync();
		}
Example #20
0
		public Task<bool> CanBeRemoved(Auction auction, string userId)
		{
			return CanBeRemoved(auction, userId, new ErrorCollection());
		}
Example #21
0
		private async Task<bool> CanBeRemoved(Auction auction, string userId, IValidationErrorNotifier errors)
		{
			if(auction.SellerId != userId && !await mUserService.IsUserInRole(userId, "Admin"))
			{
				errors.AddError(Lang.Delete.WrongUser);
				return false;
			}

			if(auction.Offers.Any())
			{
				errors.AddError(Lang.Delete.BuyOfferHasBeenMade);
				return false;				
			}

			if(auction.Status != AuctionStatus.Active)
			{
				errors.AddError(Lang.Delete.AuctionIsInactive);
				return false;
			}

			return true;
		}
        private void AddTestData(AuctioneerDbContext context)
        {
            context.Categories.Add(new TestCategory { Id = 1 });
            context.Users.Add(new TestUser { Id = "1" });
            context.SaveChanges();

            mExpiredAuction = new TestAuction
            {
                EndDate = DateTime.Now.Subtract(TimeSpan.FromDays(2))
            };

            mAuctionSoldByBidding = new TestAuction
            {
                EndDate = DateTime.Now.Subtract(TimeSpan.FromDays(3)),
                Offers  = new BuyOffer[]
                {
                    new TestBuyOffer { Amount = 10 }
                }
            };

            mAuctionSoldByBuyout = new TestAuction
            {
                BuyoutPrice = new Money(100, new Currency("$", CurrencySymbolPosition.BeforeAmount)),
                EndDate     = DateTime.Now.AddDays(3),
                Offers      = new BuyOffer[]
                {
                    new TestBuyOffer { Amount = 50 },
                    new TestBuyOffer { Amount = 100 }
                }
            };

            mActiveActionWithoutOffers = new TestAuction
            {
                EndDate = DateTime.Now.AddDays(3)
            };

            mActiveActionWithOffers = new TestAuction
            {
                EndDate = DateTime.Now.AddDays(3),
                Offers  = new BuyOffer[]
                {
                    new TestBuyOffer { Amount = 50 },
                    new TestBuyOffer { Amount = 30 }
                }
            };

            context.Auctions.Add(mExpiredAuction);
            context.Auctions.Add(mAuctionSoldByBidding);
            context.Auctions.Add(mAuctionSoldByBuyout);
            context.Auctions.Add(mActiveActionWithOffers);
            context.Auctions.Add(mActiveActionWithoutOffers);
            context.SaveChanges();
        }
Example #23
0
		public void WhenNoOfferHasBeenRaised_MinBidAllowedIsEqualToMinimumPrice()
		{
			var auction = new Auction { MinimumPrice = new Money(50.0m, new TestCurrency()) };

			Assert.That(auction.MinBidAllowed, Is.EqualTo(auction.MinimumPrice.Amount));
		}