public async Task <ActionResult> CancelSubscription(CancelSubscriptionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var currentSubscription = (await SubscriptionsFacade.UserActiveSubscriptionsAsync(User.Identity.GetUserId())).FirstOrDefault();
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                DateTime?endDate;  // Because we are passing CancelAtTheEndOfPeriod to EndSubscription, we get the date when the subscription will be cancelled
                if (currentSubscription != null &&
                    (endDate = await SubscriptionsFacade.EndSubscriptionAsync(currentSubscription.Id, user, true, model.Reason)) != null)
                {
                    // TempData.Add("flash", new FlashSuccessViewModel("Your subscription has been cancelled."));
                }
                else
                {
                    // TempData.Add("flash", new FlashDangerViewModel("Sorry, there was a problem cancelling your subscription."));
                }

                return(RedirectToAction("Index", "Billing"));
            }

            return(View(model));
        }
Exemplo n.º 2
0
		public async Task<ActionResult> CancelSubscription(CancelSubscriptionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var currentSubscription = (await SubscriptionsFacade.UserActiveSubscriptionsAsync(User.Identity.GetUserId())).FirstOrDefault();
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                DateTime? endDate; // Because we are passing CancelAtTheEndOfPeriod to EndSubscription, we get the date when the subscription will be cancelled
                if (currentSubscription != null &&
                    (endDate = await SubscriptionsFacade.EndSubscriptionAsync(currentSubscription.Id, user, true, model.Reason)) != null)
                {
                    // TempData.Add("flash", new FlashSuccessViewModel("Your subscription has been cancelled."));
                }
                else
                {
                    // TempData.Add("flash", new FlashDangerViewModel("Sorry, there was a problem cancelling your subscription."));
                }

                return RedirectToAction("Index", "Billing");
            }

			return View(model);
        }