/// <summary> /// Gets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetProperty(Umbraco.Core.Models.Property property, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (property == null) { return(null); } var mediaService = new MediaService(new RepositoryFactory()); int id; if (!int.TryParse(property.Value.ToString(), out id)) { return(null); } var file = mediaService.GetById(id); if (file != null) { int bytes; int.TryParse(file.Properties["umbracoBytes"].Value.ToString(), out bytes); var img = new File { Id = file.Id, Name = file.Name, Src = file.Properties["umbracoFile"].Value.ToString(), Extension = file.Properties["umbracoExtension"].Value.ToString(), Size = bytes }; return(img); } return(null); }
internal Property(Umbraco.Core.Models.Property property) { _id = property.Id; _property = property; _propertyType = property.PropertyType; //Just to ensure that there is a PropertyType available _pt = PropertyType.GetPropertyType(property.PropertyTypeId); //ensure we have data property editor set if (_pt.DataTypeDefinition.DataType != null) { _data = _pt.DataTypeDefinition.DataType.Data; } else { //send back null we will handle it in ContentControl AddControlNew //and display to use message from the dictionary errors section _data = new DefaultData(null); } _data.PropertyId = Id; //set the value so it doesn't need to go to the database var dvs = _data as IDataValueSetter; if (dvs != null) { dvs.SetValue(property.Value, property.PropertyType.DataTypeDatabaseType.ToString()); } }
internal Property(Umbraco.Core.Models.Property property) { _id = property.Id; _property = property; _propertyType = property.PropertyType; //Just to ensure that there is a PropertyType available _pt = PropertyType.GetPropertyType(property.PropertyTypeId); _data = _pt.DataTypeDefinition.DataType.Data; _data.PropertyId = Id; }
/// <summary> /// Sets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> public override void SetProperty(Umbraco.Core.Models.Property property, object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { throw new NotImplementedException(); /* Image img = value as Image; * var item = field.Item; * * if (field == null) return; * * ImageField scImg = new ImageField(field); * * if (img == null) * { * scImg.Clear(); * return; * } * * if (scImg.MediaID.Guid != img.MediaId) * { * //this only handles empty guids, but do we need to remove the link before adding a new one? * if (img.MediaId == Guid.Empty) * { * ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, scImg.MediaItem.Database.Name, scImg.MediaID, scImg.MediaItem.Paths.Path); * scImg.RemoveLink(link); * } * else * { * ID newId = new ID(img.MediaId); * Item target = item.Database.GetItem(newId); * if (target != null) * { * scImg.MediaID = newId; * ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath); * scImg.UpdateLink(link); * } * else throw new MapperException("No item with ID {0}. Can not update Media Item field".Formatted(newId)); * } * } * * scImg.Height = img.Height.ToString(); * scImg.Width = img.Width.ToString(); * scImg.HSpace = img.HSpace.ToString(); * scImg.VSpace = img.VSpace.ToString(); * scImg.Alt = img.Alt; * scImg.Border = img.Border; * scImg.Class = img.Class;*/ }
internal Property(Umbraco.Core.Models.Property property) { _id = property.Id; _property = property; _propertyType = property.PropertyType; //Just to ensure that there is a PropertyType available _pt = PropertyType.GetPropertyType(property.PropertyTypeId); _data = _pt.DataTypeDefinition.DataType.Data; _data.PropertyId = Id; //set the value so it doesn't need to go to the database var dvs = _data as IDataValueSetter; if (dvs != null) { dvs.SetValue(property.Value, property.PropertyType.DataTypeDatabaseType.ToString()); } }
public static bool HasValues(this Umbraco.Core.Models.Property property) { return(property != null && property.Values.HasValues()); }