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); } } }
/// <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 = _modelBinderHelper.BindModelFromMultipartRequest <ContentItemSave>(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) { 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 _modelBinderHelper.MapPropertyValuesFromSaved(variant, variant.PropertyCollectionDto); } } return(true); }
/// <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 = _modelBinderHelper.BindModelFromMultipartRequest <MemberSave>(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 <IMember, ContentPropertyCollectionDto>(model.PersistedContent); //now map all of the saved values to the dto _modelBinderHelper.MapPropertyValuesFromSaved(model, model.PropertyCollectionDto); } model.Name = model.Name.Trim(); return(true); }
/// <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 = _modelBinderHelper.BindModelFromMultipartRequest <ContentItemSave>(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) { foreach (var variant in model.Variants) { if (variant.Culture.IsNullOrWhiteSpace()) { //map the property dto collection (no culture is passed to the mapping context so it will be invariant) variant.PropertyCollectionDto = Mapper.Map <ContentPropertyCollectionDto>(model.PersistedContent); } else { //map the property dto collection with the culture of the current variant variant.PropertyCollectionDto = Mapper.Map <ContentPropertyCollectionDto>( model.PersistedContent, options => options.SetCulture(variant.Culture)); } //now map all of the saved values to the dto _modelBinderHelper.MapPropertyValuesFromSaved(variant, variant.PropertyCollectionDto); } } return(true); }