예제 #1
0
        public MediaItemBinder(IJsonSerializer jsonSerializer, IHostingEnvironment hostingEnvironment, IMediaService mediaService, IUmbracoMapper umbracoMapper, IMediaTypeService mediaTypeService)
        {
            _jsonSerializer     = jsonSerializer ?? throw new ArgumentNullException(nameof(jsonSerializer));
            _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
            _mediaService       = mediaService ?? throw new ArgumentNullException(nameof(mediaService));
            _umbracoMapper      = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper));
            _mediaTypeService   = mediaTypeService ?? throw new ArgumentNullException(nameof(mediaTypeService));

            _modelBinderHelper = new ContentModelBinderHelper();
        }
예제 #2
0
        internal static void BindModel(ContentItemSave model, IContent persistedContent, ContentModelBinderHelper modelBinderHelper, IUmbracoMapper umbracoMapper)
        {
            model.PersistedContent = persistedContent;

            //create the dto from the persisted model
            if (model.PersistedContent != null)
            {
                foreach (var variant in model.Variants)
                {
                    //map the property dto collection with the culture of the current variant
                    variant.PropertyCollectionDto = umbracoMapper.Map <ContentPropertyCollectionDto>(
                        model.PersistedContent,
                        context =>
                    {
                        // either of these may be null and that is ok, if it's invariant they will be null which is what is expected
                        context.SetCulture(variant.Culture);
                        context.SetSegment(variant.Segment);
                    });

                    //now map all of the saved values to the dto
                    modelBinderHelper.MapPropertyValuesFromSaved(variant, variant.PropertyCollectionDto);
                }
            }
        }