Beispiel #1
0
        public Guid Provision(CustomersProvisionModel model)
        {
            var fullName = model.FirstName + " " + model.LastName;

            //create customer in stripe
            StripeCustomer stripeCustomer = StripeFactory.GetStripeService().CreateCustomer(fullName, model.Email);

            // Customer
            Customer customer = new Customer(fullName, model.Domain, model.Company, stripeCustomer.Id)
            {
                PlanCreatedOn = stripeCustomer.Created
            };

            _customerRepository.Add(customer);

            // roles
            var role = new Role(customer, "Administrator", true, UserType.SystemUser);

            _roleRepository.Add(role);

            // users
            var user = new User(customer, model.Email, model.FirstName, model.LastName, model.Password, true);

            _userRepository.Add(user);
            role.AddUser(user);
            customer.UpdateAdminUser(user);

            // security questions
            ReferenceList referenceList = _referenceListRepository.Query().SingleOrDefault(l => l.SystemName == "Security Questions");

            foreach (var securityQuestion in SecurityQuestions.Questions)
            {
                referenceList.AddItem(customer, securityQuestion);
            }

            // user security questions
            user.AddSecurityQuestion("a", "a");
            user.AddSecurityQuestion("b", "b");
            user.AddSecurityQuestion("c", "c");

            _unitOfWork.Commit();

            return(customer.Id);
        }