Beispiel #1
0
        private void SelectDealPercent(DiscountedListing discountedListing)
        {
            Random rand = new Random();

            int ran = rand.Next(100);

            if (ran < 40)
            {
                discountedListing.ItemDiscountPercent = 33;
            }
            else if (ran < 65)
            {
                discountedListing.ItemDiscountPercent = 50;
            }
            else if (ran < 85)
            {
                discountedListing.ItemDiscountPercent = 66;
            }
            else if (ran < 99)
            {
                discountedListing.ItemDiscountPercent = 75;
            }
            else
            {
                discountedListing.ItemDiscountPercent = 85;
            }
        }
        public static void RolloverWeeklyDeals()
        {
            AppIdentityDbContext context;

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

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

                if (oldWeeklies != null && oldWeeklies.Count > 0)
                {
                    foreach (DiscountedListing oldListing in oldWeeklies)
                    {
                        listingRepository.DeleteDiscountedListing(oldListing.DiscountedListingID);
                    }
                }

                Random rand = new Random();

                int numDeals = rand.Next(randBase) + randOffset;

                List <Listing> newDeals = listingRepository.GetListings().Where(l => l.Quantity > 0 && l.ListingPrice > 1).OrderBy(x => Guid.NewGuid()).Take(numDeals).ToList();

                if (newDeals == null || newDeals.Count == 0)
                {
                    unitOfWork.Save();
                    return;
                }

                DateTime dealExpiry = GetMidnightEST().AddDays(7).AddHours(5);

                foreach (Listing listing in newDeals)
                {
                    DiscountedListing newDiscountedListing = new DiscountedListing();

                    SelectDealPercent(newDiscountedListing);

                    newDiscountedListing.WeeklyDeal     = true;
                    newDiscountedListing.ItemSaleExpiry = dealExpiry;

                    listing.AddDiscountedListing(newDiscountedListing);

                    listingRepository.UpdateListing(listing);
                }

                ISiteRepository siteRepository = new SiteRepository(unitOfWork);

                SiteNotification notification = new SiteNotification()
                {
                    Notification = "[weekly][/weekly] There are [gtext]" + numDeals + "[/gtext] new [url=https://theafterparty.azurewebsites.net/store/deals/weekly]deals[/url] available this week!", NotificationDate = DateTime.Now
                };
                siteRepository.InsertSiteNotification(notification);

                unitOfWork.Save();
            }
        }
        public void DeleteDiscountedListing(int discountedListingId)
        {
            DiscountedListing discountedListing = context.DiscountedListings.Find(discountedListingId);

            if (discountedListing != null)
            {
                context.DiscountedListings.Remove(discountedListing);
            }
        }
        public void UpdateDiscountedListing(DiscountedListing discountedListing)
        {
            DiscountedListing targetDiscountedListing = context.DiscountedListings.Find(discountedListing.ListingID);

            if (targetDiscountedListing != null)
            {
                targetDiscountedListing.ItemDiscountPercent = discountedListing.ItemDiscountPercent;
                targetDiscountedListing.ItemSaleExpiry      = discountedListing.ItemSaleExpiry;
                targetDiscountedListing.DailyDeal           = discountedListing.DailyDeal;
                targetDiscountedListing.WeeklyDeal          = discountedListing.WeeklyDeal;
            }
        }
Beispiel #5
0
        public void EditDiscountedListing(DiscountedListing discountedListing, int daysToAdd)
        {
            DiscountedListing updatedDiscountedListing = listingRepository.GetDiscountedListingByID(discountedListing.DiscountedListingID);

            updatedDiscountedListing.ItemDiscountPercent = discountedListing.ItemDiscountPercent;
            updatedDiscountedListing.WeeklyDeal          = discountedListing.WeeklyDeal;
            updatedDiscountedListing.DailyDeal           = discountedListing.DailyDeal;
            updatedDiscountedListing.ItemSaleExpiry      = updatedDiscountedListing.ItemSaleExpiry.AddDays(daysToAdd);

            listingRepository.UpdateDiscountedListing(updatedDiscountedListing);
            unitOfWork.Save();
        }
Beispiel #6
0
        public Listing GetDailyDeal()
        {
            DiscountedListing deal = listingRepository.GetDiscountedListingsQuery().Where(d => d.DailyDeal).FirstOrDefault();

            if (deal == null)
            {
                return(null);
            }
            else
            {
                return(deal.Listing);
            }
        }
Beispiel #7
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();
        }
Beispiel #8
0
        public void CreateNewWeeklyDeals(int numDeals)
        {
            List <Listing> newDeals = listingRepository.GetListings().Where(l => l.Quantity > 0).OrderBy(x => Guid.NewGuid()).Take(numDeals).ToList();

            DateTime dealExpiry = DateTime.Now.AddDays(7);

            foreach (Listing listing in newDeals)
            {
                DiscountedListing newDiscountedListing = new DiscountedListing();

                SelectDealPercent(newDiscountedListing);

                newDiscountedListing.WeeklyDeal     = true;
                newDiscountedListing.ItemSaleExpiry = dealExpiry;

                listing.AddDiscountedListing(newDiscountedListing);

                listingRepository.UpdateListing(listing);
            }

            unitOfWork.Save();
        }
Beispiel #9
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();
        }
Beispiel #10
0
        // If percent is 0, this signifies that percentages should be randomized
        public int RollDeals(int percent, bool days, int duration)
        {
            List <Listing>    listings = listingRepository.GetListingsQuery().Where(x => x.Quantity > 0 && x.ListingPrice > 1).OrderBy(x => Guid.NewGuid()).ToList();
            DiscountedListing discount = new DiscountedListing();
            DateTime          expiry   = DateTime.UtcNow;

            if (days)
            {
                expiry = expiry.AddDays(duration);
            }
            else
            {
                expiry = expiry.AddHours(duration);
            }

            int discountPct = 25;

            if (percent > 0)
            {
                discountPct = percent;
            }
            Random rand  = new Random();
            int    count = 0;

            int ran = 1;

            foreach (Listing listing in listings)
            {
                if (percent == 0)
                {
                    ran = rand.Next(100);

                    if (ran < 40)
                    {
                        discountPct = 33;
                    }
                    else if (ran < 65)
                    {
                        discountPct = 50;
                    }
                    else if (ran < 85)
                    {
                        discountPct = 66;
                    }
                    else if (ran < 99)
                    {
                        discountPct = 75;
                    }
                    else
                    {
                        discountPct = 85;
                    }
                }

                discount = new DiscountedListing(discountPct, expiry);
                count++;
                listingRepository.InsertDiscountedListing(discount);
            }

            unitOfWork.Save();

            return(count);
        }
Beispiel #11
0
        public int RollDeals(int deals, bool days, int duration, bool unique)
        {
            List <Listing>    listings = new List <Listing>();
            DiscountedListing discount = new DiscountedListing();
            DateTime          expiry   = DateTime.UtcNow;


            if (unique)
            {
                listings = listingRepository.GetListingsQuery().Where(x => x.Quantity > 0 && x.ListingPrice > 1 && x.DiscountedListings.Count == 0).OrderBy(x => Guid.NewGuid()).ToList();
            }
            else
            {
                listings = listingRepository.GetListingsQuery().Where(x => x.Quantity > 0 && x.ListingPrice > 1).OrderBy(x => Guid.NewGuid()).ToList();
            }

            if (days)
            {
                expiry = expiry.AddDays(duration);
            }
            else
            {
                expiry = expiry.AddHours(duration);
            }

            int    count       = 0;
            int    discountPct = 25;
            Random rand        = new Random();

            int ran = 1;

            foreach (Listing listing in listings)
            {
                ran = rand.Next(100);

                if (ran < 40)
                {
                    discountPct = 33;
                }
                else if (ran < 65)
                {
                    discountPct = 50;
                }
                else if (ran < 85)
                {
                    discountPct = 66;
                }
                else if (ran < 99)
                {
                    discountPct = 75;
                }
                else
                {
                    discountPct = 85;
                }

                discount            = new DiscountedListing(discountPct, expiry);
                discount.Listing    = listing;
                discount.DailyDeal  = false;
                discount.WeeklyDeal = false;

                if (++count >= deals)
                {
                    break;
                }

                listingRepository.InsertDiscountedListing(discount);
            }

            unitOfWork.Save();

            return(count);
        }
 public void InsertDiscountedListing(DiscountedListing discountedListing)
 {
     context.DiscountedListings.Add(discountedListing);
 }
Beispiel #13
0
 public ApiDiscountedListingModel(DiscountedListing discountedListing)
 {
     DiscountedListingID = discountedListing.DiscountedListingID;
     EndDate             = discountedListing.ItemSaleExpiry;
 }
Beispiel #14
0
 public AddEditDiscountedListingViewModel()
 {
     DiscountedListing = new DiscountedListing();
 }
        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();
            }
        }