Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new domain.
        /// </summary>
        /// <param name="domain">New domain details.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Newly allocated domain identifier.</returns>
        public long Create(Domain domain, IUnitOfWork unitOfWork = null)
        {
            try
            {
                // Perform validation
                _domainValidator.ValidateCreate(domain);

                // Create domain
                return(_domainRepository.Create(domain, unitOfWork));
            }
            catch (ValidationErrorException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates web details before creation. Throws validation error exception if validation fails.
        /// </summary>
        /// <param name="web">The model to validate.</param>
        /// <param name="keyPrefix">Validation key prefix.</param>
        public void ValidateCreate(Web web, string keyPrefix = null)
        {
            // Do stock model validation
            _modelValidator.Validate(web, keyPrefix);

            // A single domain URL must be specified when creating a website
            if (web.Domains == null || web.Domains.Count != 1)
            {
                throw new ValidationErrorException(new ValidationError(WebPropertyNames.FirstDomain + "." + DomainPropertyNames.Url, WebResource.UrlRequiredMessage, keyPrefix));
            }

            // Check web name entered is available
            Web webByName = _webRepository.ReadByName(web.Name);

            if (webByName != null)
            {
                throw new ValidationErrorException(new ValidationError(WebPropertyNames.Name, WebResource.NameNotAvailableMessage, keyPrefix));
            }

            // Validate domain
            _domainValidator.ValidateCreate(web.Domains[0], WebPropertyNames.FirstDomain);
        }