/// <summary> /// Deletes all medias of the given type, used when deleting a mediatype /// /// Use with care. /// </summary> /// <param name="dt"></param> public static void DeleteFromType(MediaType dt) { //get all document for the document type and order by level (top level first) var medias = Media.GetMediaOfMediaType(dt.Id) .OrderByDescending(x => x.Level); foreach (Media media in medias) { //before we delete this document, we need to make sure we don't end up deleting other documents that //are not of this document type that are children. So we'll move all of it's children to the trash first. foreach (Media m in media.GetDescendants()) { if (m.ContentType.Id != dt.Id) { m.MoveToTrash(); } } media.DeletePermanently(); } }
private Media GetOrCreateMediaFolder(string folderName, int parentId) { var folders = Media.GetMediaOfMediaType(_folderType.Id); return(folders.FirstOrDefault(f => f.Text == folderName && (f.ParentId == parentId || parentId == -1)) ?? CreateMediaFolder(folderName, parentId)); }