Exemple #1
0
        public static void RegisterAuctions()
        {
            IEnumerable <Auction> closedAuctions = new List <Auction>();

            using (AppIdentityDbContext context = AppIdentityDbContext.Create())
            //using (IUnitOfWork unitOfWork = new UnitOfWork(context))
            {
                IUnitOfWork        unitOfWork        = new UnitOfWork(context);
                IAuctionRepository auctionRepository = new AuctionRepository(unitOfWork);
                IListingRepository listingRepository = new ListingRepository(unitOfWork);
                IUserRepository    userRepository    = new UserRepository(unitOfWork);
                IAuctionService    auctionService    = new AuctionService(auctionRepository, userRepository, listingRepository, unitOfWork);

                //List<Auction> openAuctions = auctionService.GetAuctions().Where(a => a.IsOpen()).ToList();
                // get auctions that: are not open (have ended), have some bids (which are assumed to be valid), and has no winners assigned yet
                closedAuctions = auctionService.GetAuctionsAsQueryable().Where(a => a.EndTime < DateTime.Now && a.AuctionBids.Count > 0 && a.Winners.Count > 0);

                foreach (Auction auction in closedAuctions)
                {
                    BackgroundJob.Enqueue(() => RegisterAuction(auction.AuctionID));
                }

                auctionService.Dispose();
                auctionRepository.Dispose();
                listingRepository.Dispose();
                userRepository.Dispose();
                unitOfWork.Dispose();
            }
        }