/// <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 || property.Value == 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; }
/// <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 image = mediaService.GetById(id); if (image != null) { int width; int.TryParse(image.Properties["umbracoWidth"].Value.ToString(), out width); int height; int.TryParse(image.Properties["umbracoHeight"].Value.ToString(), out height); int bytes; int.TryParse(image.Properties["umbracoBytes"].Value.ToString(), out bytes); var img = new Image { Id = image.Id, Alt = image.Name, Src = image.Properties["umbracoFile"].Value.ToString(), Width = width, Height = height, Extension = image.Properties["umbracoExtension"].Value.ToString(), Size = bytes }; return img; } return null; }