Пример #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 }));
        }