public static PostsInfo GetItemByIndexAndTopics_id(uint?Index, ulong?Topics_id) { if (Index == null || Topics_id == null) { return(null); } if (itemCacheTimeout <= 0) { return(dal.GetItemByIndexAndTopics_id(Index, Topics_id)); } string key = string.Concat("cnodejs_BLL_PostsByIndexAndTopics_id_", Index, "_,_", Topics_id); string value = RedisHelper.Get(key); if (!string.IsNullOrEmpty(value)) { try { return(new PostsInfo(value)); } catch { } } PostsInfo item = dal.GetItemByIndexAndTopics_id(Index, Topics_id); if (item == null) { return(null); } RedisHelper.Set(key, item.Stringify(), itemCacheTimeout); return(item); }
public IActionResult 内容回复(ulong id, [FromForm] ulong?reply_id, [FromForm] string r_content, [FromForm] string _csrf) { TopicsInfo topic = Topics.GetItem(id); if (topic == null) { return new ContentResult { Content = "参数错误,回复的话题不能为空" } } ; SqlHelper.Transaction(() => { PostsInfo post = Posts.Insert(new PostsInfo { Content = r_content, Count_good = 0, Count_notgood = 0, Create_time = DateTime.Now, Topics_id = topic.Id, Users_id = LoginUser.Id, Index = (uint)topic.Count_posts + 2, Posts_id = reply_id > 0 ? reply_id : null }); topic.UpdateDiy.SetCount_postsIncrement(1).ExecuteNonQuery(); }); RedisHelper.Remove("posts_ByTopics_id" + id, "author_recent_topics" + LoginUser.Id, "author_nonereply"); return(new RedirectResult("/topic/" + id)); }
public static PostsInfo GetItem(ulong?Id) { if (Id == null) { return(null); } if (itemCacheTimeout <= 0) { return(dal.GetItem(Id)); } string key = string.Concat("cnodejs_BLL_Posts_", Id); string value = RedisHelper.Get(key); if (!string.IsNullOrEmpty(value)) { try { return(new PostsInfo(value)); } catch { } } PostsInfo item = dal.GetItem(Id); if (item == null) { return(null); } RedisHelper.Set(key, item.Stringify(), itemCacheTimeout); return(item); }
public static cnodejs.DAL.Posts.SqlUpdateBuild UpdateDiy(PostsInfo item, ulong?Id) { if (itemCacheTimeout > 0) { RemoveCache(item != null ? item : GetItem(Id)); } return(new cnodejs.DAL.Posts.SqlUpdateBuild(item, Id)); }
public static int Update(PostsInfo item) { if (itemCacheTimeout > 0) { RemoveCache(item); } return(dal.Update(item)); }
private static void RemoveCache(PostsInfo item) { if (item == null) { return; } RedisHelper.Remove(string.Concat("cnodejs_BLL_Posts_", item.Id)); RedisHelper.Remove(string.Concat("cnodejs_BLL_PostsByIndexAndTopics_id_", item.Index, "_,_", item.Topics_id)); }
public static PostsInfo Insert(PostsInfo item) { item = dal.Insert(item); if (itemCacheTimeout > 0) { RemoveCache(item); } return(item); }
public PostsInfo Insert(PostsInfo item) { ulong loc1; if (ulong.TryParse(string.Concat(SqlHelper.ExecuteScalar(TSQL.Insert, GetParameters(item))), out loc1)) { item.Id = loc1; } return(item); }
public APIReturn Get_item(ulong?Id) { PostsInfo item = Posts.GetItem(Id); if (item == null) { return(new APIReturn(98, "记录不存在,或者没有权限")); } return(new APIReturn(0, "成功", "item", item.ToBson())); }
public int Update(PostsInfo item) { return(new SqlUpdateBuild(null, item.Id) .SetPosts_id(item.Posts_id) .SetTopics_id(item.Topics_id) .SetUsers_id(item.Users_id) .SetContent(item.Content) .SetCount_good(item.Count_good) .SetCount_notgood(item.Count_notgood) .SetCreate_time(item.Create_time) .SetIndex(item.Index).ExecuteNonQuery()); }
protected static MySqlParameter[] GetParameters(PostsInfo item) { return(new MySqlParameter[] { GetParameter("?id", MySqlDbType.UInt64, 20, item.Id), GetParameter("?posts_id", MySqlDbType.UInt64, 20, item.Posts_id), GetParameter("?topics_id", MySqlDbType.UInt64, 20, item.Topics_id), GetParameter("?users_id", MySqlDbType.UInt64, 20, item.Users_id), GetParameter("?content", MySqlDbType.Text, -1, item.Content), GetParameter("?count_good", MySqlDbType.Int32, 11, item.Count_good), GetParameter("?count_notgood", MySqlDbType.Int32, 11, item.Count_notgood), GetParameter("?create_time", MySqlDbType.DateTime, -1, item.Create_time), GetParameter("?index", MySqlDbType.UInt32, 10, item.Index) }); }
public APIReturn Post_insert([FromForm] ulong?Posts_id, [FromForm] ulong?Topics_id, [FromForm] ulong?Users_id, [FromForm] string Content, [FromForm] int?Count_good, [FromForm] int?Count_notgood, [FromForm] uint?Index) { PostsInfo item = new PostsInfo(); item.Posts_id = Posts_id; item.Topics_id = Topics_id; item.Users_id = Users_id; item.Content = Content; item.Count_good = Count_good; item.Count_notgood = Count_notgood; item.Create_time = DateTime.Now; item.Index = Index; item = Posts.Insert(item); return(new APIReturn(0, "成功", "item", item.ToBson())); }
public APIReturn Put_update(ulong?Id, [FromForm] ulong?Posts_id, [FromForm] ulong?Topics_id, [FromForm] ulong?Users_id, [FromForm] string Content, [FromForm] int?Count_good, [FromForm] int?Count_notgood, [FromForm] uint?Index) { PostsInfo item = new PostsInfo(); item.Id = Id; item.Posts_id = Posts_id; item.Topics_id = Topics_id; item.Users_id = Users_id; item.Content = Content; item.Count_good = Count_good; item.Count_notgood = Count_notgood; item.Create_time = DateTime.Now; item.Index = Index; int affrows = Posts.Update(item); if (affrows > 0) { return(new APIReturn(0, "成功")); } return(new APIReturn(99, "失败")); }
public IActionResult GetPosts([FromBody] PostsInfo postsInfo) { var blog = _blogRepository.Blogs .FirstOrDefault(b => b.User.UserName == postsInfo.Username); if (blog == null) { return(NotFound("User not found")); } var tagsIsNotExist = postsInfo.Tags == null || !postsInfo.Tags.Any(); var posts = _postRepository.Posts.Include(p => p.PostTags) .Where(p => (postsInfo.Type == null || p.Type == postsInfo.Type) && p.Blog == blog && (tagsIsNotExist || p.PostTags.Any(t => postsInfo.Tags.Contains(t.Tag.Name)))) .OrderByDescending(p => p.Created); var totalItems = posts.Count(); return(Ok(new UserPostsViewData { Posts = posts .Skip((postsInfo.CurrentPage - 1) * ItemsPerPage) .Take(ItemsPerPage) .Select(p => new ItemViewData <Post> { Item = p, Likes = p.Likes.Count, IsLiked = _postLikeRepository.IsLiked(User.Identity.Name, p.Id), Comments = p.Comments.Count }), PagingInfo = new PagingInfo { CurrentPage = postsInfo.CurrentPage, TotalItems = totalItems, ItemsPerPage = ItemsPerPage } })); }
public IActionResult 发布话题([FromForm] string tab, [FromForm] string title, [FromForm] string t_content, [FromForm] uint[] topic_tags, [FromForm] string _csrf) { SqlHelper.Transaction(() => { TopicsInfo topic = Topics.Insert(new TopicsInfo { Title = title, Count_posts = 0, Count_views = 0, Create_time = DateTime.Now, Owner_users_id = LoginUser.Id, Top = 0 }); PostsInfo post = Posts.Insert(new PostsInfo { Content = t_content, Count_good = 0, Count_notgood = 0, Create_time = DateTime.Now, Topics_id = topic.Id, Users_id = LoginUser.Id, Index = 1 }); var tags_id = topic_tags.ToList(); TagsInfo tag = Tags.GetItemByKeyname(tab); if (tag.Id > 1) { tags_id.Add(tag.Id.Value); } foreach (uint tagid in tags_id) { topic.FlagTags(tagid); } }); RedisHelper.Remove("author_nonereply", "indextopics_all1", "indextopics_all2", "indextopics_all3", "indextopics_all4", "indextopics_good1", "indextopics_good2", "indextopics_good3", "indextopics_good4", "indextopics_share1", "indextopics_share2", "indextopics_share3", "indextopics_share4", "indextopics_ask1", "indextopics_ask2", "indextopics_ask3", "indextopics_ask4", "indextopics_job1", "indextopics_job2", "indextopics_job3", "indextopics_job4"); return(new RedirectResult("/")); }
public SqlUpdateBuild(PostsInfo item, ulong?Id) { _item = item; _where = SqlHelper.Addslashes("`id` = {0}", Id); }