/// <summary> /// Accesses the <see cref="MediaTypeAttribute"/> applied to a class to find /// the media type alias for that class /// </summary> /// <param name="input">The media type instance to get the alias for</param> /// <returns>the media type alias</returns> /// <exception cref="CodeFirstException">Thrown if the specified type does not have a <see cref="MediaTypeAttribute"/> attribute.</exception> public static string GetMediaTypeAlias(this MediaTypeBase input) { try { return(input.GetType().GetCodeFirstAttribute <MediaTypeAttribute>().Alias); } catch (Exception e) { throw new CodeFirstException(input.GetType().Name, e); } }
public IMedia ConvertToContent(MediaTypeBase model, int parentId = -1) { var contentId = model.NodeDetails.UmbracoId; MediaTypeRegistration registration; _mediaTypeModule.TryGetMediaType(model.GetType(), out registration); if (registration == null) { throw new CodeFirstException("Media type not registered. Type: " + model.GetType()); } //Create or update object if (contentId == -1) { return(CreateContent(parentId, model, registration)); } else { return(UpdateContent(model, registration)); } }
public void ProjectModelToContent(MediaTypeBase model, IMedia content) { var type = model.GetType(); MediaTypeRegistration reg; if (_mediaTypeModule.TryGetMediaType(type, out reg) && (reg.ClrType == type || reg.ClrType.Inherits(type))) { MapModelToContent(content, model, reg); if (model.MediaFile != null && content.HasProperty("umbracoFile")) { content.SetValue("umbracoFile", System.IO.Path.GetFileNameWithoutExtension(model.MediaFile.Name), model.MediaFile); } } }