コード例 #1
0
        public ActionResult AddCompany(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(Json(new { success = false }));
            }

            using (var scope = new TransactionScope())
            {
                var lastMonth = DateTime.Now.AddMonths(-1);

                // Create a new company.
                var newCompany = _companyManager.Create(new Company
                {
                    Name          = name,
                    StartMonth    = lastMonth,
                    TwitterHandle = string.Empty
                });

                // Associate the user to the company.
                _companyManager.AddUser(newCompany.Id, User.Identity.GetUserId <int>(), true);

                // Create a trial subscription
                var subscription = new Subscription {
                    Status = SubscriptionStatus.Trialing
                };
                subscription.AddDays(ConfigUtil.DefaultTrialDuration);
                subscription.CompanyId = newCompany.Id;

                _subscriptionManager.Create(subscription);

                // Complete the scope.
                scope.Complete();
            }

            return(Json(new { success = true }));
        }
コード例 #2
0
        public ActionResult Index()
        {
            var subscription = _subscriptionManager.GetList(new { CompanyId }).FirstOrDefault();
            var company      = _companyManager.Get(CompanyId);
            var owner        = _companyManager.GetOwner(CompanyId);

            if (subscription == null)
            {
                // Create a trial subscription
                subscription = new Subscription {
                    Status = SubscriptionStatus.Trialing
                };
                subscription.AddDays(ConfigUtil.DefaultTrialDuration);
                subscription.CompanyId = company.Id;
                _subscriptionManager.Create(subscription);
            }

            string stripeCardLabel      = "Start Subscription";
            string stripeCardPostTarget = Url.Action("StartSubcription");

            if (subscription.StripeSubscriptionId != null)
            {
                stripeCardLabel      = "Update Card Details";
                stripeCardPostTarget = Url.Action("UpdateCardDetails");
            }

            return(View(new BillingViewModel
            {
                Subscription = subscription,
                Company = company,
                Owner = owner,
                StripeCardLabel = stripeCardLabel,
                StripeCardPostTarget = stripeCardPostTarget,
                HasValidSubscription = HasValidSubscription
            }));
        }