Exemple #1
0
        private void Validate(Organisation organisation)
        {
            // Standard validations.

            organisation.Validate();

            // Check that the parent properties are consistent.

            if (organisation.ParentId == null && !string.IsNullOrEmpty(organisation.ParentFullName))
            {
                throw new ValidationErrorsException(new InconsistentValidationError("ParentId", "ParentFullName"));
            }

            // Cannot be its own parent.

            if (organisation.ParentId != null)
            {
                if (organisation.Id == organisation.ParentId.Value)
                {
                    throw new ValidationErrorsException(new CircularValidationError("Parent"));
                }

                // The parent cannot be a descendent.

                if (_repository.IsDescendent(organisation.Id, organisation.ParentId.Value))
                {
                    throw new ValidationErrorsException(new CircularValidationError("Parent"));
                }
            }

            // Unverified organisations can have the same name but verified organisations cannot.

            if (organisation.IsVerified)
            {
                var existingOrganisation = _repository.GetVerifiedOrganisation(organisation.FullName);
                if (existingOrganisation != null && existingOrganisation.Id != organisation.Id)
                {
                    throw new ValidationErrorsException(new DuplicateValidationError("FullName"));
                }
            }
        }
Exemple #2
0
 VerifiedOrganisation IOrganisationsQuery.GetVerifiedOrganisation(string fullName)
 {
     return(_repository.GetVerifiedOrganisation(fullName));
 }