示例#1
0
        public ActionResult Edit()
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't edit media folder")))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new MediaManagerFolderEditViewModel();

            UpdateModel(viewModel);

            try {
                _mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name);

                var segments      = viewModel.FolderPath.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                var newFolderPath = String.Join(Path.DirectorySeparatorChar.ToString(), segments.Take(segments.Length - 1).Union(new [] { viewModel.Name }));

                foreach (var media in Services.ContentManager.Query().ForPart <MediaPart>().Where <MediaPartRecord>(m => m.FolderPath.StartsWith(viewModel.FolderPath)).List())
                {
                    media.FolderPath = newFolderPath + media.FolderPath.Substring(viewModel.FolderPath.Length);
                }
                Services.Notifier.Information(T("Media folder renamed"));
            }
            catch (ArgumentException argumentException) {
                Services.Notifier.Error(T("Editing Folder failed: {0}", argumentException.Message));
                Services.TransactionManager.Cancel();
                return(View(viewModel));
            }

            return(RedirectToAction("Index", "Admin", new { area = "Orchard.MediaLibrary" }));
        }
示例#2
0
        public ActionResult Edit()
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia, T("Couldn't edit media folder")))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new MediaManagerFolderEditViewModel();

            UpdateModel(viewModel);

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

            // Shouldn't be able to rename the root folder
            if (IsRootFolder(viewModel.FolderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            try {
                _mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name);
                Services.Notifier.Information(T("Media folder renamed"));
            }
            catch (Exception exception) {
                Services.Notifier.Error(T("Editing Folder failed: {0}", exception.Message));
                return(View(viewModel));
            }

            return(RedirectToAction("Index", "Admin", new { area = "Tomelt.MediaLibrary" }));
        }
示例#3
0
        public ActionResult Edit()
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia))
            {
                Services.Notifier.Error(T("Couldn't edit media folder"));
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new MediaManagerFolderEditViewModel();

            UpdateModel(viewModel);

            if (!(_mediaLibraryService.CheckMediaFolderPermission(Permissions.ImportMediaContent, viewModel.FolderPath) ||
                  _mediaLibraryService.CheckMediaFolderPermission(Permissions.EditMediaContent, viewModel.FolderPath)))
            {
                return(new HttpUnauthorizedResult());
            }

            // Shouldn't be able to rename the root folder
            if (IsRootFolder(viewModel.FolderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            try {
                bool valid = String.IsNullOrWhiteSpace(viewModel.Name) || Regex.IsMatch(viewModel.Name, @"^[^:?#\[\]@!$&'()*+,.;=\s\""\<\>\\\|%]+$");
                if (!valid)
                {
                    throw new ArgumentException(T("Folder contains invalid characters").ToString());
                }
                else
                {
                    _mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name);
                    Services.Notifier.Information(T("Media folder renamed"));
                }
            }
            catch (Exception exception) {
                Services.Notifier.Error(T("Editing Folder failed: {0}", exception.Message));
                return(View(viewModel));
            }

            return(RedirectToAction("Index", "Admin", new { area = "Orchard.MediaLibrary" }));
        }
示例#4
0
        public void RenameImageGallery(string imageGalleryName, string newName)
        {
            string mediaPath = GetMediaPath(imageGalleryName);

            _mediaService.RenameFolder(mediaPath, newName);

            ImageGallerySettingsRecord settings = GetImageGallerySettings(imageGalleryName);

            if (settings != null)
            {
                settings.ImageGalleryName = newName;
                _repository.Update(settings);
            }

            IEnumerable <ImageGalleryRecord> records = _imageGalleryPartRepository.Fetch(partRecord => partRecord.ImageGalleryName == imageGalleryName);

            foreach (ImageGalleryRecord imageGalleryRecord in records)
            {
                imageGalleryRecord.ImageGalleryName = newName;
                _imageGalleryPartRepository.Update(imageGalleryRecord);
            }
        }