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 })); }
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 })); }
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" })); }
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" })); }
//编辑姿势 public ActionResult BlogEdit(Guid id) { Blog blog = BlogDataSvc.GetByID(id); if (blog.OwnerID != CurrentUser.ID) { return(RedirectToAction("Error")); } ViewBag.Blog = blog; return(View()); }
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" })); }
//管理员编辑姿势 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")); }
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 }) })); }
//查看姿势 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()); }