Beispiel #1
0
        /// <summary>
        /// Maps a code base custom entity definition into a CustomEntityDefinitionSummary object.
        /// </summary>
        /// <param name="codeDefinition">Code based definition to map.</param>
        public CustomEntityDefinitionSummary Map(ICustomEntityDefinition codeDefinition)
        {
            if (codeDefinition == null)
            {
                throw new ArgumentNullException(nameof(codeDefinition));
            }

            var result = new CustomEntityDefinitionSummary()
            {
                CustomEntityDefinitionCode = codeDefinition.CustomEntityDefinitionCode,
                Description            = codeDefinition.Description,
                ForceUrlSlugUniqueness = codeDefinition.ForceUrlSlugUniqueness,
                Name                = codeDefinition.Name,
                NamePlural          = codeDefinition.NamePlural,
                AutoGenerateUrlSlug = codeDefinition.AutoGenerateUrlSlug,
                AutoPublish         = codeDefinition.AutoPublish,
                HasLocale           = codeDefinition.HasLocale,
                Ordering            = CustomEntityOrdering.None
            };

            result.DataModelType = codeDefinition.GetDataModelType();
            result.Terms         = codeDefinition.GetTerms();

            if (codeDefinition is IOrderableCustomEntityDefinition orderableDefinition)
            {
                result.Ordering = orderableDefinition.Ordering;
            }

            return(result);
        }
        private CustomEntity MapEntity(AddCustomEntityCommand command, CustomEntityDefinitionSummary definition, IExecutionContext executionContext)
        {
            var entity = new CustomEntity();

            _entityAuditHelper.SetCreated(entity, executionContext);

            entity.Locale  = GetLocale(command.LocaleId);
            entity.UrlSlug = command.UrlSlug;
            entity.CustomEntityDefinitionCode = definition.CustomEntityDefinitionCode;

            var version = new CustomEntityVersion();

            version.Title          = command.Title.Trim();
            version.SerializedData = _dbUnstructuredDataSerializer.Serialize(command.Model);
            version.DisplayVersion = 1;

            if (command.Publish)
            {
                entity.SetPublished(executionContext.ExecutionDate, command.PublishDate);
                version.WorkFlowStatusId = (int)WorkFlowStatus.Published;
            }
            else
            {
                entity.PublishStatusCode = PublishStatusCode.Unpublished;
                version.WorkFlowStatusId = (int)WorkFlowStatus.Draft;
            }

            _entityAuditHelper.SetCreated(version, executionContext);
            entity.CustomEntityVersions.Add(version);

            return(entity);
        }
        private async Task ValidateIsUniqueAsync(
            UpdateCustomEntityUrlCommand command,
            CustomEntityDefinitionSummary definition,
            IExecutionContext executionContext
            )
        {
            if (!definition.ForceUrlSlugUniqueness)
            {
                return;
            }

            var query = new IsCustomEntityUrlSlugUniqueQuery();

            query.CustomEntityDefinitionCode = definition.CustomEntityDefinitionCode;
            query.CustomEntityId             = command.CustomEntityId;
            query.LocaleId = command.LocaleId;
            query.UrlSlug  = command.UrlSlug;

            var isUnique = await _queryExecutor.ExecuteAsync(query, executionContext);

            if (!isUnique)
            {
                var message = string.Format("A {0} already exists with the {2} '{1}'",
                                            definition.Name,
                                            command.UrlSlug,
                                            definition.Terms.GetOrDefault(CustomizableCustomEntityTermKeys.UrlSlug, "url slug").ToLower());
                throw new UniqueConstraintViolationException(message, "UrlSlug", command.UrlSlug);
            }
        }
Beispiel #4
0
 public string Details(CustomEntityDefinitionSummary summary, int id)
 {
     if (summary == null)
     {
         return(string.Empty);
     }
     return(List(summary) + id.ToString());
 }
Beispiel #5
0
 public string New(CustomEntityDefinitionSummary summary)
 {
     if (summary == null)
     {
         return(string.Empty);
     }
     return(List(summary) + "new");
 }
Beispiel #6
0
 public string List(CustomEntityDefinitionSummary summary)
 {
     if (summary == null)
     {
         return(string.Empty);
     }
     return("/" + RouteConstants.AdminAreaPrefix + "/" + SlugFormatter.ToSlug(summary.NamePlural) + "#/");
 }
Beispiel #7
0
 public string New(CustomEntityDefinitionSummary definition)
 {
     if (definition == null)
     {
         return(string.Empty);
     }
     return(List(definition) + "new");
 }
        private async Task ValidateIsUniqueAsync(
            AddCustomEntityCommand command,
            CustomEntityDefinitionSummary definition,
            IExecutionContext executionContext
            )
        {
            if (!definition.ForceUrlSlugUniqueness)
            {
                return;
            }

            var query    = GetUniquenessQuery(command, definition);
            var isUnique = await _queryExecutor.ExecuteAsync(query, executionContext);

            EnforceUniquenessResult(isUnique, command, definition);
        }
        private void ValidateCommand(AddCustomEntityCommand command, CustomEntityDefinitionSummary definition)
        {
            if (definition.AutoGenerateUrlSlug)
            {
                command.UrlSlug = SlugFormatter.ToSlug(command.Title);
            }
            else
            {
                command.UrlSlug = SlugFormatter.ToSlug(command.UrlSlug);
            }

            if (command.LocaleId.HasValue && !definition.HasLocale)
            {
                throw ValidationErrorException.CreateWithProperties(definition.NamePlural + " cannot be assigned locales", "LocaleId");
            }
        }
Beispiel #10
0
        /// <summary>
        /// Maps a CustomEntityDefinitionSummary into a CustomEntityDefinitionMicroSummary object.
        /// </summary>
        /// <param name="summary">Instance to map.</param>
        public CustomEntityDefinitionMicroSummary Map(CustomEntityDefinitionSummary summary)
        {
            if (summary == null)
            {
                throw new ArgumentNullException(nameof(summary));
            }

            var result = new CustomEntityDefinitionMicroSummary()
            {
                CustomEntityDefinitionCode = summary.CustomEntityDefinitionCode,
                Description            = summary.Description,
                ForceUrlSlugUniqueness = summary.ForceUrlSlugUniqueness,
                Name       = summary.Name,
                NamePlural = summary.NamePlural
            };

            return(result);
        }
        private async Task SetOrdering(CustomEntity customEntity, CustomEntityDefinitionSummary definition)
        {
            if (definition.Ordering == CustomEntityOrdering.Full)
            {
                var maxOrdering = await _dbContext
                                  .CustomEntities
                                  .MaxAsync(e => e.Ordering);

                if (maxOrdering.HasValue)
                {
                    // don't worry too much about race conditons here
                    // if two entities are added at the same time it's no
                    // big deal if the ordering is tied
                    customEntity.Ordering = maxOrdering.Value + 1;
                }
                else
                {
                    customEntity.Ordering = 0;
                }
            }
        }
Beispiel #12
0
        private async Task <ICustomEntityRoutingRule> GetAndValidateRoutingRuleAsync(
            AddPageCommand command,
            CustomEntityDefinitionSummary definition,
            IExecutionContext executionContext
            )
        {
            var rules = await _queryExecutor.ExecuteAsync(new GetAllCustomEntityRoutingRulesQuery(), executionContext);

            var rule = rules.SingleOrDefault(r => r.RouteFormat == command.CustomEntityRoutingRule);

            if (rule == null)
            {
                throw ValidationErrorException.CreateWithProperties("Routing rule not found", "CustomEntityRoutingRule");
            }

            if (rule.RequiresUniqueUrlSlug && !definition.ForceUrlSlugUniqueness)
            {
                throw ValidationErrorException.CreateWithProperties("Ths routing rule requires a unique url slug, but the selected custom entity does not enforce url slug uniqueness", "CustomEntityRoutingRule");
            }

            return(rule);
        }
Beispiel #13
0
 public string List(CustomEntityDefinitionSummary definition)
 {
     return(GetCustomEntityRoute(definition?.NamePlural));
 }
        private void EnforceUniquenessResult(bool isUnique, AddCustomEntityCommand command, CustomEntityDefinitionSummary definition)
        {
            if (!isUnique)
            {
                string message;
                string prop;

                if (definition.AutoGenerateUrlSlug)
                {
                    // If the slug is autogenerated then we should show the error with the title
                    message = string.Format("The {1} '{0}' must be unique (symbols and spaces are ignored in the uniqueness check)",
                                            command.Title,
                                            definition.Terms.GetOrDefault(CustomizableCustomEntityTermKeys.Title, "title").ToLower());
                    prop = "Title";
                }
                else
                {
                    message = string.Format("The {1} '{0}' must be unique",
                                            command.UrlSlug,
                                            definition.Terms.GetOrDefault(CustomizableCustomEntityTermKeys.UrlSlug, "url slug").ToLower());
                    prop = "UrlSlug";
                }

                throw new UniqueConstraintViolationException(message, prop, command.UrlSlug);
            }
        }
        private IsCustomEntityUrlSlugUniqueQuery GetUniquenessQuery(AddCustomEntityCommand command, CustomEntityDefinitionSummary definition)
        {
            var query = new IsCustomEntityUrlSlugUniqueQuery();

            query.CustomEntityDefinitionCode = definition.CustomEntityDefinitionCode;
            query.LocaleId = command.LocaleId;
            query.UrlSlug  = command.UrlSlug;

            return(query);
        }
 private void Map(UpdateCustomEntityUrlCommand command, CustomEntity entity, CustomEntityDefinitionSummary definition)
 {
     entity.UrlSlug  = command.UrlSlug;
     entity.LocaleId = command.LocaleId;
 }