コード例 #1
0
    /// <summary>
    /// 绑定资讯列表
    /// </summary>
    private void BindTreeList()
    {
        //ddlArticleCategory.Items.Clear();

        List <ArticleCategory> cates = ArticleManager.GetAllCategories();

        BindTreeItem(cates, null, 0);
    }
コード例 #2
0
        public async Task <ActionResult> EditArticle(Guid?articleId, string title, string content, string introContent, Guid[] categoryIds)
        {
            //id和内容和标题为空、未登录、登陆id不是这篇文章的拥有者、分类id不属于自己
            if (articleId == null || articleId == Guid.Empty || title == null || content == null || title.Trim() == "" || content.Trim() == "") //提交的信息为空
            {
                return(Json(new { status = "fail", result = "提交的信息不完整,请重试" }, JsonRequestBehavior.AllowGet));                                   //返回错误信息
            }
            //获取当前登陆的id,cookie的id需要解密
            string userCookieId = ""; string message;

            if (Request.Cookies["userId"] != null)
            {
                if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message))
                {
                    return(Json(new { status = "fail", result = message }, JsonRequestBehavior.AllowGet));//返回错误信息
                }
            }
            string userId = Session["userId"] == null ? userCookieId : Session["userId"].ToString();

            if (userId == null || userId.Trim() == "")                                                            //用户未登录
            {
                return(Json(new { status = "fail", result = "获取不到用户信息,请检查登陆状态" }, JsonRequestBehavior.AllowGet)); //返回错误信息
            }
            //查找提交的文章id是否存在,是否属于当前登陆用户
            IArticleManager articleManager = new ArticleManager();

            if (!await articleManager.ExistsArticle(articleId.Value))                                              //文章id找不到则跳转文章不存在错误页面
            {
                return(Json(new { status = "fail", result = "未能找到对应ID的文章,请稍后再试" }, JsonRequestBehavior.AllowGet)); //返回错误信息
            }
            var data = await articleManager.GetOneArticleById(articleId.Value);                                    //要经过上面的判断否则会出错

            if (data.userId != Guid.Parse(userId))                                                                 //文章作者才可编辑文章
            {
                return(Json(new { status = "fail", result = "非本人文章不可进行编辑" }, JsonRequestBehavior.AllowGet));       //返回错误信息
            }
            //提交的分类信息不为空,循环自己所有的分类,对比是否正确
            if (categoryIds != null)
            {
                List <BlogCategoryDto> categoryDtoes = await articleManager.GetAllCategories(Guid.Parse(userId)); //获取分类对象集合

                List <Guid> currentUserCategoryIds = new List <Guid>();                                           //将分类对象中的分类id整合进一个集合中
                foreach (BlogCategoryDto category in categoryDtoes)
                {
                    currentUserCategoryIds.Add(category.Id);
                }
                for (int i = 0; i < categoryIds.Length; i++)              //循环检查提交的分类id是否和自身的分类id有对应
                {
                    if (!currentUserCategoryIds.Contains(categoryIds[i])) //如果提交的分类id与自身的分类id没有匹配项,提示错误
                    {
                        return(Json(new { status = "fail", result = "提交的分类与用户所拥有的分类不匹配,请重试!" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            await articleManager.EditArticle(articleId.Value, title, content, introContent, categoryIds);

            return(Json(new { status = "ok", result = "提交成功!", articleId = articleId.Value }, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public async Task <ActionResult> EditCategory(Guid categoryId, string newCategoryName)
        {
            //未登陆、系统内置、重名、信息为空、当前用户不是分类的拥有者不可编辑
            if (categoryId == null || newCategoryName == null || categoryId == Guid.Empty || newCategoryName.Trim() == "")
            {
                return(Json(new { status = "fail", result = "提交的数据不完整,请重试!" }, JsonRequestBehavior.AllowGet));
            }
            //获取当前登陆的id,cookie的id需要解密
            string userCookieId = ""; string message;

            if (Request.Cookies["userId"] != null)
            {
                if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message))
                {
                    return(Json(new { status = "fail", result = message }, JsonRequestBehavior.AllowGet));
                }
            }
            string userId = Session["userId"] == null ? userCookieId : Session["userId"].ToString();

            if (userId.Trim() == "")
            {
                return(Json(new { status = "fail", result = "还未登陆无法编辑" }, JsonRequestBehavior.AllowGet));
            }
            IArticleManager articleManager = new ArticleManager();

            if (!await articleManager.ExistsCategory(categoryId))//分类id不存在
            {
                return(Json(new { status = "fail", result = "未能找到对应ID的分类,请稍后再试" }, JsonRequestBehavior.AllowGet));
            }
            var data = await articleManager.GetOneCategoryById(categoryId); //要经过上面的判断否则会出错

            if (data.UserId != Guid.Parse(userId))                          //分类作者才可编辑分类
            {
                if (data.UserId == Guid.Parse("00000000-0000-0000-0000-000000000001"))
                {
                    return(Json(new { status = "fail", result = "系统内置分类不可进行编辑" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { status = "fail", result = "非本人分类不可进行编辑" }, JsonRequestBehavior.AllowGet));
                }
            }
            //循环自己所有的分类,对比是否有重名
            List <BlogCategoryDto> categories = await articleManager.GetAllCategories(Guid.Parse(userId));

            foreach (BlogCategoryDto category in categories)
            {
                if (category.BlogCategoryName == newCategoryName)//修改后的名字和现有的重复,则提示失败
                {
                    return(Json(new { status = "fail", result = "该名字已存在,请修改后重试!" }, JsonRequestBehavior.AllowGet));
                }
            }
            await articleManager.EditCategory(categoryId, newCategoryName);

            return(Json(new { status = "ok", result = "编辑成功!" }, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public async Task <ActionResult> GetMoreCategories(Guid?userId)
        {
            IUserManager userManager = new UserManager();

            if (userId == null || !await userManager.ExistsUser(userId.Value))
            {
                return(Json(new { status = "fail", result = "获取用户信息失败!" }, JsonRequestBehavior.AllowGet));
            }
            var articleManager          = new ArticleManager();
            List <BlogCategoryDto> data = await articleManager.GetAllCategories(userId.Value);

            return(Json(new { status = "ok", data, userId }, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public async Task <ActionResult> AddArticle(string title, string content, string introContent, Guid[] categoryIds)
        {
            //未登录、内容不为空、标题不为空、分类id不属于自己
            if (title == null || content == null || title.Trim() == "" || content.Trim() == "")               //提交的信息为空
            {
                return(Json(new { status = "fail", result = "提交的信息不完整,请重试" }, JsonRequestBehavior.AllowGet)); //返回错误信息
            }
            //获取当前登陆的id,cookie的id需要解密
            string userCookieId = ""; string message;

            if (Request.Cookies["userId"] != null)
            {
                if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message))
                {
                    return(Json(new { status = "fail", result = message }, JsonRequestBehavior.AllowGet));//返回错误信息
                }
            }
            string userId = Session["userId"] == null ? userCookieId : Session["userId"].ToString();

            if (userId == null || userId.Trim() == "")                                                            //用户未登录
            {
                return(Json(new { status = "fail", result = "获取不到用户信息,请检查登陆状态" }, JsonRequestBehavior.AllowGet)); //返回错误信息
            }
            IArticleManager articleManager = new ArticleManager();

            //如果提交的分类不为空,循环自己所有的分类,对比是否正确
            if (categoryIds != null)
            {
                List <BlogCategoryDto> categoryDtoes = await articleManager.GetAllCategories(Guid.Parse(userId)); //获取分类对象集合

                List <Guid> currentUserCategoryIds = new List <Guid>();                                           //将分类对象中的分类id整合进一个集合中
                foreach (BlogCategoryDto category in categoryDtoes)
                {
                    currentUserCategoryIds.Add(category.Id);
                }
                for (int i = 0; i < categoryIds.Length; i++)              //循环检查提交的分类id是否和自身的分类id有对应
                {
                    if (!currentUserCategoryIds.Contains(categoryIds[i])) //如果提交的分类id与自身的分类id没有匹配项,提示错误
                    {
                        return(Json(new { status = "fail", result = "提交的分类与用户所拥有的分类不匹配,请重试!" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            Guid articleId = await articleManager.CreateArticle(title, content, introContent, categoryIds, Guid.Parse(userId));

            return(Json(new { status = "ok", result = "提交成功!", articleId }, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        public async Task <ActionResult> AddCategory(string categoryName)
        {
            //不可为空,不可重复,未登录无法提交
            if (categoryName == null || categoryName.Trim() == "")
            {
                return(Json(new { status = "fail", result = "分类名称不可为空!" }, JsonRequestBehavior.AllowGet));
            }
            //获取当前登陆的id,cookie的id需要解密
            string userCookieId = ""; string message;

            if (Request.Cookies["userId"] != null)
            {
                if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message))
                {
                    return(Json(new { status = "fail", result = message }, JsonRequestBehavior.AllowGet));
                }
            }
            string userId = Session["userId"] == null ? userCookieId : Session["userId"].ToString(); //优先获取session的id

            if (userId == "")                                                                        //未登录提醒
            {
                return(Json(new { status = "fail", result = "未登陆无法提交!" }, JsonRequestBehavior.AllowGet));
            }
            IArticleManager        articleManager = new ArticleManager();
            List <BlogCategoryDto> categoryList   = await articleManager.GetAllCategories(Guid.Parse(userId));//获取所有分类名,循环对比是否有重复

            bool isRepeat = false;

            foreach (var cate in categoryList)
            {
                if (cate.BlogCategoryName == categoryName)
                {
                    isRepeat = true;
                    break;
                }
            }
            if (isRepeat)
            {
                return(Json(new { status = "fail", result = "添加的分类名称已存在,请勿重复添加!" }, JsonRequestBehavior.AllowGet));
            }
            await articleManager.CreateCategory(categoryName, Guid.Parse(userId));//添加分类

            return(Json(new { status = "ok", result = "添加成功!" }, JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
    /// <summary>
    /// 绑定分类集合
    /// </summary>
    private void BindCategories()
    {
        List <ArticleCategory> categories = ArticleManager.GetAllCategories();

        foreach (ArticleCategory info in categories)
        {
            if (info.ParentID == null || info.ParentID == 0)
            {
                TreeNode newNode = MakeCategoryNode(info);
                newNode.ExpandAll();

                LoadChild(newNode);

                tvwCategory.Nodes.Add(newNode);
            }
        }

        HttpCookie cache = HHCookie.GetCookie(nodeState + Profile.AccountInfo.UserName);

        if (cache != null)
        {
            CheckNode(tvwCategory.Nodes, cache.Value);
            SetValue();
            LoadChildArticles(int.Parse(cache.Value));
        }

        if (tvwCategory.Nodes.Count != 0)
        {
            HttpCookie hhcache = HHCookie.GetCookie(nodeState + Profile.AccountInfo.UserName);
            if (hhcache != null)
            {
                CheckNode(tvwCategory.Nodes, hhcache.Value);
                SetValue();
                //BindUserDept(int.Parse(hhcache.Value));
            }
            else
            {
                tvwCategory.Nodes[0].Selected = true;
            }

            tvwCategory_SelectedNodeChanged(tvwCategory, null);
        }
    }
コード例 #8
0
    private void BindList()
    {
        tempCates = ArticleManager.GetAllCategories();
        int?parId = null;

        foreach (ArticleCategory ac in tempCates)
        {
            if (ac.ParentID == null || ac.ParentID == 0)
            {
                parId = ac.ID; break;
            }
        }
        List <ArticleCategory> catesLevel1 = new List <ArticleCategory>();

        foreach (ArticleCategory item in tempCates)
        {
            // 1为“华宏资讯”分类
            if (item.ParentID == parId)
            {
                catesLevel1.Add(item);
            }
        }

        repCategories.DataSource = catesLevel1;
        repCategories.DataBind();

        // 移除一级分类的节点
        foreach (ArticleCategory item in catesLevel1)
        {
            tempCates.Remove(item);
        }

        // 绑定子分类
        repCategoryLevel1.DataSource = catesLevel1;
        repCategoryLevel1.DataBind();
    }
コード例 #9
0
        public async Task <ActionResult> CategoryList()
        {
            IArticleManager articleManager = new ArticleManager();

            return(View(await articleManager.GetAllCategories(Guid.Parse(Session["userId"].ToString()))));
        }