コード例 #1
0
ファイル: PagesController.cs プロジェクト: radtek/documentor
        public async Task <IActionResult> Modify(PageModifyCommand modifyCommand)
        {
            if (ModelState.IsValid)
            {
                await _pager.ModifyPageAsync(modifyCommand);

                string newVirtualPath = modifyCommand.VirtualPath.Remove(modifyCommand.VirtualPath.LastIndexOf(Separator.Path) + 1) + modifyCommand.VirtualName;
                return(RedirectToAction(nameof(Index))
                       .Notify(NotificationType.Success, $"Page \"{modifyCommand.Title}\" modified"));
            }
            return(View(modifyCommand));
        }
コード例 #2
0
ファイル: PagesController.cs プロジェクト: radtek/documentor
        public async Task <IActionResult> Modify(string p)
        {
            PageContext pageContext = await _pager.GetPageContextAsync(p);

            PageModifyCommand modifyCommand = new PageModifyCommand
            {
                VirtualPath = pageContext.Path.Location.GetVirtualPath(),
                VirtualName = pageContext.Path.Location.GetDestinationFolder().VirtualName,
                Title       = pageContext.Metadata.Title,
                Description = pageContext.Metadata.Description
            };

            return(View(modifyCommand));
        }
コード例 #3
0
ファイル: Pager.cs プロジェクト: radtek/documentor
        public async Task ModifyPageAsync(PageModifyCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            PagePath pagePath = GetPagePath(command.VirtualPath);

            if (pagePath == null)
            {
                throw new AppException("Page not found");
            }

            _cacheManager.ClearCache("*" + Cache.NavPostfix);

            string pageDirectoryPath = pagePath.Location.GetDirectoryPath();

            PageMetadata pageMetadata = await GetPageMetadataAsync(pagePath);

            pageMetadata.Title       = command.Title;
            pageMetadata.Description = command.Description;
            await _pageIOManager.SaveMetadataAsync(pageDirectoryPath, pageMetadata);

            if (!command.VirtualName.Equals(pagePath.Location.GetDestinationFolder().VirtualName))
            {
                string pagesDirectoryPath   = _pageIOManager.GetPagesDirectory().FullName;
                string oldPageDirectoryName = pagePath.Location.GetDestinationFolder().DirectoryName;
                string newPageDirectoryPath = pageDirectoryPath.Remove(pageDirectoryPath.LastIndexOf(Separator.Path) + 1) +
                                              oldPageDirectoryName.Split(Separator.Sequence)[0] +
                                              Separator.Sequence +
                                              command.VirtualName;
                string fakePageDirectoryPath = newPageDirectoryPath + "_";
                Directory.Move(Path.Combine(pagesDirectoryPath, pageDirectoryPath), Path.Combine(pagesDirectoryPath, fakePageDirectoryPath));
                Directory.Move(Path.Combine(pagesDirectoryPath, fakePageDirectoryPath), Path.Combine(pagesDirectoryPath, newPageDirectoryPath));
            }
        }