예제 #1
0
        public JsonResult _SetCategory(string threadIds, long categoryId)
        {
            CategoryService categoryService = new CategoryService();
            IUser           currentUser     = UserContext.CurrentUser;


            if (!string.IsNullOrEmpty(threadIds))
            {
                var ids = threadIds.TrimEnd(',').Split(',');
                foreach (var id in ids)
                {
                    categoryService.ClearCategoriesFromItem(long.Parse(id), 0, TenantTypeIds.Instance().BlogThread());
                    categoryService.AddCategoriesToItem(new List <long>()
                    {
                        categoryId
                    }, long.Parse(id), currentUser.UserId);
                }

                return(Json(new StatusMessageData(StatusMessageType.Success, "设置分类成功!")));
            }
            else
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "请选择要设置的日志!")));
            }
        }
예제 #2
0
        public JsonResult _SetCategory(string pageIds, long categoryId)
        {
            IUser user = UserContext.CurrentUser;

            if (!string.IsNullOrEmpty(pageIds))
            {
                string[] pageIdsArray = pageIds.TrimEnd(',').Split(',');
                foreach (string item in pageIdsArray)
                {
                    if (string.IsNullOrEmpty(item))
                    {
                        continue;
                    }

                    categoryService.ClearCategoriesFromItem(long.Parse(item), 0, TenantTypeIds.Instance().WikiPage());
                    categoryService.AddCategoriesToItem(new List <long> {
                        categoryId
                    }, long.Parse(item));
                }
                return(Json(new StatusMessageData(StatusMessageType.Success, "成功设置分类")));
            }
            else
            {
                return(Json(new StatusMessageData(StatusMessageType.Success, "请选择词条")));
            }
        }
예제 #3
0
        public ActionResult Edit(string spaceKey, BlogThreadEditModel model)
        {
            string errorMessage = string.Empty;

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

            BlogThread blogThread = null;

            //写日志
            if (model.ThreadId == 0)
            {
                if (!authorizer.BlogThread_Create(spaceKey, out errorMessage))
                {
                    if (model.IsDraft)
                    {
                        return(Json(new StatusMessageData(StatusMessageType.Error, "没有权限创建新的日志!")));
                    }
                    else
                    {
                        return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                        {
                            Title = "没有权限",
                            Body = errorMessage,
                            StatusMessageType = StatusMessageType.Error
                        })));
                    }
                }

                blogThread = model.AsBlogThread();
                bool isCreated = blogService.Create(blogThread);

                if (!isCreated)
                {
                    if (model.IsDraft)
                    {
                        return(Json(new StatusMessageData(StatusMessageType.Error, "发布失败,请稍后再试!")));
                    }
                    else
                    {
                        return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                        {
                            Title = "发布失败",
                            Body = "发布失败,请稍后再试!",
                            StatusMessageType = StatusMessageType.Error
                        })));
                    }
                }
            }
            //编辑日志
            else
            {
                blogThread = model.AsBlogThread();

                if (!authorizer.BlogThread_Edit(blogThread))
                {
                    if (model.IsDraft)
                    {
                        return(Json(new StatusMessageData(StatusMessageType.Error, "没有权限编辑" + blogThread.Subject + "!")));
                    }
                    else
                    {
                        return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                        {
                            Title = "没有权限",
                            Body = "没有权限编辑" + blogThread.Subject + "!",
                            StatusMessageType = StatusMessageType.Error
                        })));
                    }
                }

                //如果之前是草稿,现在正式发布,那么需要先删除草稿,然后创建新的日志
                BlogThread oldBlogThread = blogService.Get(blogThread.ThreadId);
                if (oldBlogThread.IsDraft && !blogThread.IsDraft)
                {
                    blogService.Delete(oldBlogThread);
                    bool isCreated = blogService.Create(blogThread);
                }
                else
                {
                    blogService.Update(blogThread);

                    //清除用户分类
                    categoryService.ClearCategoriesFromItem(blogThread.ThreadId, blogThread.OwnerId, TenantTypeIds.Instance().BlogThread());

                    if (blogSettings.AllowSetSiteCategory)
                    {
                        //清除站点分类(投稿到)
                        categoryService.ClearCategoriesFromItem(blogThread.ThreadId, 0, TenantTypeIds.Instance().BlogThread());
                    }

                    //清除标签
                    tagService.ClearTagsFromItem(blogThread.ThreadId, blogThread.UserId);
                }
            }

            //设置隐私状态
            UpdatePrivacySettings(blogThread, model.PrivacyStatus1, model.PrivacyStatus2);

            //设置用户分类
            if (!string.IsNullOrEmpty(model.OwnerCategoryIds))
            {
                string[] ownerCategoryIds = model.OwnerCategoryIds.TrimEnd(',').Split(',');
                categoryService.AddCategoriesToItem(ownerCategoryIds.Select(n => long.Parse(n)), blogThread.ThreadId, blogThread.OwnerId);
            }

            if (blogSettings.AllowSetSiteCategory)
            {
                //设置站点分类(投稿到)
                if (model.SiteCategoryId.HasValue)
                {
                    categoryService.AddCategoriesToItem(new List <long> {
                        model.SiteCategoryId.Value
                    }, blogThread.ThreadId, 0);
                }
            }

            string tags = string.Join(",", model.TagNames);

            if (!string.IsNullOrEmpty(tags))
            {
                tagService.AddTagsToItem(tags, blogThread.UserId, blogThread.ThreadId);
            }

            //如果是保存草稿,则返回Json
            if (blogThread.IsDraft)
            {
                return(Json(new { MessageType = StatusMessageType.Success, MessageContent = "保存成功!", ThreadId = blogThread.ThreadId }));
            }
            else
            {
                return(Redirect(SiteUrls.Instance().BlogDetail(spaceKey, blogThread.ThreadId)));
                //return Json(new { MessageType = StatusMessageType.Success, MessageContent = SiteUrls.Instance().BlogDetail(spaceKey, blogThread.ThreadId), ThreadId = blogThread.ThreadId });
            }
        }
        public JsonResult _SetCategory(string threadIds, long categoryId)
        {
            CategoryService categoryService = new CategoryService();
            IUser currentUser = UserContext.CurrentUser;

            if (!string.IsNullOrEmpty(threadIds))
            {
                var ids = threadIds.TrimEnd(',').Split(',');
                foreach (var id in ids)
                {
                    categoryService.ClearCategoriesFromItem(long.Parse(id), 0, TenantTypeIds.Instance().BlogThread());
                    categoryService.AddCategoriesToItem(new List<long>() { categoryId }, long.Parse(id));
                }

                return Json(new StatusMessageData(StatusMessageType.Success, "设置分类成功!"));
            }
            else
            {
                return Json(new StatusMessageData(StatusMessageType.Error, "请选择要设置的文章!"));
            }
        }