public JsonNetResult GetPlan(string planName)
        {
            AccountPaymentPlanService.PaymentPlan paymentPlan = null;

            #region (Plan A) Get data from Redis Cache

            try
            {
                IDatabase cache = CoreServices.RedisConnectionMultiplexers.RedisMultiplexer.GetDatabase();

                string hashKey   = "paymentplans";
                string hashField = "plan:" + planName;

                var redisValue = cache.HashGet(hashKey, hashField);

                if (redisValue.HasValue)
                {
                    paymentPlan = JsonConvert.DeserializeObject <AccountPaymentPlanService.PaymentPlan>(redisValue);
                }
            }
            catch (Exception e)
            {
                var error = e.Message;
                //TODO: Log: error message for Redis call
            }

            #endregion

            if (paymentPlan == null)
            {
                #region (Plan B) Get data from WCF

                var accountPaymentPlanServiceClient = new AccountPaymentPlanService.AccountPaymentPlanServiceClient();

                try
                {
                    accountPaymentPlanServiceClient.Open();
                    paymentPlan = accountPaymentPlanServiceClient.GetPaymentPlan(planName);

                    //Close the connection
                    WCFManager.CloseConnection(accountPaymentPlanServiceClient);
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(accountPaymentPlanServiceClient, exceptionMessage, currentMethodString);

                    #endregion
                }

                #endregion
            }

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = paymentPlan;

            return(jsonNetResult);
        }
Ejemplo n.º 2
0
        public JsonNetResult UpgradePathAvailable(string planName)
        {
            var response = new AccountPaymentPlanService.DataAccessResponseType();

            List <AccountPaymentPlanService.PaymentPlan> paymentPlans = null;

            #region (Plan A) Get data from Redis Cache

            try
            {
                IDatabase cache = CoreServices.RedisConnectionMultiplexers.RedisMultiplexer.GetDatabase();

                string hashKey   = "paymentplans";
                string hashField = "list:True:True";

                var redisValue = cache.HashGet(hashKey, hashField);

                //con.Close();

                if (redisValue.HasValue)
                {
                    paymentPlans = JsonConvert.DeserializeObject <List <AccountPaymentPlanService.PaymentPlan> >(redisValue);
                }
            }
            catch (Exception e)
            {
                var error = e.Message;
                //TODO: Log: error message for Redis call
            }

            #endregion

            if (paymentPlans == null)
            {
                #region (Plan B) Get data from WCF

                var accountPaymentPlanServiceClient = new AccountPaymentPlanService.AccountPaymentPlanServiceClient();

                try
                {
                    accountPaymentPlanServiceClient.Open();

                    paymentPlans = accountPaymentPlanServiceClient.GetPaymentPlans(true, true).ToList();

                    //Close the connection
                    WCFManager.CloseConnection(accountPaymentPlanServiceClient);
                }
                catch (Exception e)
                {
                    #region Manage Exception

                    string exceptionMessage = e.Message.ToString();

                    var    currentMethod       = System.Reflection.MethodBase.GetCurrentMethod();
                    string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name;

                    // Abort the connection & manage the exception
                    WCFManager.CloseConnection(accountPaymentPlanServiceClient, exceptionMessage, currentMethodString);

                    #endregion
                }

                #endregion
            }

            response.isSuccess    = false;
            response.ErrorMessage = "No upgrade paths available for this plan.";

            AccountPaymentPlanService.PaymentPlan planBeingChecked = null;

            try
            {
                planBeingChecked = paymentPlans.First(p => p.PaymentPlanName.ToLower() == planName.ToLower());
            }
            catch
            {
            }


            if (planBeingChecked != null)
            {
                foreach (var plan in paymentPlans)
                {
                    if (plan.MonthlyRate > planBeingChecked.MonthlyRate && plan.SearchPlan == planBeingChecked.SearchPlan)
                    {
                        response.isSuccess       = true;
                        response.ErrorMessage    = null;
                        response.SuccessMessage += plan.PaymentPlanName + "|";
                    }
                }

                if (response.isSuccess)
                {
                    response.SuccessMessage = "Can upgrade to: " + response.SuccessMessage;
                    var lastIndex = response.SuccessMessage.LastIndexOf("|");
                    response.SuccessMessage = response.SuccessMessage.Remove(lastIndex, 1);
                }
            }



            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Newtonsoft.Json.Formatting.Indented;
            jsonNetResult.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; //<-- Convert UTC times to LocalTime
            jsonNetResult.Data = response;

            return(jsonNetResult);
        }