Пример #1
0
        public ActionResult EditPage(long?pageId, long?ownerId, long?questionId)
        {
            if (UserContext.CurrentUser == null)
            {
                return(Redirect(SiteUrls.Instance().Login(true)));
            }

            if (!pageId.HasValue)
            {
                pageId = 0;
            }

            //声明必要的对象
            WikiPage          page          = null;
            WikiPageEditModel pageEditModel = null;

            //输入的wikiId是否有效
            if (pageId.HasValue && pageId.Value > 0)//编辑词条
            {
                page = wikiService.Get(pageId.Value);
                if (page == null)
                {
                    return(HttpNotFound());
                }
            }
            int ModuleSpeechCategoryId = Convert.ToInt32(ConfigurationManager.AppSettings["HaierSpeechModelFolderId"]);
            //百科分类
            IEnumerable <Category> siteCategories = categoryService.GetOwnerCategories(0, TenantTypeIds.Instance().WikiPage());

            ViewData["ownerCategories"] = siteCategories;

            if (pageId.HasValue && pageId.Value > 0)//编辑词条
            {
                pageResourceManager.InsertTitlePart("编辑词条");
                page          = wikiService.Get(pageId.Value);
                pageEditModel = page.AsEditModel();
            }
            else//创建词条
            {
                pageResourceManager.InsertTitlePart("新建词条");
                pageEditModel = new WikiPageEditModel();
                if (ownerId.HasValue)
                {
                    pageEditModel.OwnerId = ownerId.Value;
                }
                if (questionId.HasValue && questionId.Value > 0)
                {
                    string title = string.Empty;
                    string body  = string.Empty;
                    wikiService.GetAskTitleAndBody(questionId.Value, out title, out body);
                    pageEditModel.Title = title;
                    pageEditModel.Body  = body;
                }
            }

            return(View(pageEditModel));
        }
Пример #2
0
        public IActionResult Save(WikiPageEditModel item)
        {
            WikiPageBO bo = new WikiPageBO()
            {
                Title        = item.Title,
                BodyMarkDown = item.Markdown
            };

            WikiPageDTO page = service.Save(bo);

            return(Redirect("/wiki/" + page.Slug));
        }
Пример #3
0
        public IActionResult Edit(string slug)
        {
            WikiPageDTO       page  = service.GetPage(slug);
            WikiPageEditModel model = null;


            if (page == null)
            {
                model = new WikiPageEditModel()
                {
                    Title    = slug,
                    Markdown = "## " + slug
                };
            }
            else
            {
                model = new WikiPageEditModel()
                {
                    Title    = page.Title,
                    Markdown = page.BodyMarkDown
                };
            }
            return(View(model));
        }
Пример #4
0
        public ActionResult EditPage(WikiPageEditModel editModel)
        {
            if (UserContext.CurrentUser == null)
            {
                return(Redirect(SiteUrls.Instance().Login(true)));
            }

            //声明必要的变量
            WikiPage        page        = null;
            WikiPageVersion pageVersion = null;

            #region 敏感词过滤

            string errorMessage = string.Empty;
            if (ModelState.HasBannedWord(out errorMessage))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Title = "发布失败",
                    Body = errorMessage,
                    StatusMessageType = StatusMessageType.Error
                })));
            }

            #endregion

            if (editModel.PageId < 1)//新建词条
            {
                page = editModel.AsWikiPage();
                bool valid = wikiService.IsExists(page.Title);
                if (valid)
                {
                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Title = "发布同名词条失败",
                        Body = "发布失败,请稍后再试!",
                        StatusMessageType = StatusMessageType.Error
                    })));
                }

                bool isCreated = wikiService.Create(page, editModel.Body);

                if (page.PageId < 1)
                {
                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Title = "发布失败",
                        Body = "发布失败,请稍后再试!",
                        StatusMessageType = StatusMessageType.Error
                    })));
                }

                pageVersion = page.LastestVersion;
            }
            else//编辑词条
            {
                //userFocusCategoryService.del
                page = wikiService.Get(editModel.PageId);
                if (page == null)
                {
                    return(HttpNotFound());
                }

                //判断一下是否可以编辑
                bool  IsCanEdit = !page.IsLocked;
                IUser user      = UserContext.CurrentUser;
                if (page.OwnerId == user.UserId || DIContainer.Resolve <Authorizer>().IsAdministrator(ApplicationIds.Instance().Wiki()))
                {
                    IsCanEdit = true;
                }
                if (!IsCanEdit)
                {
                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Title = "编辑失败",
                        Body = "编辑失败,该词条已经被锁定,请稍后再试!",
                        StatusMessageType = StatusMessageType.Error
                    })));
                }


                categoryService.DeleteItemInCategory(page.SiteCategory.CategoryId, page.PageId);

                page = editModel.AsWikiPage();

                wikiService.Update(page);

                pageVersion        = editModel.AsWikiPageVersion();
                pageVersion.PageId = page.PageId;
                wikiService.CreatePageVersion(pageVersion);

                if (pageVersion.VersionId < 1)
                {
                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Title = "编辑失败",
                        Body = "编辑失败,请稍后再试!",
                        StatusMessageType = StatusMessageType.Error
                    })));
                }
            }

            #region 分类、标签

            if (editModel.SiteCategoryId > 0)
            {
                categoryService.AddCategoriesToItem(new List <long> {
                    editModel.SiteCategoryId
                }, page.PageId);
            }
            string tags = string.Join(",", editModel.TagNames);
            if (!string.IsNullOrEmpty(tags))
            {
                tagService.ClearTagsFromItem(page.PageId, pageVersion.UserId);
                tagService.AddTagsToItem(tags, pageVersion.UserId, page.PageId);
            }

            #endregion


            return(Redirect(SiteUrls.Instance().PageDetail(page.PageId)));
        }