public void GetPosts(int UserID, int Page) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboPost posts = new ComboPost(); posts.GetPostByUserID(UserID); List<Models.ComboPost> Posts = posts.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboPost { ComboPostID = Convert.ToInt32(row["ComboPostID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), ComboUserName = row["UserName"].ToString(), ProfilePic = row["ProfilePic"].ToString(), PostText = row["PostText"].ToString(), PostDate = Convert.ToDateTime(row["PostDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, IsDownloadable = (row["IsPostsDownloadable"] == DBNull.Value) ? false : Convert.ToBoolean(row["IsPostsDownloadable"]), Source = Convert.ToInt32(row["Source"]), IsFavourite = Convert.ToBoolean(row["IsFavourite"]), IsLike = Convert.ToBoolean(row["IsLike"]), UserRankID = Convert.ToInt32(row["UserRankID"]), IsCommented = Convert.ToBoolean(row["IsCommented"]), IsReposted = Convert.ToBoolean(row["IsReposted"]), }; }).Skip(Page * PostsPageSize).Take(PostsPageSize).ToList(); foreach (Models.ComboPost item in Posts) { ComboPostLike likes = new ComboPostLike(); likes.GetPostLikesByPostID(item.ComboPostID); item.Likes = likes.DefaultView.Table.AsEnumerable().Select(r => { return new Models.ComboPostLike { ComboPostID = Convert.ToInt32(r["ComboPostID"]), ComboUserID = Convert.ToInt32(r["ComboUserID"]), UserName = r["UserName"].ToString(), }; }).ToList(); ComboComment totalCount = new ComboComment(); totalCount.GetPostCommentsCount(item.ComboPostID); item.CommentsCount = Convert.ToInt32(totalCount.GetColumn("TotalCount")); ComboPostShare shareCount = new ComboPostShare(); shareCount.GetPostShareCount(item.ComboPostID); item.ShareCount = Convert.ToInt32(shareCount.GetColumn("TotalCount")); ComboComment comments = new ComboComment(); comments.GetTopPostCommentsByPostID(item.ComboPostID); // get top 3 comments for each post item.Comments = comments.DefaultView.Table.AsEnumerable().Select(r => { return new Models.ComboComment { ComboCommentID = Convert.ToInt32(r["ComboCommentID"]), ComboPostID = Convert.ToInt32(r["ComboPostID"]), ComboUserID = Convert.ToInt32(r["ComboUserID"]), ComboUserName = r["UserName"].ToString(), ProfilePic = r["ProfilePic"].ToString(), CommentText = r["CommentText"].ToString(), CommentDate = Convert.ToDateTime(r["CommentDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, }; }).ToList(); List<Models.ComboComment> _comm = item.Comments as List<Models.ComboComment>; foreach (Models.ComboComment _itemcomm in _comm) { ComboCommentLike c_likes = new ComboCommentLike(); ComboCommentAttachment c_attachments = new ComboCommentAttachment(); c_likes.GetCommentLikesByCommentID(_itemcomm.ComboCommentID); c_attachments.GetCommentAttachmentsByCommentID(_itemcomm.ComboCommentID); _itemcomm.Likes = c_likes.DefaultView.Table.AsEnumerable().Select(r => { return new Models.ComboCommentLike { ComboCommentID = Convert.ToInt32(r["ComboCommentID"]), ComboUserID = Convert.ToInt32(r["ComboUserID"]), UserName = r["UserName"].ToString(), }; }).ToList(); _itemcomm.Attachments = c_attachments.DefaultView.Table.AsEnumerable().Select(r => { return new Models.Attachment { AttachmentID = Convert.ToInt32(r["AttachmentID"]), Path = r["Path"].ToString(), AttachmentTypeID = Convert.ToInt32(r["AttachmentTypeID"]), ThumbsPath = r["ThumbsPath"].ToString() }; }).ToList(); // get user mention CommentUserTag CommentuserTags = new CommentUserTag(); CommentuserTags.GetUserTagsByCommentID(_itemcomm.ComboCommentID); _itemcomm.UserTags = CommentuserTags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.CommentUserTag { ComboCommentID = Convert.ToInt32(r["ComboCommentID"]), UserName = r["Username"].ToString(), ComboUserID = Convert.ToInt32(r["ComboUserID"]), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(); // get hashtags CommentHashTag Commenthastags = new CommentHashTag(); Commenthastags.GetHashTagsByCommnetID(_itemcomm.ComboCommentID); _itemcomm.HashTags = Commenthastags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.CommentHashTag { HashTagID = Convert.ToInt32(r["HashTagID"]), TagName = r["Name"].ToString(), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(); } item.Comments = _comm; ComboPostAttachment attachments = new ComboPostAttachment(); attachments.GetPostAttachmentsByPostID(item.ComboPostID); item.Attachments = attachments.DefaultView.Table.AsEnumerable().Select(r => { return new Models.Attachment { AttachmentID = Convert.ToInt32(r["AttachmentID"]), Path = r["Path"].ToString(), AttachmentTypeID = Convert.ToInt32(r["AttachmentTypeID"]), ThumbsPath = r["ThumbsPath"].ToString() }; }).ToList(); // get user mention PostUserTag userTags = new PostUserTag(); userTags.GetUserTagsByPostID(item.ComboPostID); item.UserTags = userTags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.PostUserTag { ComboPostID = Convert.ToInt32(r["ComboPostID"]), UserName = r["Username"].ToString(), ComboUserID = Convert.ToInt32(r["ComboUserID"]), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(); // get hashtags PostHashTag hastags = new PostHashTag(); hastags.GetHashTagsByPostID(item.ComboPostID); item.HashTags = hastags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.PostHashTag { HashTagID = Convert.ToInt32(r["HashTagID"]), TagName = r["Name"].ToString(), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(); } _response.Entity = Posts; SetContentResult(_response); // calculate user rank in another thread // and send notifications with followers birthday ThreadPool.QueueUserWorkItem(delegate { if (AddActivityLog(UserID, DateTime.Now.Date)) { SendFollowersBirthdaysNotifications(UserID); UpdateUserRank(UserID); } }); //return _response; }
public void SearchPosts(string filterText, int requester,int Page) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboPost posts = new ComboPost(); posts.SearchPosts(filterText, requester); List<Models.ComboPost> Posts = posts.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboPost { ComboPostID = Convert.ToInt32(row["ComboPostID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), ComboUserName = row["UserName"].ToString(), ProfilePic = row["ProfilePic"].ToString(), PostText = row["PostText"].ToString(), PostDate = Convert.ToDateTime(row["PostDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, IsDownloadable = (row["IsPostsDownloadable"] == DBNull.Value) ? false : Convert.ToBoolean(row["IsPostsDownloadable"]) }; }).Skip(Page * PostsPageSize).Take(PostsPageSize).ToList(); foreach (Models.ComboPost item in Posts) { ComboPostLike likes = new ComboPostLike(); likes.GetPostLikesByPostID(item.ComboPostID); item.Likes = likes.DefaultView.Table.AsEnumerable().Select(r => { return new Models.ComboPostLike { ComboPostID = Convert.ToInt32(r["ComboPostID"]), ComboUserID = Convert.ToInt32(r["ComboUserID"]), UserName = r["UserName"].ToString(), }; }).ToList(); ComboComment totalCount = new ComboComment(); totalCount.GetPostCommentsCount(item.ComboPostID); item.CommentsCount = Convert.ToInt32(totalCount.GetColumn("TotalCount")); ComboPostShare shareCount = new ComboPostShare(); shareCount.GetPostShareCount(item.ComboPostID); item.ShareCount = Convert.ToInt32(shareCount.GetColumn("TotalCount")); ComboComment comments = new ComboComment(); comments.GetTopPostCommentsByPostID(item.ComboPostID); // get top 3 comments for each post item.Comments = comments.DefaultView.Table.AsEnumerable().Select(r => { return new Models.ComboComment { ComboCommentID = Convert.ToInt32(r["ComboCommentID"]), ComboPostID = Convert.ToInt32(r["ComboPostID"]), ComboUserID = Convert.ToInt32(r["ComboUserID"]), ComboUserName = r["UserName"].ToString(), ProfilePic = r["ProfilePic"].ToString(), CommentText = r["CommentText"].ToString(), CommentDate = Convert.ToDateTime(r["CommentDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, }; }).ToList(); List<Models.ComboComment> _comm = item.Comments as List<Models.ComboComment>; foreach (Models.ComboComment _itemcomm in _comm) { ComboCommentLike c_likes = new ComboCommentLike(); ComboCommentAttachment c_attachments = new ComboCommentAttachment(); c_likes.GetCommentLikesByCommentID(_itemcomm.ComboCommentID); c_attachments.GetCommentAttachmentsByCommentID(_itemcomm.ComboCommentID); _itemcomm.Likes = c_likes.DefaultView.Table.AsEnumerable().Select(r => { return new Models.ComboCommentLike { ComboCommentID = Convert.ToInt32(r["ComboCommentID"]), ComboUserID = Convert.ToInt32(r["ComboUserID"]), UserName = r["UserName"].ToString(), }; }).ToList(); _itemcomm.Attachments = c_attachments.DefaultView.Table.AsEnumerable().Select(r => { return new Models.Attachment { AttachmentID = Convert.ToInt32(r["AttachmentID"]), Path = r["Path"].ToString(), AttachmentTypeID = Convert.ToInt32(r["AttachmentTypeID"]), ThumbsPath = r["ThumbsPath"].ToString() }; }).ToList(); // get user mention CommentUserTag CommentuserTags = new CommentUserTag(); CommentuserTags.GetUserTagsByCommentID(_itemcomm.ComboCommentID); _itemcomm.UserTags = CommentuserTags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.CommentUserTag { ComboCommentID = Convert.ToInt32(r["ComboCommentID"]), UserName = r["Username"].ToString(), ComboUserID = Convert.ToInt32(r["ComboUserID"]), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(); // get hashtags CommentHashTag Commenthastags = new CommentHashTag(); Commenthastags.GetHashTagsByCommnetID(_itemcomm.ComboCommentID); _itemcomm.HashTags = Commenthastags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.CommentHashTag { HashTagID = Convert.ToInt32(r["HashTagID"]), TagName = r["Name"].ToString(), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(); } item.Comments = _comm; ComboPostAttachment attachments = new ComboPostAttachment(); attachments.GetPostAttachmentsByPostID(item.ComboPostID); item.Attachments = attachments.DefaultView.Table.AsEnumerable().Select(r => { return new Models.Attachment { AttachmentID = Convert.ToInt32(r["AttachmentID"]), Path = r["Path"].ToString(), AttachmentTypeID = Convert.ToInt32(r["AttachmentTypeID"]), ThumbsPath = r["ThumbsPath"].ToString() }; }).ToList(); // get user mention PostUserTag userTags = new PostUserTag(); userTags.GetUserTagsByPostID(item.ComboPostID); item.UserTags = userTags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.PostUserTag { ComboPostID = Convert.ToInt32(r["ComboPostID"]), UserName = r["Username"].ToString(), ComboUserID = Convert.ToInt32(r["ComboUserID"]), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(); // get hashtags PostHashTag hastags = new PostHashTag(); hastags.GetHashTagsByPostID(item.ComboPostID); item.HashTags = hastags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.PostHashTag { HashTagID = Convert.ToInt32(r["HashTagID"]), TagName = r["Name"].ToString(), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(); } _response.Entity = Posts; SetContentResult(_response); //return _response; }
public void GetPostByID(int id, int CommentPage) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboPost post = new ComboPost(); post.GetPostByID(id); ComboPostLike likes = new ComboPostLike(); ComboPostAttachment attachments = new ComboPostAttachment(); ComboComment comments = new ComboComment(); likes.GetPostLikesByPostID(post.ComboPostID); attachments.GetPostAttachmentsByPostID(post.ComboPostID); comments.GetPostCommentsByPostID(post.ComboPostID); PostUserTag userTags = new PostUserTag(); userTags.GetUserTagsByPostID(post.ComboPostID); PostHashTag hastags = new PostHashTag(); hastags.GetHashTagsByPostID(post.ComboPostID); ComboComment totalCount = new ComboComment(); totalCount.GetPostCommentsCount(post.ComboPostID); ComboPostShare shareCount = new ComboPostShare(); shareCount.GetPostShareCount(post.ComboPostID); List<Models.ComboPost> Post = post.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboPost { ComboPostID = Convert.ToInt32(row["ComboPostID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), ComboUserName = row["UserName"].ToString(), ProfilePic = row["ProfilePic"].ToString(), PostText = row["PostText"].ToString(), PostDate = Convert.ToDateTime(row["PostDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, IsDownloadable = (row["IsPostsDownloadable"] == DBNull.Value) ? false : Convert.ToBoolean(row["IsPostsDownloadable"]), CommentsCount = Convert.ToInt32(totalCount.GetColumn("TotalCount")), ShareCount = Convert.ToInt32(shareCount.GetColumn("TotalCount")), Likes = likes.DefaultView.Table.AsEnumerable().Select(r => { return new Models.ComboPostLike { ComboPostID = Convert.ToInt32(r["ComboPostID"]), ComboUserID = Convert.ToInt32(r["ComboUserID"]), UserName = r["UserName"].ToString(), }; }).ToList(), // get top 20 comment for post Comments = comments.DefaultView.Table.AsEnumerable().Select(r => { return new Models.ComboComment { ComboCommentID = Convert.ToInt32(r["ComboCommentID"]), ComboPostID = Convert.ToInt32(r["ComboPostID"]), ComboUserID = Convert.ToInt32(r["ComboUserID"]), ComboUserName = r["UserName"].ToString(), ProfilePic = r["ProfilePic"].ToString(), CommentText = r["CommentText"].ToString(), CommentDate = Convert.ToDateTime(r["CommentDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, }; }).Skip(CommentPage * CommentsPageSize).Take(CommentsPageSize).ToList(), Attachments = attachments.DefaultView.Table.AsEnumerable().Select(r => { return new Models.Attachment { AttachmentID = Convert.ToInt32(r["AttachmentID"]), Path = r["Path"].ToString(), AttachmentTypeID = Convert.ToInt32(r["AttachmentTypeID"]), ThumbsPath = r["ThumbsPath"].ToString() }; }).ToList(), // get user mention UserTags = userTags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.PostUserTag { ComboPostID = Convert.ToInt32(r["ComboPostID"]), UserName = r["Username"].ToString(), ComboUserID = Convert.ToInt32(r["ComboUserID"]), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(), // get hashtags HashTags = hastags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.PostHashTag { HashTagID = Convert.ToInt32(r["HashTagID"]), TagName = r["Name"].ToString(), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(), UserRankID = Convert.ToInt32(row["UserRankID"]), }; }).ToList(); foreach (Models.ComboPost item in Post) { List<Models.ComboComment> comm = (List<Models.ComboComment>)item.Comments; for (int i = 0; i < comm.Count;i++ ) { ComboCommentLike c_likes = new ComboCommentLike(); ComboCommentAttachment c_attachments = new ComboCommentAttachment(); c_likes.GetCommentLikesByCommentID(comm[i].ComboCommentID); c_attachments.GetCommentAttachmentsByCommentID(comm[i].ComboCommentID); comm[i].Likes = c_likes.DefaultView.Table.AsEnumerable().Select(r => { return new Models.ComboCommentLike { ComboCommentID = Convert.ToInt32(r["ComboCommentID"]), ComboUserID = Convert.ToInt32(r["ComboUserID"]), UserName = r["UserName"].ToString(), }; }).ToList(); comm[i].Attachments = c_attachments.DefaultView.Table.AsEnumerable().Select(r => { return new Models.Attachment { AttachmentID = Convert.ToInt32(r["AttachmentID"]), Path = r["Path"].ToString(), AttachmentTypeID = Convert.ToInt32(r["AttachmentTypeID"]), ThumbsPath = r["ThumbsPath"].ToString() }; }).ToList(); // get user mention CommentUserTag CommentuserTags = new CommentUserTag(); CommentuserTags.GetUserTagsByCommentID(comm[i].ComboCommentID); comm[i].UserTags = CommentuserTags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.CommentUserTag { ComboCommentID = Convert.ToInt32(r["ComboCommentID"]), UserName = r["Username"].ToString(), ComboUserID = Convert.ToInt32(r["ComboUserID"]), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(); // get hashtags CommentHashTag Commenthastags = new CommentHashTag(); Commenthastags.GetHashTagsByCommnetID(comm[i].ComboCommentID); comm[i].HashTags = Commenthastags.DefaultView.Table.AsEnumerable().Select(r => { return new Models.CommentHashTag { HashTagID = Convert.ToInt32(r["HashTagID"]), TagName = r["Name"].ToString(), Offset = Convert.ToInt32(r["Offset"]) }; }).ToList(); } } _response.Entity = Post; SetContentResult(_response); }