Esempio n. 1
0
        internal static void BindModel(ContentItemSave model, IContent persistedContent)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            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 = Current.Mapper.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
                    ContentModelBinderHelper.MapPropertyValuesFromSaved(variant, variant.PropertyCollectionDto);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the model from the request and binds it to the context
        /// </summary>
        /// <param name="actionContext"></param>
        /// <param name="bindingContext"></param>
        /// <returns></returns>
        public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            var model = ContentModelBinderHelper.BindModelFromMultipartRequest <ContentItemSave>(actionContext, bindingContext);

            if (model == null)
            {
                return(false);
            }

            BindModel(model, ContentControllerBase.IsCreatingAction(model.Action) ? CreateNew(model) : GetExisting(model));

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the model from the request and binds it to the context
        /// </summary>
        /// <param name="actionContext"></param>
        /// <param name="bindingContext"></param>
        /// <returns></returns>
        public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            var model = ContentModelBinderHelper.BindModelFromMultipartRequest <MediaItemSave>(actionContext, bindingContext);

            if (model == null)
            {
                return(false);
            }

            model.PersistedContent = ContentControllerBase.IsCreatingAction(model.Action) ? CreateNew(model) : GetExisting(model);

            //create the dto from the persisted model
            if (model.PersistedContent != null)
            {
                model.PropertyCollectionDto = Current.Mapper.Map <IMedia, ContentPropertyCollectionDto>(model.PersistedContent);
                //now map all of the saved values to the dto
                ContentModelBinderHelper.MapPropertyValuesFromSaved(model, model.PropertyCollectionDto);
            }

            model.Name = model.Name.Trim();

            return(true);
        }
Esempio n. 4
0
 public MemberBinder(ServiceContext services)
 {
     _services          = services;
     _modelBinderHelper = new ContentModelBinderHelper();
 }
Esempio n. 5
0
 public ContentItemBinder(ILogger logger, ServiceContext services, IUmbracoContextAccessor umbracoContextAccessor)
 {
     Services           = services;
     _modelBinderHelper = new ContentModelBinderHelper();
 }