Ejemplo n.º 1
0
        public ActionResult Move(string folderPath, int[] mediaItemIds)
        {
            // check permission on destination folder
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.ImportMediaContent, folderPath))
            {
                Services.Notifier.Error(T("Couldn't move media items"));
                return(new HttpUnauthorizedResult());
            }

            if (!_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            foreach (var media in Services.ContentManager.Query().ForPart <MediaPart>().ForContentItems(mediaItemIds).List())
            {
                // don't try to rename the file if there is no associated media file
                if (!string.IsNullOrEmpty(media.FileName))
                {
                    // check permission on source folder
                    if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.DeleteMediaContent, media.FolderPath))
                    {
                        return(new HttpUnauthorizedResult());
                    }
                    var uniqueFilename = _mediaLibraryService.GetUniqueFilename(folderPath, media.FileName);
                    _mediaLibraryService.MoveFile(media.FolderPath, media.FileName, folderPath, uniqueFilename);
                    media.FileName = uniqueFilename;
                }

                media.FolderPath = folderPath;
            }

            return(Json(true));
        }
Ejemplo n.º 2
0
        public ActionResult Move(string folderPath, int[] mediaItemIds)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia, T("Couldn't move media items")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (!_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            foreach (var media in Services.ContentManager.Query().ForPart <MediaPart>().ForContentItems(mediaItemIds).List())
            {
                // don't try to rename the file if there is no associated media file
                if (!string.IsNullOrEmpty(media.FileName))
                {
                    var uniqueFilename = _mediaLibraryService.GetUniqueFilename(folderPath, media.FileName);
                    _mediaLibraryService.MoveFile(media.FolderPath, media.FileName, folderPath, uniqueFilename);
                    media.FileName = uniqueFilename;
                }

                media.FolderPath = folderPath;
            }

            return(Json(true));
        }