private void RegisterAdministratorFor(
            Tenant tenant,
            FullName administorName,
            EmailAddress emailAddress,
            PostalAddress postalAddress,
            Telephone primaryTelephone,
            Telephone secondaryTelephone)
        {
            RegistrationInvitation invitation = tenant.OfferRegistrationInvitation("init").OpenEnded();
            string strongPassword             = new PasswordService().GenerateStrongPassword();

            // Publishes domain event UserRegistered.
            User admin = tenant.RegisterUser(
                invitation.InvitationId,
                "admin",
                strongPassword,
                Enablement.IndefiniteEnablement(),
                new Person(
                    tenant.TenantId,
                    administorName,
                    new ContactInformation(
                        emailAddress,
                        postalAddress,
                        primaryTelephone,
                        secondaryTelephone)));

            tenant.WithdrawInvitation(invitation.InvitationId);

            // Since this is a new entity, add it to
            // the collection-oriented repository.
            // Subsequent changes to the entity
            // are implicitly persisted.
            _userRepository.Add(admin);

            // Publishes domain event RoleProvisioned.
            Role adminRole = tenant.ProvisionRole(
                "Administrator",
                string.Format("Default {0} administrator.", tenant.Name));

            // Publishes domain event UserAssignedToRole,
            // but not GroupUserAdded because the group
            // reference held by the role is an "internal" group.
            adminRole.AssignUser(admin);

            // Since this is a new entity, add it to
            // the collection-oriented repository.
            // Subsequent changes to the entity
            // are implicitly persisted.
            _roleRepository.Add(adminRole);

            DomainEventPublisher
            .Instance
            .Publish(new TenantAdministratorRegistered(
                         tenant.TenantId,
                         tenant.Name,
                         administorName,
                         emailAddress,
                         admin.Username,
                         strongPassword));
        }
Esempio n. 2
0
        public bool IsRegistrationAvailableThrough(string invitationIdentifier)
        {
            AssertionConcern.AssertStateTrue(this.Active, "Tenant is not active.");

            RegistrationInvitation invitation = this.GetInvitation(invitationIdentifier);

            return((invitation != null) && invitation.IsAvailable());
        }
Esempio n. 3
0
        public void WithdrawInvitation(string invitationIdentifier)
        {
            RegistrationInvitation invitation = this.GetInvitation(invitationIdentifier);

            if (invitation != null)
            {
                this.registrationInvitations.Remove(invitation);
            }
        }
Esempio n. 4
0
        public RegistrationInvitation OfferRegistrationInvitation(string description)
        {
            AssertionConcern.AssertStateTrue(this.Active, "Tenant is not active.");
            AssertionConcern.AssertArgumentTrue(this.IsRegistrationAvailableThrough(description), "Invitation already exists.");

            RegistrationInvitation invitation = new RegistrationInvitation(this.TenantId, new Guid().ToString(), description);

            AssertionConcern.AssertStateTrue(this.registrationInvitations.Add(invitation), "The invitation should have been added.");

            return(invitation);
        }
Esempio n. 5
0
        public RegistrationInvitation RedefineRegistrationInvitationAs(string invitationIdentifier)
        {
            AssertionConcern.AssertStateTrue(this.Active, "Tenant is not active.");

            RegistrationInvitation invitation = this.GetInvitation(invitationIdentifier);

            if (invitation != null)
            {
                invitation.RedefineAs().OpenEnded();
            }

            return(invitation);
        }
Esempio n. 6
0
        public RegistrationInvitation OfferRegistrationInvitation(string description)
        {
            AssertionConcern.AssertStateTrue(this.Active, "Tenant is not active.");
            AssertionConcern.AssertArgumentTrue(this.IsRegistrationAvailableThrough(description), "Invitation already exists.");

            RegistrationInvitation invitation =
                new RegistrationInvitation(
                        this.TenantId,
                        new Guid().ToString(),
                        description);

            AssertionConcern.AssertStateTrue(this.RegistrationInvitations.Add(invitation), "The invitation should have been added.");

            return invitation;
        }