Пример #1
0
        public ActionResult Clone(int mediaItemId)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't clone media items")))
            {
                return(new HttpUnauthorizedResult());
            }

            try {
                var media = Services.ContentManager.Get(mediaItemId).As <MediaPart>();

                var newFileName = Path.GetFileNameWithoutExtension(media.FileName) + " Copy" + Path.GetExtension(media.FileName);

                _mediaLibraryService.CopyFile(media.FolderPath, media.FileName, media.FolderPath, newFileName);

                var clonedContentItem = Services.ContentManager.Clone(media.ContentItem);
                var clonedMediaPart   = clonedContentItem.As <MediaPart>();
                var clonedTitlePart   = clonedContentItem.As <TitlePart>();

                clonedMediaPart.FileName = newFileName;
                clonedTitlePart.Title    = clonedTitlePart.Title + " Copy";

                Services.ContentManager.Publish(clonedContentItem);

                return(Json(true));
            }
            catch (Exception e) {
                Logger.Error(e, "Could not clone media item.");
                return(Json(false));
            }
        }
        public ActionResult Clone(int mediaItemId)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia))
            {
                Services.Notifier.Add(UI.Notify.NotifyType.Error, T("Couldn't clone media items"));
                return(new HttpUnauthorizedResult());
            }

            try {
                var media = Services.ContentManager.Get(mediaItemId).As <MediaPart>();

                if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.ImportMediaContent, media.FolderPath))
                {
                    return(Json(false));
                }

                var newFileName = _mediaLibraryService.GetUniqueFilename(media.FolderPath, media.FileName);

                var settings = Services.WorkContext.CurrentSite.As <MediaLibrarySettingsPart>();

                // skip file if the allowed extensions is defined and doesn't match
                if (!settings.IsFileAllowed(Path.GetFileName(newFileName)))
                {
                    return(Json(false));
                }

                _mediaLibraryService.CopyFile(media.FolderPath, media.FileName, media.FolderPath, newFileName);

                var clonedContentItem = Services.ContentManager.Clone(media.ContentItem);
                var clonedMediaPart   = clonedContentItem.As <MediaPart>();
                var clonedTitlePart   = clonedContentItem.As <TitlePart>();

                clonedMediaPart.FileName   = newFileName;
                clonedMediaPart.FolderPath = media.FolderPath;
                clonedMediaPart.MimeType   = media.MimeType;
                clonedTitlePart.Title      = clonedTitlePart.Title + " Copy";
                Services.ContentManager.Create(clonedContentItem);
                Services.ContentManager.Publish(clonedContentItem);

                return(Json(true));
            }
            catch (Exception e) {
                Logger.Error(e, "Could not clone media item.");
                return(Json(false));
            }
        }
Пример #3
0
        public ActionResult Clone(int mediaItemId)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia, T("Couldn't clone media items")))
            {
                return(new HttpUnauthorizedResult());
            }

            try {
                var media = Services.ContentManager.Get(mediaItemId).As <MediaPart>();

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

                var newFileName = _mediaLibraryService.GetUniqueFilename(media.FolderPath, media.FileName);

                _mediaLibraryService.CopyFile(media.FolderPath, media.FileName, media.FolderPath, newFileName);

                var clonedContentItem = Services.ContentManager.Clone(media.ContentItem);
                var clonedMediaPart   = clonedContentItem.As <MediaPart>();
                var clonedTitlePart   = clonedContentItem.As <TitlePart>();

                clonedMediaPart.FileName   = newFileName;
                clonedMediaPart.FolderPath = media.FolderPath;
                clonedMediaPart.MimeType   = media.MimeType;
                clonedTitlePart.Title      = clonedTitlePart.Title + " Copy";
                Services.ContentManager.Create(clonedContentItem);
                Services.ContentManager.Publish(clonedContentItem);

                return(Json(true));
            }
            catch (Exception e) {
                Logger.Error(e, "Could not clone media item.");
                return(Json(false));
            }
        }