/// <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;
        }
Ejemplo n.º 2
0
        /// <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);
        }