public async Task <ActionResult> GetArticleDetails(Guid?id)
        {
            var articleManager = new ArticleManager();

            if (id == null || !await articleManager.ExistsArticle(id.Value))
            {
                return(Json(new { result = "未能找到对应ID的文章,请稍后再试", status = "fail" }, JsonRequestBehavior.AllowGet));//返回错误信息
            }
            ArticleDto articleData = await articleManager.GetOneArticleById(id.Value);

            var userManager             = new UserManager();
            UserInformationDto userInfo = await userManager.GetUserById(articleData.userId);

            //查询是否已经关注
            string userid = ""; string message;

            if (Request.Cookies["userId"] != null)
            {
                JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userid, out message);
            }
            string userId        = Session["userId"] == null ? userid : Session["userId"].ToString();
            var    articlesCount = await articleManager.GetArticleDataCount(userInfo.Id);                            //查找文章总数

            var categoriesCount = await articleManager.GetCategoryDataCount(userInfo.Id);                            //查找分类总数

            var isCurrentUser = userId.Trim() == "" ? false : userInfo.Id == Guid.Parse(userId) ? true : false;      //是否为当前登陆用户
            var isFocused     = userId == "" ? false : await userManager.IsFocused(Guid.Parse(userId), userInfo.Id); //id为空也视为没关注

            var tenTags = await articleManager.GetCategoriesByCount(userInfo.Id, 10);                                //返回10个分类

            return(Json(new { status = "ok", articleData, userInfo, articlesCount, categoriesCount, isCurrentUser, isFocused, tenTags }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> ArticleDetails(Guid?id)
        {
            var articleManager = new ArticleManager();

            if (id == null || !await articleManager.ExistsArticle(id.Value))
            {
                ErrorController.message = "未能找到对应ID的文章,请稍后再试";
                return(RedirectToAction("IllegalOperationError", "Error"));//返回错误页面
            }
            ArticleDto data = await articleManager.GetOneArticleById(id.Value);

            var userManager         = new UserManager();
            UserInformationDto user = await userManager.GetUserById(data.userId);

            ViewBag.User          = user;
            ViewBag.ArticlesCount = await articleManager.GetArticleDataCount(user.Id);    //查找文章总数

            ViewBag.CategoriesCount = await articleManager.GetCategoryDataCount(user.Id); //查找分类总数

            //查询是否已经关注
            string userid = ""; string message;

            if (Request.Cookies["userId"] != null)
            {
                JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userid, out message);
            }
            string userId = Session["userId"] == null ? userid : Session["userId"].ToString();

            ViewBag.IsCurrentUser = userId.Trim() == "" ? false : user.Id == Guid.Parse(userId) ? true : false;      //是否为当前登陆用户
            ViewBag.IsFocused     = userId == "" ? false : await userManager.IsFocused(Guid.Parse(userId), user.Id); //id为空也视为没关注

            ViewBag.TenTags = await articleManager.GetCategoriesByCount(user.Id, 10);                                //返回10个分类

            return(View(data));
        }
Exemple #3
0
        public async Task <ActionResult> Index()
        {
            IArticleManager articleManager = new ArticleManager();
            IUserManager    userManager    = new UserManager();

            ViewBag.PopularUser = await userManager.GetFamousUser(10);

            ViewBag.ArticlesCount = await articleManager.GetArticleDataCount(); //查找文章总数

            ViewBag.UsersCount = await userManager.GetUserDataCount();          //查找用户总数

            return(View(await articleManager.GetFamousArticle(5)));
        }
Exemple #4
0
        public async Task <ActionResult> GetIndex()
        {
            IArticleManager articleManager = new ArticleManager();
            IUserManager    userManager    = new UserManager();
            var             popularUser    = await userManager.GetFamousUser(10);

            var articlesCount = await articleManager.GetArticleDataCount(); //查找文章总数

            var usersCount = await userManager.GetUserDataCount();          //查找用户总数

            var famousArticle = await articleManager.GetFamousArticle(5);   //查找喜欢数量最多的

            return(Json(new { status = "ok", popularUser, articlesCount, usersCount, famousArticle }, JsonRequestBehavior.AllowGet));
        }
Exemple #5
0
        public async Task <ActionResult> GetUserDetails(Guid?id)
        {
            //获取当前登陆的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 { result = message, status = "fail", code = 401 }, JsonRequestBehavior.AllowGet));//返回错误信息
                }
            }
            string userId = Session["userId"] == null ? userCookieId : Session["userId"].ToString();

            if (id == null && userId != null && userId.Trim() != "")
            {
                return(RedirectToAction(nameof(GetUserDetails), new { id = userId }));
            }
            IUserManager userManager = new UserManager();

            if (id == null)                                                     //未登录不可为空
            {
                return(Json(new { code = 401 }, JsonRequestBehavior.AllowGet)); //仅返回错误代码跳转登陆,不弹提示
            }
            if (!await userManager.ExistsUser(id.Value))
            {
                return(Json(new { result = "未能找到对应ID的用户,请稍后再试", status = "fail" }, JsonRequestBehavior.AllowGet));//返回错误信息
            }
            UserInformationDto userInfo = await userManager.GetUserById(id.Value);

            IArticleManager articleManager = new ArticleManager();
            var             latestArticles = await articleManager.GetCurrentUserLatestArticle(5, id.Value, false); //选取5篇最新发布的文章,不含置顶

            var topArticles = await articleManager.GetCurrentUserLatestArticle(100, id.Value, true);               //选取100篇最新发布的置顶文章(不足100取找到的最大值)

            var articlesCount = await articleManager.GetArticleDataCount(userInfo.Id);                             //查找文章总数

            var categoriesCount = await articleManager.GetCategoryDataCount(userInfo.Id);                          //查找分类总数

            var isFocused = userId == "" ? false : await userManager.IsFocused(Guid.Parse(userId), id.Value);      //id为空也视为没关注

            var isCurrentUser = userId == "" ? false : Guid.Parse(userId) == id.Value ? true : false;              //是否为当前登陆用户
            var tenTags       = await articleManager.GetCategoriesByCount(id.Value, 10);                           //返回10个分类

            return(Json(new { status = "ok", userInfo, latestArticles, topArticles, articlesCount, categoriesCount, isFocused, isCurrentUser, tenTags }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> CategoryList(string userId, int pageIndex = 1, int pageSize = 7)
        {
            //获取当前登陆的id,cookie的id需要解密
            string userCookieId = ""; string message;

            if (Request.Cookies["userId"] != null)
            {
                if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message))
                {
                    ErrorController.message = message;
                    return(RedirectToAction("IllegalOperationError", "Error"));//返回错误页面
                }
            }
            string currentUserId = Session["userId"] == null ? userCookieId : Session["userId"].ToString();

            if (userId == null && currentUserId != null && currentUserId.Trim() != "")
            {
                return(RedirectToAction(nameof(CategoryList), new { userId = currentUserId }));
            }
            IUserManager    userManager    = new UserManager();
            IArticleManager articleManager = new ArticleManager();
            Guid            userIdGuid;

            Guid.TryParse(userId, out userIdGuid);
            if (!await userManager.ExistsUser(userIdGuid) || userIdGuid == Guid.Empty)
            {
                ErrorController.message = "未能找到对应ID的用户,请稍后再试";
                return(RedirectToAction("IllegalOperationError", "Error"));                                                                  //返回错误页面
            }
            var categorys = await articleManager.GetAllCategoriesByUserId(userIdGuid, (pageIndex - 1), pageSize);                            //数据库是从0开始的

            var dataCount = await articleManager.GetCategoryDataCount(userIdGuid);                                                           //分类总数

            ViewBag.PageCount     = dataCount % pageSize == 0 ? dataCount / pageSize : dataCount / pageSize + 1;                             //总页数
            ViewBag.PageIndex     = pageIndex;                                                                                               //当前页数
            ViewBag.IsCurrentUser = currentUserId.Trim() == "" ? false : userIdGuid == Guid.Parse(currentUserId) ? true : false;             //是否为当前登陆用户
            ViewBag.IsFocused     = currentUserId.Trim() == "" ? false : await userManager.IsFocused(Guid.Parse(currentUserId), userIdGuid); //id为空也视为没关注

            ViewBag.RequestId = userIdGuid;                                                                                                  //当前请求id
            ViewBag.User      = await userManager.GetUserById(userIdGuid);

            ViewBag.ArticlesCount = await articleManager.GetArticleDataCount(userIdGuid); //查找文章总数

            ViewBag.CategoriesCount = dataCount;                                          //查找分类总数
            return(View(categorys));
        }
Exemple #7
0
        public async Task <ActionResult> UserDetails(Guid?id)
        {
            //获取当前登陆的id,cookie的id需要解密
            string userCookieId = ""; string message;

            if (Request.Cookies["userId"] != null)
            {
                if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message))
                {
                    ErrorController.message = message;
                    return(RedirectToAction("IllegalOperationError", "Error"));//返回错误页面
                }
            }
            string userId = Session["userId"] == null ? userCookieId : Session["userId"].ToString();

            if (id == null && userId != null && userId.Trim() != "")
            {
                return(RedirectToAction(nameof(UserDetails), new { id = userId }));
            }
            IUserManager userManager = new UserManager();

            if (id == null || !await userManager.ExistsUser(id.Value))
            {
                ErrorController.message = "未能找到对应ID的用户,请稍后再试";
                return(RedirectToAction("IllegalOperationError", "Error"));//返回错误页面
            }
            UserInformationDto user = await userManager.GetUserById(id.Value);

            IArticleManager articleManager = new ArticleManager();

            ViewBag.LatestArticles = await articleManager.GetCurrentUserLatestArticle(5, id.Value, false);        //选取5篇最新发布的文章,不含置顶

            ViewBag.TopArticles = await articleManager.GetCurrentUserLatestArticle(100, id.Value, true);          //选取100篇最新发布的置顶文章(不足100取找到的最大值)

            ViewBag.ArticlesCount = await articleManager.GetArticleDataCount(user.Id);                            //查找文章总数

            ViewBag.CategoriesCount = await articleManager.GetCategoryDataCount(user.Id);                         //查找分类总数

            ViewBag.IsFocused = userId == "" ? false : await userManager.IsFocused(Guid.Parse(userId), id.Value); //id为空也视为没关注

            ViewBag.IsCurrentUser = userId == "" ? false : Guid.Parse(userId) == id.Value ? true : false;         //是否为当前登陆用户
            ViewBag.TenTags       = await articleManager.GetCategoriesByCount(id.Value, 10);                      //返回10个分类

            return(View(user));
        }
        public async Task <ActionResult> DeleteCategory(Guid?Id)
        {
            //获取当前登陆的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 (Id == null || !await articleManager.ExistsCategory(Id.Value))          //文章id找不到则跳转分类不存在错误页面
            {
                return(Json(new { status = "fail", result = "未能找到对应ID的分类,请稍后再试" }));   //返回错误信息
            }//要经过上面的判断否则会出错
            BlogCategory data = await articleManager.GetOneCategoryById(Id.Value);     //获取分类id的所有信息

            if (data.UserId != Guid.Parse(userId))                                     //文章作者才可删除文章
            {
                if (data.UserId == Guid.Parse("00000000-0000-0000-0000-000000000001")) //如果是01用户,说明是系统内置分类,不可删除
                {
                    return(Json(new { status = "fail", result = "系统内置分类不可进行删除" }));    //返回错误信息
                }
                else
                {
                    return(Json(new { status = "fail", result = "非本人分类不可进行删除" }));//返回错误信息
                }
            }
            if (await articleManager.GetArticleDataCount(Guid.Parse(userId), Id.Value) != 0)
            {
                return(Json(new { status = "fail", result = "已有文章引用了该分类,如需删除请先编辑文章取消引用该分类" }));//返回错误信息
            }
            await articleManager.RemoveCategory(Id.Value);

            return(Json(new { status = "ok", result = "删除成功!" }));
        }
        public async Task <ActionResult> GetCategoryList(string userId, int pageIndex = 1, int pageSize = 7)
        {
            //获取当前登陆的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 { result = message, status = "fail" }, JsonRequestBehavior.AllowGet));//返回错误信息
                }
            }
            string currentUserId = Session["userId"] == null ? userCookieId : Session["userId"].ToString();

            if (userId == null && currentUserId != null && currentUserId.Trim() != "")
            {
                return(RedirectToAction(nameof(GetCategoryList), new { userId = currentUserId }));
            }
            IUserManager    userManager    = new UserManager();
            IArticleManager articleManager = new ArticleManager();
            Guid            userIdGuid;

            Guid.TryParse(userId, out userIdGuid);
            if (!await userManager.ExistsUser(userIdGuid) || userIdGuid == Guid.Empty)
            {
                return(Json(new { result = "未能找到对应ID的用户,请稍后再试", status = "fail" }, JsonRequestBehavior.AllowGet));                       //返回错误信息
            }
            var categoriesInfo = await articleManager.GetAllCategoriesByUserId(userIdGuid, (pageIndex - 1), pageSize);                   //数据库是从0开始的

            var dataCount = await articleManager.GetCategoryDataCount(userIdGuid);                                                       //分类总数

            var pageCount     = dataCount % pageSize == 0 ? dataCount / pageSize : dataCount / pageSize + 1;                             //总页数
            var isCurrentUser = currentUserId.Trim() == "" ? false : userIdGuid == Guid.Parse(currentUserId) ? true : false;             //是否为当前登陆用户
            var isFocused     = currentUserId.Trim() == "" ? false : await userManager.IsFocused(Guid.Parse(currentUserId), userIdGuid); //id为空也视为没关注

            var requestId = userIdGuid;                                                                                                  //当前请求id
            var userInfo  = await userManager.GetUserById(userIdGuid);

            var articlesCount = await articleManager.GetArticleDataCount(userIdGuid); //查找文章总数

            var categoriesCount = dataCount;                                          //查找分类总数

            return(Json(new { status = "ok", categoriesInfo, pageCount, pageIndex, pageSize, isCurrentUser, isFocused, requestId, userInfo, articlesCount, categoriesCount }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> GetArticleList(string userId, string categoryId = null, int pageIndex = 1, int pageSize = 7)
        {
            //获取当前登陆的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 { result = message, status = "fail" }, JsonRequestBehavior.AllowGet));//返回错误信息
                }
            }
            string currentUserId = Session["userId"] == null ? userCookieId : Session["userId"].ToString();

            if (userId == null && currentUserId != null && currentUserId.Trim() != "")
            {
                return(RedirectToAction(nameof(GetArticleList), new { userId = currentUserId }));
            }
            //需要返回前端 总页数 当前页数 单个页面数量
            IArticleManager articleManager = new ArticleManager();
            IUserManager    userManager    = new UserManager();
            Guid            userIdGuid;

            Guid.TryParse(userId, out userIdGuid);
            if (!await userManager.ExistsUser(userIdGuid) || userIdGuid == Guid.Empty)
            {
                return(Json(new { result = "未能找到对应ID的用户,请稍后再试", status = "fail" }, JsonRequestBehavior.AllowGet));//返回错误信息
            }
            //新增按照用户id和分类id查找文章,默认为不找分类id
            Guid categoryIdGuid;

            Guid.TryParse(categoryId, out categoryIdGuid);
            List <ArticleDto> articlesInfo;
            int dataCount;

            if (categoryIdGuid == Guid.Empty)
            {
                articlesInfo = await articleManager.GetAllArticlesByUserId(userIdGuid, (pageIndex - 1), pageSize); //数据库是从0开始的

                dataCount = await articleManager.GetArticleDataCount(userIdGuid);                                  //文章总数
            }
            else
            {
                articlesInfo = await articleManager.GetAllArticlesByUserIdAndCategoryId(userIdGuid, categoryIdGuid, (pageIndex - 1), pageSize); //数据库是从0开始的

                dataCount = await articleManager.GetArticleDataCount(userIdGuid, categoryIdGuid);                                               //文章总数
            }
            var pageCount = dataCount % pageSize == 0 ? dataCount / pageSize : dataCount / pageSize + 1;                                        //总页数
            var category  = categoryIdGuid == Guid.Empty ? null : await articleManager.GetOneCategoryById(categoryIdGuid);

            var isCurrentUser = currentUserId.Trim() == "" ? false : userIdGuid == Guid.Parse(currentUserId) ? true : false;         //是否为当前登陆用户
            var requestId     = userIdGuid;                                                                                          //当前请求id
            var tenTags       = await articleManager.GetCategoriesByCount(userIdGuid, 10);                                           //返回10个分类

            var articlesCount = await articleManager.GetArticleDataCount(userIdGuid);                                                //查找文章总数

            var categoriesCount = await articleManager.GetCategoryDataCount(userIdGuid);                                             //查找分类总数

            var isFocused = currentUserId.Trim() == "" ? false : await userManager.IsFocused(Guid.Parse(currentUserId), userIdGuid); //id为空也视为没关注

            var userInfo = await userManager.GetUserById(userIdGuid);

            var pageMatchArticleCount = dataCount;

            return(Json(new { status = "ok", articlesInfo, pageMatchArticleCount, pageCount, pageIndex, pageSize, category, isCurrentUser, requestId, tenTags, articlesCount, categoriesCount, isFocused, userInfo }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> ArticleList(string userId, string categoryId = null, int pageIndex = 1, int pageSize = 7)
        {
            //获取当前登陆的id,cookie的id需要解密
            string userCookieId = ""; string message;

            if (Request.Cookies["userId"] != null)
            {
                if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message))
                {
                    ErrorController.message = message;
                    return(RedirectToAction("IllegalOperationError", "Error"));//返回错误页面
                }
            }
            string currentUserId = Session["userId"] == null ? userCookieId : Session["userId"].ToString();

            if (userId == null && currentUserId != null && currentUserId.Trim() != "")
            {
                return(RedirectToAction(nameof(ArticleList), new { userId = currentUserId }));
            }
            //需要返回前端 总页数 当前页数 单个页面数量
            IArticleManager articleManager = new ArticleManager();
            IUserManager    userManager    = new UserManager();
            Guid            userIdGuid;

            Guid.TryParse(userId, out userIdGuid);
            if (!await userManager.ExistsUser(userIdGuid) || userIdGuid == Guid.Empty)
            {
                ErrorController.message = "未能找到对应ID的用户,请稍后再试";
                return(RedirectToAction("IllegalOperationError", "Error"));//返回错误页面
            }
            //新增按照用户id和分类id查找文章,默认为不找分类id
            Guid categoryIdGuid;

            Guid.TryParse(categoryId, out categoryIdGuid);
            List <ArticleDto> articles;
            int dataCount;

            if (categoryIdGuid == Guid.Empty)
            {
                articles = await articleManager.GetAllArticlesByUserId(userIdGuid, (pageIndex - 1), pageSize); //数据库是从0开始的

                dataCount = await articleManager.GetArticleDataCount(userIdGuid);                              //文章总数
            }
            else
            {
                articles = await articleManager.GetAllArticlesByUserIdAndCategoryId(userIdGuid, categoryIdGuid, (pageIndex - 1), pageSize); //数据库是从0开始的

                dataCount = await articleManager.GetArticleDataCount(userIdGuid, categoryIdGuid);                                           //文章总数
            }
            ViewBag.PageCount = dataCount % pageSize == 0 ? dataCount / pageSize : dataCount / pageSize + 1;                                //总页数
            ViewBag.PageIndex = pageIndex;                                                                                                  //当前页数
            ViewBag.PageSize  = pageSize;                                                                                                   //当前显示数目
            ViewBag.Category  = categoryIdGuid == Guid.Empty ? null : await articleManager.GetOneCategoryById(categoryIdGuid);

            ViewBag.IsCurrentUser = currentUserId.Trim() == "" ? false : userIdGuid == Guid.Parse(currentUserId) ? true : false;         //是否为当前登陆用户
            ViewBag.RequestId     = userIdGuid;                                                                                          //当前请求id
            ViewBag.TenTags       = await articleManager.GetCategoriesByCount(userIdGuid, 10);                                           //返回10个分类

            ViewBag.ArticlesCount = await articleManager.GetArticleDataCount(userIdGuid);                                                //查找文章总数

            ViewBag.CategoriesCount = await articleManager.GetCategoryDataCount(userIdGuid);                                             //查找分类总数

            ViewBag.IsFocused = currentUserId.Trim() == "" ? false : await userManager.IsFocused(Guid.Parse(currentUserId), userIdGuid); //id为空也视为没关注

            ViewBag.User = await userManager.GetUserById(userIdGuid);

            return(View(articles));
        }