예제 #1
0
        public void RolloverDailyDeal()
        {
            DiscountedListing discountedListing = listingRepository.GetDiscountedListings().Where(d => d.DailyDeal).FirstOrDefault();

            if (discountedListing != null)
            {
                listingRepository.DeleteDiscountedListing(discountedListing.DiscountedListingID);
            }

            List <DiscountedListing> expiredListings = listingRepository.GetDiscountedListings().Where(d => d.IsLive() == false).ToList();

            if (expiredListings != null)
            {
                foreach (DiscountedListing listing in expiredListings)
                {
                    listingRepository.DeleteDiscountedListing(listing.DiscountedListingID);
                }
            }

            DiscountedListing newDiscountedListing = new DiscountedListing();

            Listing randomListing = listingRepository.GetListings().Where(l => l.Quantity > 0).OrderBy(x => Guid.NewGuid()).FirstOrDefault();

            if (randomListing == null)
            {
                unitOfWork.Save();
                return;
            }

            SelectDealPercent(newDiscountedListing);

            DateTime expiry = DateTime.Now.AddDays(1).AddMinutes(-5);

            newDiscountedListing.DailyDeal      = true;
            newDiscountedListing.ItemSaleExpiry = expiry;

            randomListing.AddDiscountedListing(newDiscountedListing);

            listingRepository.UpdateListing(randomListing);

            SiteNotification notification = new SiteNotification()
            {
                Notification = "Today's daily deal is " + randomListing.ListingName + ", now on sale for " + randomListing.SaleOrDefaultPrice() + " points!", NotificationDate = DateTime.Now
            };

            siteRepository.InsertSiteNotification(notification);

            unitOfWork.Save();
        }
예제 #2
0
        public void AddDiscountedListing(DiscountedListing discountedListing, int daysDealLast)
        {
            discountedListing.ItemSaleExpiry = DateTime.Now.AddDays(daysDealLast);

            Listing saleListing = listingRepository.GetListingByID(discountedListing.ListingID);

            saleListing.AddDiscountedListing(discountedListing);

            if (daysDealLast == 0)
            {
                if (discountedListing.WeeklyDeal)
                {
                    discountedListing.ItemSaleExpiry = DateTime.Now.AddDays(7);
                }
                else if (discountedListing.DailyDeal)
                {
                    discountedListing.ItemSaleExpiry = DateTime.Now.AddDays(1);
                }
            }

            listingRepository.InsertDiscountedListing(discountedListing);
            unitOfWork.Save();
        }
예제 #3
0
        public static void RolloverDailyDeal()
        {
            AppIdentityDbContext context;

            using (context = AppIdentityDbContext.Create())
            {
                IUnitOfWork        unitOfWork        = new UnitOfWork(context);
                IListingRepository listingRepository = new ListingRepository(unitOfWork);

                DiscountedListing discountedListing = listingRepository.GetDiscountedListings().Where(d => d.DailyDeal).FirstOrDefault();

                if (discountedListing != null)
                {
                    listingRepository.DeleteDiscountedListing(discountedListing.DiscountedListingID);
                }

                List <DiscountedListing> expiredListings = listingRepository.GetDiscountedListings().Where(d => d.IsLive() == false).ToList();

                if (expiredListings != null)
                {
                    foreach (DiscountedListing listing in expiredListings)
                    {
                        listingRepository.DeleteDiscountedListing(listing.DiscountedListingID);
                    }
                }

                DiscountedListing newDiscountedListing = new DiscountedListing();

                Listing randomListing = listingRepository.GetListings().Where(l => l.Quantity > 0 && l.ListingPrice > 1).OrderBy(x => Guid.NewGuid()).FirstOrDefault();

                if (randomListing == null)
                {
                    unitOfWork.Save();
                    return;
                }

                SelectDealPercent(newDiscountedListing);

                DateTime expiry = GetMidnightEST().AddDays(1).AddHours(5);

                newDiscountedListing.DailyDeal      = true;
                newDiscountedListing.ItemSaleExpiry = expiry;

                randomListing.AddDiscountedListing(newDiscountedListing);

                listingRepository.UpdateListing(randomListing);

                ISiteRepository siteRepository = new SiteRepository(unitOfWork);

                String urlAndName = String.Empty;

                if (String.IsNullOrWhiteSpace(randomListing.GetQualifiedSteamStorePageURL()) == false)
                {
                    urlAndName = "[url=" + randomListing.GetQualifiedSteamStorePageURL() + "]" + randomListing.ListingName + "[/url]";
                }
                else
                {
                    urlAndName = randomListing.ListingName;
                }

                SiteNotification notification = new SiteNotification()
                {
                    Notification = "[daily][/daily] Today's [url=https://theafterparty.azurewebsites.net/store/deals/daily]daily deal[/url] is " + urlAndName + ", now on sale for [gtext]" + randomListing.SaleOrDefaultPrice() + "[/gtext] " + randomListing.GetPluralizedSalePriceUnit() + "!", NotificationDate = DateTime.Now
                };
                siteRepository.InsertSiteNotification(notification);

                unitOfWork.Save();
            }
        }