/// <summary> /// Maps the property values to the persisted entity /// </summary> /// <param name="contentItem"></param> protected override void MapPropertyValues <TPersisted>(ContentBaseItemSave <TPersisted> contentItem) { UpdateName(contentItem); //use the base method to map the rest of the properties base.MapPropertyValues(contentItem); }
protected void UpdateName <TPersisted>(ContentBaseItemSave <TPersisted> contentItem) where TPersisted : IContentBase { //Don't update the name if it is empty if (!contentItem.Name.IsNullOrWhiteSpace()) { contentItem.PersistedContent.Name = contentItem.Name; } }
/// <summary> /// Maps the dto property values to the persisted model /// </summary> /// <typeparam name="TPersisted"></typeparam> /// <param name="contentItem"></param> protected virtual void MapPropertyValues <TPersisted>(ContentBaseItemSave <TPersisted> contentItem) where TPersisted : IContentBase { //Map the property values foreach (var property in contentItem.ContentDto.Properties) { //get the dbo property var dboProperty = contentItem.PersistedContent.Properties[property.Alias]; //create the property data to send to the property editor var dictionary = new Dictionary <string, object>(); //add the files if any var files = contentItem.UploadedFiles.Where(x => x.PropertyAlias == property.Alias).ToArray(); if (files.Length > 0) { dictionary.Add("files", files); } foreach (var file in files) { file.FileName = file.FileName.ToSafeFileName(); } // add extra things needed to figure out where to put the files dictionary.Add("cuid", contentItem.PersistedContent.Key); dictionary.Add("puid", dboProperty.PropertyType.Key); var data = new ContentPropertyData(property.Value, property.PreValues, dictionary); //get the deserialized value from the property editor if (property.PropertyEditor == null) { LogHelper.Warn <ContentController>("No property editor found for property " + property.Alias); } else { var valueEditor = property.PropertyEditor.ValueEditor; //don't persist any bound value if the editor is readonly if (valueEditor.IsReadOnly == false) { var propVal = property.PropertyEditor.ValueEditor.ConvertEditorToDb(data, dboProperty.Value); var supportTagsAttribute = TagExtractor.GetAttribute(property.PropertyEditor); if (supportTagsAttribute != null) { TagExtractor.SetPropertyTags(dboProperty, data, propVal, supportTagsAttribute); } else { dboProperty.Value = propVal; } } } } }