示例#1
0
        public ActionResult ProBlog(Guid id)
        {
            Blog   blog = BlogDataSvc.GetByID(id);
            string key  = MyRedisKeys.Pre_UserRecord + CurrentUser.ID;
            IEnumerable <UserRecord> userRecords = MyRedisDB.GetSet <UserRecord>(key);

            if (userRecords.Count() == 0)
            {
                MyRedisDB.SetAdd(key, new UserRecord()
                {
                    ObjID = blog.ID, type = (int)EnumRecordType.点赞
                });
                MyRedisDB.RedisDB.KeyExpire(key, DateTime.Now.AddDays(1));
                blog.ProCount += 1;
                BlogDataSvc.Update(blog);
                ProUser(blog.OwnerID);
            }
            else if (userRecords.Where(r => r.ObjID == blog.ID && r.type == (int)EnumRecordType.点赞).Count() == 0)
            {
                MyRedisDB.SetAdd(key, new UserRecord()
                {
                    ObjID = blog.ID, type = (int)EnumRecordType.点赞
                });
                blog.ProCount += 1;
                BlogDataSvc.Update(blog);
                ProUser(blog.OwnerID);
            }
            return(Json(new { msg = "done", count = blog.ProCount }));
        }
示例#2
0
        public ActionResult AddBlogComment(Guid blogID, string mdTxt, string mdValue)
        {
            DisabledUser user = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == CurrentUser.ID && d.ObjectType == (int)EnumObjectType.姿势 && d.AbleDate > DateTime.Now).FirstOrDefault();

            if (user != null)
            {
                return(Json(new { msg = "你被封禁至" + user.AbleDate.ToString("yyyy-MM-dd HH:ss") }));
            }
            if (string.IsNullOrEmpty(mdTxt) || string.IsNullOrEmpty(mdValue))
            {
                return(Json(new { msg = "参数错误" }));
            }
            if (mdTxt.GetByteCount() > 5000 || mdValue.GetByteCount() > 10000)
            {
                return(Json(new { msg = "参数太长" }));
            }

            Blog blog = BlogDataSvc.GetByID(blogID);

            blog.CommentCount += 1;

            BlogComment comment = new BlogComment();

            comment.BlogID  = blogID;
            comment.MDText  = mdTxt;
            comment.MDValue = HtmlST.Sanitize(mdValue);
            comment.OwnerID = CurrentUser.ID;
            comment.Order   = blog.CommentCount;
            BlogCommentDataSvc.Add(comment);

            BlogDataSvc.Update(blog);

            if (blog.OwnerID != CurrentUser.ID)
            {
                string key   = MyRedisKeys.Pre_CMsg + blog.OwnerID;
                CMsg   bcmsg = MyRedisDB.GetSet <CMsg>(key).Where(m => m.ObjID == blogID).FirstOrDefault();
                if (bcmsg != null)
                {
                    MyRedisDB.SetRemove(key, bcmsg);
                    bcmsg.Count += 1;
                    MyRedisDB.SetAdd(key, bcmsg);
                }
                else
                {
                    bcmsg         = new CMsg();
                    bcmsg.ObjType = (int)EnumObjectType.姿势;
                    bcmsg.ObjID   = blogID;
                    bcmsg.Count   = 1;
                    bcmsg.Date    = DateTime.Now;
                    bcmsg.Order   = comment.Order;
                    bcmsg.Title   = blog.Title.MaxByteLength(32);
                    MyRedisDB.SetAdd(key, bcmsg);
                }
            }

            return(Json(new { msg = "done", count = blog.CommentCount }));
        }
示例#3
0
        public ActionResult UserBlogPage(Guid uid, int pageSize, int pageNum = 1)
        {
            ViewBag.Owner = CurrentUser == null ? false : uid == CurrentUser.ID;
            int totalCount;

            ViewBag.UserBlogs   = BlogDataSvc.GetPagedEntitys(ref pageNum, pageSize, b => b.OwnerID == uid, b => b.InsertDate, true, out totalCount).ToList();
            ViewBag.TotalCount  = totalCount;
            ViewBag.CurrentPage = pageNum;
            return(View());
        }
示例#4
0
        public ActionResult StarBlog(Guid id)
        {
            Blog   blog    = BlogDataSvc.GetByID(id);
            string starKey = MyRedisKeys.Pre_UserStarCache + CurrentUser.ID;
            IEnumerable <UserStarCache> userStarCaches = MyRedisDB.GetSet <UserStarCache>(starKey);

            bool add = false;

            if (userStarCaches.Count() == 0)
            {
                IEnumerable <UserStar> userStars = UserStarDataSvc.GetByCondition(s => s.OwnerID == CurrentUser.ID);
                if (userStars.Count() > 0)
                {
                    //添加收藏缓存
                    foreach (UserStar star in userStars)
                    {
                        MyRedisDB.SetAdd(starKey, new UserStarCache()
                        {
                            ObjID = blog.ID, ObjType = star.ObjType
                        });
                    }
                    MyRedisDB.RedisDB.KeyExpire(starKey, DateTime.Now.AddHours(3));
                    //添加收藏
                    if (userStars.Where(s => s.ObjID == blog.ID).Count() == 0)
                    {
                        add = true;
                    }
                }
                else
                {
                    add = true;
                }
            }
            else if (userStarCaches.Where(s => s.ObjID == blog.ID).Count() == 0)
            {
                add = true;
            }

            if (add)
            {
                //添加收藏
                UserStar star = new UserStar();
                star.OwnerID = CurrentUser.ID;
                star.ObjID   = blog.ID;
                star.Title   = blog.Title;
                star.ObjType = (int)EnumObjectType.姿势;
                UserStarDataSvc.Add(star);
                MyRedisDB.SetAdd(starKey, new UserStarCache()
                {
                    ObjID = blog.ID, ObjType = star.ObjType
                });
                MyRedisDB.RedisDB.KeyExpire(starKey, DateTime.Now.AddHours(3));
            }
            return(Json(new { msg = "done" }));
        }
示例#5
0
        public ActionResult BlogDelete(Guid id)
        {
            Blog blog = BlogDataSvc.GetByID(id);

            if (blog.OwnerID != CurrentUser.ID)
            {
                return(Json(new { msg = "小伙子你想干嘛" }));
            }
            BlogDataSvc.DeleteByID(id);
            return(Json(new { msg = "done" }));
        }
示例#6
0
        //编辑姿势
        public ActionResult BlogEdit(Guid id)
        {
            Blog blog = BlogDataSvc.GetByID(id);

            if (blog.OwnerID != CurrentUser.ID)
            {
                return(RedirectToAction("Error"));
            }
            ViewBag.Blog = blog;
            return(View());
        }
示例#7
0
        public ActionResult BlogDelete(Guid id)
        {
            Blog blog = BlogDataSvc.GetByID(id);

            BlogDataSvc.DeleteByID(id);

            SysMsg msg = new SysMsg();

            msg.Date  = DateTime.Now;
            msg.Title = "你的" + Enum.GetName(typeof(EnumObjectType), 1) + "被删除";
            msg.Msg   = blog.Title.MaxByteLength(30);
            string key = MyRedisKeys.Pre_SysMsg + blog.OwnerID;

            MyRedisDB.SetAdd(key, msg);

            return(Json(new { msg = "done" }));
        }
示例#8
0
        //管理员编辑姿势
        public ActionResult BlogManagerEdit(Guid id, Guid keyId)
        {
            Guid key = Guid.Empty;

            if (!Guid.TryParse(MyRedisDB.StringGet("MBEditKey"), out key))
            {
                return(RedirectToAction("Error"));
            }
            if (key != keyId)
            {
                return(RedirectToAction("Error"));
            }
            Blog blog = BlogDataSvc.GetByID(id);

            ViewBag.Blog = blog;
            return(View("BlogEdit"));
        }
示例#9
0
        public ActionResult BlogEdit(Guid id, string mdTxt, string mdValue)
        {
            if (string.IsNullOrEmpty(mdTxt) || string.IsNullOrEmpty(mdValue))
            {
                return(Json(new { msg = "参数错误" }));
            }
            if (mdTxt.GetByteCount() > 50000 || mdValue.GetByteCount() > 100000)
            {
                return(Json(new { msg = "参数太长" }));
            }

            //内容无害化
            mdValue = HtmlST.Sanitize(mdValue);
            Blog nblog = BlogDataSvc.GetByID(id);

            nblog.MDText  = mdTxt;
            nblog.MDValue = mdValue;
            BlogDataSvc.Update(nblog);
            return(Json(new { msg = "done", url = Url.Action("BlogView", new { id = nblog.ID }) }));
        }
示例#10
0
        public ActionResult BlogPage(string order, int pageSize, int pageNum = 1, int days = 3)
        {
            DateTime validDate  = DateTime.Now.AddDays(days * -1);
            int      totalCount = 0;

            if (order == "new")
            {
                ViewBag.BlogList = BlogDataSvc.GetPagedEntitys(ref pageNum, pageSize, it => true, it => it.InsertDate, true, out totalCount).ToList();
            }
            else if (order == "view")
            {
                ViewBag.BlogList = BlogDataSvc.GetPagedEntitys(ref pageNum, pageSize, it => it.InsertDate > validDate, it => it.ViewCount, true, out totalCount).ToList();
            }
            else if (order == "pro")
            {
                ViewBag.BlogList = BlogDataSvc.GetPagedEntitys(ref pageNum, pageSize, it => it.InsertDate > validDate, it => it.ProCount, true, out totalCount).ToList();
            }
            ViewBag.TotalCount  = totalCount;
            ViewBag.CurrentPage = pageNum;
            return(View());
        }
示例#11
0
        public ActionResult BlogNew(int type, string title, string mdTxt, string mdValue)
        {
            DisabledUser user = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == CurrentUser.ID && d.ObjectType == (int)EnumObjectType.姿势 && d.AbleDate > DateTime.Now).FirstOrDefault();

            if (user != null)
            {
                return(Json(new { msg = "你被封禁至" + user.AbleDate.ToString("yyyy-MM-dd HH:ss") }));
            }
            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(mdTxt) || string.IsNullOrEmpty(mdValue))
            {
                return(Json(new { msg = "参数错误" }));
            }
            if (title.GetByteCount() > 90 || mdTxt.GetByteCount() > 50000 || mdValue.GetByteCount() > 100000)
            {
                return(Json(new { msg = "参数太长" }));
            }
            if (type < 0 || type > 4)
            {
                type = 0;
            }

            //内容无害化
            mdValue = HtmlST.Sanitize(mdValue);
            Blog nblog = new Blog();

            nblog.Type    = type;
            nblog.Title   = title;
            nblog.MDText  = mdTxt;
            nblog.MDValue = mdValue;
            nblog.OwnerID = CurrentUser.ID;
            BlogDataSvc.Add(nblog);
            //发布成功删除草稿
            string key = MyRedisKeys.Pre_BlogDraft + CurrentUser.ID;

            MyRedisDB.DelKey(key);
            return(Json(new { msg = "done", url = Url.Action("BlogList") }));
        }
示例#12
0
        public ActionResult BlogPage(int pageSize, int pageNum = 1, string condition = "")
        {
            int totalCount;

            if (string.IsNullOrEmpty(condition))
            {
                ViewBag.BlogList = BlogDataSvc.GetPagedEntitys(ref pageNum, pageSize, u => true, u => u.InsertDate, true, out totalCount).ToList();
            }
            else
            {
                Guid id = Guid.Empty;
                if (Guid.TryParse(condition, out id))
                {
                    ViewBag.BlogList = BlogDataSvc.GetPagedEntitys(ref pageNum, pageSize, u => u.ID == id, u => u.InsertDate, true, out totalCount).ToList();
                }
                else
                {
                    ViewBag.BlogList = BlogDataSvc.GetPagedEntitys(ref pageNum, pageSize, u => u.Title.Contains(condition) || u.Owner.GitHubLogin.Contains(condition), u => u.InsertDate, true, out totalCount).ToList();
                }
            }
            ViewBag.TotalCount  = totalCount;
            ViewBag.CurrentPage = pageNum;
            return(View());
        }
示例#13
0
        //查看姿势
        public ActionResult BlogView(Guid id, int co = 0, int ro = 0)
        {
            Blog blog = BlogDataSvc.GetByID(id);

            ViewBag.Blog   = blog;
            ViewBag.Login  = CurrentUser != null;
            ViewBag.Owner  = CurrentUser != null ? CurrentUser.ID == blog.OwnerID : false;
            ViewBag.COrder = co;
            ViewBag.ROrder = ro;

            blog.ViewCount += 1;
            BlogDataSvc.Update(blog);

            #region 查看点赞收藏是否显示
            if (CurrentUser != null)
            {
                //查看次数
                string key = MyRedisKeys.Pre_UserRecord + CurrentUser.ID;
                IEnumerable <UserRecord> userRecords = MyRedisDB.GetSet <UserRecord>(key);
                //if (userRecords.Count() == 0)
                //{
                //    MyRedisDB.SetAdd(key, new UserRecord() { ObjID = blog.ID, type = (int)EnumRecordType.查看 });
                //    MyRedisDB.RedisDB.KeyExpire(key, DateTime.Now.AddDays(1));
                //    blog.ViewCount += 1;
                //    BlogDataSvc.Update(blog);
                //}
                //else if (userRecords.Where(r => r.ObjID == blog.ID && r.type == (int)EnumRecordType.查看).Count() == 0)
                //{
                //    MyRedisDB.SetAdd(key, new UserRecord() { ObjID = blog.ID, type = (int)EnumRecordType.查看 });
                //    blog.ViewCount += 1;
                //    BlogDataSvc.Update(blog);
                //}

                //点赞
                ViewBag.ShowPro = false;
                if (userRecords.Where(r => r.ObjID == blog.ID && r.type == (int)EnumRecordType.点赞).Count() == 0)
                {
                    ViewBag.ShowPro = true;
                }

                //收藏
                ViewBag.ShowStar = true;
                string starKey = MyRedisKeys.Pre_UserStarCache + CurrentUser.ID;
                IEnumerable <UserStarCache> userStarCaches = MyRedisDB.GetSet <UserStarCache>(starKey);
                if (userStarCaches.Count() == 0)
                {
                    IEnumerable <UserStar> userStars = UserStarDataSvc.GetByCondition(s => s.OwnerID == CurrentUser.ID);
                    if (userStars.Count() > 0)
                    {
                        if (userStars.Where(s => s.ObjID == blog.ID).Count() > 0)
                        {
                            ViewBag.ShowStar = false;
                        }
                        //添加收藏缓存
                        foreach (UserStar star in userStars)
                        {
                            MyRedisDB.SetAdd(starKey, new UserStarCache()
                            {
                                ObjID = blog.ID, ObjType = star.ObjType
                            });
                        }
                        MyRedisDB.RedisDB.KeyExpire(starKey, DateTime.Now.AddHours(3));
                    }
                }
                else if (userStarCaches.Where(s => s.ObjID == blog.ID).Count() > 0)
                {
                    ViewBag.ShowStar = false;
                }
            }
            #endregion

            if (ViewBag.Login)
            {
                DisabledUser user = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == CurrentUser.ID && d.ObjectType == (int)EnumObjectType.姿势 && d.AbleDate > DateTime.Now).FirstOrDefault();
                if (user != null)
                {
                    ViewBag.DisableMsg = "你被封禁至" + user.AbleDate.ToString("yyyy-MM-dd HH:ss");
                }
            }

            return(View());
        }