Example #1
0
        /// <summary>
        ///     Validates the composition and adds errors to the model state if any are found then throws an error response if
        ///     there are errors
        /// </summary>
        /// <param name="contentTypeSave"></param>
        /// <param name="composition"></param>
        /// <returns></returns>
        private TContentTypeDisplay?CreateCompositionValidationExceptionIfInvalid <TContentTypeSave, TPropertyType,
                                                                                   TContentTypeDisplay>(TContentTypeSave contentTypeSave, TContentType?composition)
            where TContentTypeSave : ContentTypeSave <TPropertyType>
            where TPropertyType : PropertyTypeBasic
            where TContentTypeDisplay : ContentTypeCompositionDisplay
        {
            IContentTypeBaseService <TContentType>?service = GetContentTypeService <TContentType>();
            Attempt <string[]?> validateAttempt            = service?.ValidateComposition(composition) ?? Attempt.Fail <string[]?>();

            if (validateAttempt == false)
            {
                // if it's not successful then we need to return some model state for the property type and property group
                // aliases that are duplicated
                IEnumerable <string>?duplicatePropertyTypeAliases = validateAttempt.Result?.Distinct();
                var invalidPropertyGroupAliases =
                    (validateAttempt.Exception as InvalidCompositionException)?.PropertyGroupAliases ??
                    Array.Empty <string>();

                AddCompositionValidationErrors <TContentTypeSave, TPropertyType>(contentTypeSave,
                                                                                 duplicatePropertyTypeAliases, invalidPropertyGroupAliases);

                TContentTypeDisplay?display = UmbracoMapper.Map <TContentTypeDisplay>(composition);
                //map the 'save' data on top
                display = UmbracoMapper.Map(contentTypeSave, display);
                if (display is not null)
                {
                    display.Errors = ModelState.ToErrorDictionary();
                }

                return(display);
            }

            return(null);
        }
Example #2
0
 protected ContentTypeBaseSerializer(
     IEntityService entityService, ILogger logger,
     IDataTypeService dataTypeService,
     IContentTypeBaseService <TObject> baseService,
     UmbracoObjectTypes containerType)
     : base(entityService, logger, containerType)
 {
     this.dataTypeService = dataTypeService;
     this.baseService     = baseService;
 }