示例#1
0
    /// <summary>
    ///     Creates the model from the request and binds it to the context
    /// </summary>
    /// <param name="bindingContext"></param>
    /// <returns></returns>
    public async Task BindModelAsync(ModelBindingContext bindingContext)
    {
        MediaItemSave?model =
            await _modelBinderHelper.BindModelFromMultipartRequestAsync <MediaItemSave>(_jsonSerializer, _hostingEnvironment, bindingContext);

        if (model == null)
        {
            return;
        }

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

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

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

        bindingContext.Result = ModelBindingResult.Success(model);
    }
示例#2
0
    public async Task BindModelAsync(ModelBindingContext bindingContext)
    {
        if (bindingContext == null)
        {
            throw new ArgumentNullException(nameof(bindingContext));
        }

        ContentItemSave?model =
            await _modelBinderHelper.BindModelFromMultipartRequestAsync <ContentItemSave>(_jsonSerializer,
                                                                                          _hostingEnvironment, bindingContext);

        if (model is null)
        {
            return;
        }

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

        BindModel(model, persistedContent !, _modelBinderHelper, _umbracoMapper);

        bindingContext.Result = ModelBindingResult.Success(model);
    }