public static TopicsInfo GetItem(ulong?Id) { if (Id == null) { return(null); } if (itemCacheTimeout <= 0) { return(dal.GetItem(Id)); } string key = string.Concat("cnodejs_BLL_Topics_", Id); string value = RedisHelper.Get(key); if (!string.IsNullOrEmpty(value)) { try { return(new TopicsInfo(value)); } catch { } } TopicsInfo item = dal.GetItem(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 APIReturn Post_insert([FromForm] ulong?Last_posts_id, [FromForm] ulong?Owner_users_id, [FromForm] int?Count_posts, [FromForm] uint?Count_views, [FromForm] string Title, [FromForm] ulong?Top, [FromForm] uint[] mn_Tags, [FromForm] ulong[] mn_Users) { TopicsInfo item = new TopicsInfo(); item.Last_posts_id = Last_posts_id; item.Owner_users_id = Owner_users_id; item.Count_posts = Count_posts; item.Count_views = Count_views; item.Create_time = DateTime.Now; item.Title = Title; item.Top = Top; item.Update_time = DateTime.Now; item = Topics.Insert(item); //关联 Tags foreach (uint mn_Tags_in in mn_Tags) { item.FlagTags(mn_Tags_in); } //关联 Users foreach (ulong mn_Users_in in mn_Users) { item.FlagUsers(mn_Users_in); } return(new APIReturn(0, "成功", "item", item.ToBson())); }
public static cnodejs.DAL.Topics.SqlUpdateBuild UpdateDiy(TopicsInfo item, ulong?Id) { if (itemCacheTimeout > 0) { RemoveCache(item != null ? item : GetItem(Id)); } return(new cnodejs.DAL.Topics.SqlUpdateBuild(item, Id)); }
public static int Update(TopicsInfo item) { if (itemCacheTimeout > 0) { RemoveCache(item); } return(dal.Update(item)); }
private static void RemoveCache(TopicsInfo item) { if (item == null) { return; } RedisHelper.Remove(string.Concat("cnodejs_BLL_Topics_", item.Id)); }
public static TopicsInfo Insert(TopicsInfo item) { item = dal.Insert(item); if (itemCacheTimeout > 0) { RemoveCache(item); } return(item); }
public TopicsInfo Insert(TopicsInfo 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) { TopicsInfo item = Topics.GetItem(Id); if (item == null) { return(new APIReturn(98, "记录不存在,或者没有权限")); } return(new APIReturn(0, "成功", "item", item.ToBson())); }
public int Update(TopicsInfo item) { return(new SqlUpdateBuild(null, item.Id) .SetLast_posts_id(item.Last_posts_id) .SetOwner_users_id(item.Owner_users_id) .SetCount_posts(item.Count_posts) .SetCount_views(item.Count_views) .SetCreate_time(item.Create_time) .SetTitle(item.Title) .SetTop(item.Top) .SetUpdate_time(item.Update_time).ExecuteNonQuery()); }
public IActionResult 除(ulong id) { TopicsInfo topic = Topics.GetItem(id); if (topic.Owner_users_id == LoginUser.Id || LoginUser.Id == 1 //管理员 ) { Topics.Delete(id); return(Json(new { success = true, message = "成功" })); } return(Json(new { success = false, message = "没有权限删除" })); }
protected static MySqlParameter[] GetParameters(TopicsInfo item) { return(new MySqlParameter[] { GetParameter("?id", MySqlDbType.UInt64, 20, item.Id), GetParameter("?last_posts_id", MySqlDbType.UInt64, 20, item.Last_posts_id), GetParameter("?owner_users_id", MySqlDbType.UInt64, 20, item.Owner_users_id), GetParameter("?count_posts", MySqlDbType.Int32, 11, item.Count_posts), GetParameter("?count_views", MySqlDbType.UInt32, 10, item.Count_views), GetParameter("?create_time", MySqlDbType.DateTime, -1, item.Create_time), GetParameter("?title", MySqlDbType.VarChar, 255, item.Title), GetParameter("?top", MySqlDbType.UInt64, 20, item.Top), GetParameter("?update_time", MySqlDbType.DateTime, -1, item.Update_time) }); }
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(TopicsInfo item, ulong?Id) { _item = item; _where = SqlHelper.Addslashes("`id` = {0}", Id); }
public APIReturn Put_update(ulong?Id, [FromForm] ulong?Last_posts_id, [FromForm] ulong?Owner_users_id, [FromForm] int?Count_posts, [FromForm] uint?Count_views, [FromForm] string Title, [FromForm] ulong?Top, [FromForm] uint[] mn_Tags, [FromForm] ulong[] mn_Users) { TopicsInfo item = new TopicsInfo(); item.Id = Id; item.Last_posts_id = Last_posts_id; item.Owner_users_id = Owner_users_id; item.Count_posts = Count_posts; item.Count_views = Count_views; item.Create_time = DateTime.Now; item.Title = Title; item.Top = Top; item.Update_time = DateTime.Now; int affrows = Topics.Update(item); //关联 Tags if (mn_Tags.Length == 0) { item.UnflagTagsALL(); } else { List <uint> mn_Tags_list = mn_Tags.ToList(); foreach (TagsInfo Obj_tags in item.Obj_tagss) { int idx = mn_Tags_list.FindIndex(a => a == Obj_tags.Id); if (idx == -1) { item.UnflagTags(Obj_tags.Id); } else { mn_Tags_list.RemoveAt(idx); } } mn_Tags_list.ForEach(a => item.FlagTags(a)); } //关联 Users if (mn_Users.Length == 0) { item.UnflagUsersALL(); } else { List <ulong> mn_Users_list = mn_Users.ToList(); foreach (UsersInfo Obj_users in item.Obj_userss) { int idx = mn_Users_list.FindIndex(a => a == Obj_users.Id); if (idx == -1) { item.UnflagUsers(Obj_users.Id); } else { mn_Users_list.RemoveAt(idx); } } mn_Users_list.ForEach(a => item.FlagUsers(a)); } if (affrows > 0) { return(new APIReturn(0, "成功")); } return(new APIReturn(99, "失败")); }