Esempio n. 1
0
        public ActionResult ChangeSubscription(ChangeSubscriptionModel model)
        {
            if (ModelState.IsValid)
            {
                ChangeSubscriptionRequest request = new ChangeSubscriptionRequest
                {
                    CustomerId = Customer.CustomerId,
                    ChangeSubscriptionModel = model,
                    PlanId = model.PlanId
                };
                ChangeSubscriptionResponse response = _subscriptionsService.ChangeSubscription(request);

                if (response.IsStatusActive)
                {
                    return(RedirectToAction("index", "subscriptions").AndAlert(AlertType.Danger, "Error.",
                                                                               "Previous subscription wasn't cancelled."));
                }

                if (response.ErrorCode == ErrorCode.IncorrectPlanIdentifier)
                {
                    throw new Exception(response.ErrorCode.ToString());
                }

                if (response.Result != "active")
                {
                    return(RedirectToAction("index", "subscriptions")
                           .AndAlert(AlertType.Danger, "Error.", response.Message));
                }

                return(RedirectToAction("index").AndAlert(AlertType.Success, "Changed.",
                                                          "The subscription was changed successfully."));
            }

            model.Plans = _planService.List();
            return(View("ChangeSubscription", model));
        }