Ejemplo n.º 1
0
        public static void RegisterGiveaways()
        {
            List <Giveaway> closedGiveaways = new List <Giveaway>();

            using (AppIdentityDbContext context = AppIdentityDbContext.Create())
            //using (IUnitOfWork unitOfWork = new UnitOfWork(context))
            {
                IUnitOfWork         unitOfWork         = new UnitOfWork(context);
                IGiveawayRepository giveawayRepository = new GiveawayRepository(unitOfWork);
                IListingRepository  listingRepository  = new ListingRepository(unitOfWork);
                IUserRepository     userRepository     = new UserRepository(unitOfWork);
                IUserService        userService        = new UserService(listingRepository, userRepository, null, giveawayRepository, null, null, 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
                closedGiveaways = userService.GetGiveaways().Where(a => a.IsOpen() == false && String.IsNullOrWhiteSpace(a.WinnerID) == true).ToList();

                userService.Dispose();
                giveawayRepository.Dispose();
                listingRepository.Dispose();
                userRepository.Dispose();
                unitOfWork.Dispose();
            }

            foreach (Giveaway giveaway in closedGiveaways)
            {
                BackgroundJob.Enqueue(() => RegisterGiveaways(giveaway.GiveawayID));
            }
        }
Ejemplo n.º 2
0
        public static void CloseGiveaway(int giveawayId)
        {
            using (AppIdentityDbContext context = AppIdentityDbContext.Create())
            {
                IUnitOfWork         unitOfWork         = new UnitOfWork(context);
                IGiveawayRepository giveawayRepository = new GiveawayRepository(unitOfWork);
                IListingRepository  listingRepository  = new ListingRepository(unitOfWork);
                IUserRepository     userRepository     = new UserRepository(unitOfWork);
                IUserService        userService        = new UserService(listingRepository, userRepository, null, giveawayRepository, null, null, unitOfWork);

                userService.DrawGiveawayWinners(giveawayId);

                userService.Dispose();
                giveawayRepository.Dispose();
                listingRepository.Dispose();
                userRepository.Dispose();
                unitOfWork.Dispose();
            }
        }