Esempio n. 1
0
        public bool SubscriptionWithinTrafficLimit(ApplicationUser user, ApplicationDbContext DbContext)
        {
            if (CommonAccount.FreeTrialActive(user))
            {
                return(true);
            }

            bool subscriptionWithinTrafficLimit = true;

            int promoClaimsThisMonth = FindClaimsForCurrentMonth(user);

            switch (user.SubscriptionPlan)
            {
            case SubscriptionOptions.FreeAccount:
                //0-25 Claims a month
                subscriptionWithinTrafficLimit = promoClaimsThisMonth <= SubscriptionOptions.MaxFreeAccountClaims;
                break;

            case SubscriptionOptions.Bronze:
                //Up to 500 Claims a month
                subscriptionWithinTrafficLimit = promoClaimsThisMonth <= SubscriptionOptions.MaxBronzeAccountClaims;
                break;

            case SubscriptionOptions.Silver:
                //Up to 2000 Claims a month
                subscriptionWithinTrafficLimit = promoClaimsThisMonth <= SubscriptionOptions.MaxSilverAccountClaims;
                break;

            case SubscriptionOptions.Gold:
                //Unlimited Claims a month
                subscriptionWithinTrafficLimit = true;
                break;
            }

            if (subscriptionWithinTrafficLimit && user.MonthlyPromotionLimitReached == true)
            {
                // Once a user upgrades a plan OR a new month starts, reset their promo limit flag
                user.MonthlyPromotionLimitReached = false;
                DbContext.SaveChanges();
            }
            else if (subscriptionWithinTrafficLimit == false && user.MonthlyPromotionLimitReached == false)
            {
                // 1st traffic limit violation that has not been set in the DB should come in here...
                // This flag will be cleared after a new month or an upgrade of a plan
                user.MonthlyPromotionLimitReached = true;
                DbContext.SaveChanges();
            }

            return(subscriptionWithinTrafficLimit);
        }
Esempio n. 2
0
        private String GetDashboardMessage(ApplicationUser user)
        {
            if (CommonAccount.FreeTrialActive(user))
            {
                return(GetFreeTrialMessage(CommonAccount.DaysSinceAccountSignup(user.AccountCreationDate)));
            }

            String dashboardMessage = String.Empty;

            if (user.AccountSuspended)
            {
                dashboardMessage = "Account suspended, make a payment on your account here";
            }
            else if (user.MonthlyPromotionLimitReached)
            {
                dashboardMessage = "Account promotion limit reached, upgrade account here";
            }
            else
            {
                dashboardMessage = "You rock, view account here";
            }

            return(dashboardMessage);
        }