Example #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 }));
        }
Example #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 }));
        }
Example #3
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 }) }));
        }
Example #4
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());
        }