Example #1
0
        private void SetActiveCouponDetails(ApplicationDbContext dbContext, Dashboard model, Promotion activePromo)
        {
            model.ActivePromoName           = activePromo.Title;
            model.ActivePromoDiscount       = activePromo.Discount;
            model.ActivePromoEndDate        = activePromo.DisplayEndDate;
            model.ActivePromoWarningMessage = GetActivePromoWarningMessage(activePromo.EndDate);
            model.ActivePromoId             = activePromo.Id;
            model.ActivePromoType           = Common.PromoType_Coupon;

            PromotionStats stats = (from x in dbContext.PromotionStats where x.Promotion.Id == activePromo.Id select x).FirstOrDefault();

            model.ActivePromoClaimedEntries = stats != null ? stats.TimesClaimed : 0;
            model.ActivePromoViews          = stats != null ? stats.TimesViewed : 0;
        }
Example #2
0
        public void UpdatePromotionStats(Promotion clientPromotion, ApplicationDbContext apiDbContext)
        {
            PromotionStats stats = apiDbContext.PromotionStats.Where(c => c.Promotion == clientPromotion).FirstOrDefault();

            if (stats == null)
            {
                stats = new PromotionStats {
                    Promotion = clientPromotion
                };
                apiDbContext.PromotionStats.Add(stats);
            }

            stats.TimesViewed++;
            apiDbContext.SaveChanges();
        }
Example #3
0
        public void HandleCLaimedPromotion(Promotion clientPromotion, ApplicationDbContext apiDbContext, string name, string email, ApplicationUser appUser)
        {
            PromotionStats stats = apiDbContext.PromotionStats.Where(c => c.Promotion == clientPromotion).FirstOrDefault();

            if (stats == null)
            {
                stats = new PromotionStats {
                    Promotion = clientPromotion
                };
                apiDbContext.PromotionStats.Add(stats);
            }
            stats.TimesClaimed++;
            UpdateClaimsPerMonthStat(appUser);

            var entry = new PromotionEntries {
                Promotion = clientPromotion, Name = name, EmailAddress = email
            };

            apiDbContext.PromotionEntries.Add(entry);

            apiDbContext.SaveChanges();
        }
Example #4
0
        public string GetPromoDetails()
        {
            var promoStatsId   = HttpContext.Session.GetString("promoStatsId");
            var promoStatsName = HttpContext.Session.GetString("promoStatsName");

            PromoDetails promoDetails = new PromoDetails();

            if (!String.IsNullOrEmpty(promoStatsId))
            {
                using (_dbContext)
                {
                    PromotionStats          promoStats   = (from x in _dbContext.PromotionStats where x.Promotion.Id == promoStatsId select x).FirstOrDefault();
                    List <PromotionEntries> promoEntries = (from x in _dbContext.PromotionEntries where x.Promotion.Id == promoStatsId select x).ToList();

                    promoDetails.PromoName    = (!String.IsNullOrEmpty(promoStatsName) ? promoStatsName : "");
                    promoDetails.PromoId      = promoStatsId;
                    promoDetails.TimesClaimed = (promoStats != null ? promoStats.TimesClaimed : 0);
                    promoDetails.TimesViewed  = (promoStats != null ? promoStats.TimesViewed : 0);
                    promoDetails.PromoEntries = promoEntries;
                }
            }

            return(JsonConvert.SerializeObject(promoDetails));
        }