private void UpdateUserRank(int UserID) { ComboUser user = new ComboUser(); user.GetUserByUserId(UserID); UserActivityLog log = new UserActivityLog(); log.GetActivityDaysByUserID(user.ComboUserID); ComboPost posts = new ComboPost(); posts.GetUserPostsCountByUserID(user.ComboUserID); ComboComment comments = new ComboComment(); comments.GetPostCommentsCountByUserID(user.ComboUserID); ComboPostLike postLikes = new ComboPostLike(); postLikes.GetPostLikesCountByUserID(user.ComboUserID); ProfileFollower followers = new ProfileFollower(); followers.GetProfileFollowersCountByUserID(user.ComboUserID); ProfileFollower followings = new ProfileFollower(); followings.GetProfileFollowingCountByUserID(user.ComboUserID); ProfileLiker profileLikes = new ProfileLiker(); profileLikes.GetProfileLikerCountByUserID(user.ComboUserID); int oldRank = user.UserRankID; if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 365 || Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 3000 || Convert.ToInt32(comments.GetColumn("TotalCount")) > 3000 || Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 3000 || Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 3000 || Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 3000 || Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 3000) { user.UserRankID = 5; } else if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 240 || Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 2000 || Convert.ToInt32(comments.GetColumn("TotalCount")) > 2000 || Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 2000 || Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 2000 || Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 2000 || Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 2000) { user.UserRankID = 4; } else if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 120 || Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 1000 || Convert.ToInt32(comments.GetColumn("TotalCount")) > 1000 || Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 1000 || Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 1000 || Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 1000 || Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 1000) { user.UserRankID = 3; } else if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 30 || Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 500 || Convert.ToInt32(comments.GetColumn("TotalCount")) > 500 || Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 500 || Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 500 || Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 500 || Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 500) { user.UserRankID = 2; } user.Save(); if (user.UserRankID > oldRank) { /**************************/ // save notification and push it to device UserRank old = new UserRank(); old.LoadByPrimaryKey(oldRank); UserRank newrank = new UserRank(); newrank.LoadByPrimaryKey(user.UserRankID); List<Models.UserRankUpdated> arequest = user.DefaultView.Table.AsEnumerable().Select(row => { return new Models.UserRankUpdated { ComboUserID = Convert.ToInt32(row["ComboUserID"]), UserName = user.UserName, DisplayName = user.DisplayName, OldUserRankID = oldRank, NewUserRankID = user.UserRankID, OldRankName = old.Name, NewRankName = newrank.Name, ProfilePic = row["ProfilePic"].ToString() }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = user.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.UPDATE_USER_RANK; // update rank notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(arequest); notification.IsRead = false; notification.Save(); List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboNotification { ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), IsRead = Convert.ToBoolean(row["IsRead"]), NotificationBody = row["NotificationBody"].ToString(), NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, NotificationType = Convert.ToInt32(row["NotificationType"]) }; }).ToList(); SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), user.DeviceID); /**************************/ } }
protected void Page_Load(object sender, EventArgs e) { if (PostID != 0) { ComboPost post = new ComboPost(); post.GetPostByID(PostID); uiImageProfilePic.ImageUrl = "comboAPI/images.aspx?Image=" + post.GetColumn("ProfilePic").ToString(); uiLabelName.Text = post.GetColumn("UserName").ToString(); uiLabelDate.Text = post.PostDate.ToString("dd/MM/yyyy hh:mm tt"); uiLiteralText.Text = post.PostText; } }
public void AddComment(Models.ComboComment comment) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; BLL.ComboComment newComment = new ComboComment(); newComment.AddNew(); if (comment.ComboUserID != 0) newComment.ComboUserID = comment.ComboUserID; else { _response.ErrorCode = 30; _response.ErrorMsg = "Can't insert commnet. No user id ."; _response.bool_result = false; SetContentResult(_response); return; } if (comment.ComboPostID != 0) newComment.ComboPostID = comment.ComboPostID; else { _response.ErrorCode = 31; _response.ErrorMsg = "Can't insert comment. No post id ."; _response.bool_result = false; SetContentResult(_response); return; } newComment.CommentText = comment.CommentText.Replace("\n", " "); ; newComment.CommentDate = DateTime.UtcNow; newComment.Save(); JavaScriptSerializer js = new JavaScriptSerializer(); Models.Attachment[] att = js.Deserialize<Models.Attachment[]>(js.Serialize(comment.Attachments)); if (att != null) { ComboCommentAttachment attachment = new ComboCommentAttachment(); foreach (Models.Attachment item in att) { attachment.AddNew(); attachment.AttachmentID = item.AttachmentID; attachment.ComboCommnetID = newComment.ComboCommentID; } attachment.Save(); } ComboCommentAttachment notificationAtt = new ComboCommentAttachment (); notificationAtt.GetCommentAttachmentsByCommentID(newComment.ComboCommentID); Models.CommentUserTag[] userTags = js.Deserialize<Models.CommentUserTag[]>(js.Serialize(comment.UserTags)); if (userTags != null) { CommentUserTag usertag = new CommentUserTag(); foreach (Models.CommentUserTag item in userTags) { usertag.AddNew(); usertag.ComboUserID = item.ComboUserID; usertag.ComboCommentID = newComment.ComboCommentID; usertag.Offset = item.Offset; /**************************/ // save notification and push it to device ComboUser commentcreator = new ComboUser(); ComboUser tagged = new ComboUser(); commentcreator.GetUserByUserId(newComment.ComboUserID); tagged.GetUserByUserId(item.ComboUserID); List<Models.CommentUserTag> postTag = new List<Models.CommentUserTag>(); postTag.Add(new Models.CommentUserTag { ComboCommentID = newComment.ComboCommentID, ComboUserID = tagged.ComboUserID, UserName = tagged.UserName, Offset = item.Offset, ComboPostID = newComment.ComboPostID, CreatorUserID = commentcreator.ComboUserID, CreatorUserName= commentcreator.UserName, CreatorProfilePic = commentcreator.GetColumn("ProfilePic").ToString(), CommentText = newComment.CommentText, Attachments = notificationAtt.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(), }); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = tagged.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.TAG_USER_IN_POST; // tag user to post notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(postTag); notification.IsRead = false; notification.Save(); NotificationUserSettings settings = new NotificationUserSettings(); settings.LoadByPrimaryKey(tagged.ComboUserID, (int)Combo.Models.NotificationType.TAG_USER_IN_POST); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(tagged.ComboUserID, commentcreator.ComboUserID, (int)Combo.Models.NotificationType.TAG_USER_IN_POST); if (notify) { List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboNotification { ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), IsRead = Convert.ToBoolean(row["IsRead"]), NotificationBody = row["NotificationBody"].ToString(), NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, NotificationType = Convert.ToInt32(row["NotificationType"]) }; }).ToList(); SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), tagged.DeviceID); } /**************************/ } usertag.Save(); } Models.CommentHashTag[] hashTags = js.Deserialize<Models.CommentHashTag[]>(js.Serialize(comment.HashTags)); if (hashTags != null) { CommentHashTag commentthashtag = new CommentHashTag(); foreach (Models.CommentHashTag item in hashTags) { HashTag currenttag = new HashTag(); if (!currenttag.GetHashTagByName(item.TagName)) { currenttag.AddNew(); currenttag.Name = item.TagName; currenttag.Save(); } commentthashtag.AddNew(); commentthashtag.HashTagID = currenttag.HashTagID; commentthashtag.ComboCommentID = newComment.ComboCommentID; commentthashtag.Offset = item.Offset; } commentthashtag.Save(); } /**************************/ // save notification and push it to device ComboPost post = new ComboPost(); post.LoadByPrimaryKey(comment.ComboPostID); ComboUser creator = new ComboUser(); ComboUser commentor = new ComboUser(); ComboPostAttachment postatt = new ComboPostAttachment(); postatt.GetPostAttachmentsByPostID(comment.ComboPostID); creator.GetUserByUserId(post.ComboUserID); commentor.GetUserByUserId(comment.ComboUserID); if (creator.ComboUserID != commentor.ComboUserID) { List<Models.ComboComment> acomment = newComment.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboComment { ComboPostID = Convert.ToInt32(row["ComboPostID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), ComboUserName = commentor.UserName, ComboDisplayName = commentor.DisplayName, CommentText = newComment.CommentText, CommentDate = newComment.CommentDate.Subtract(new DateTime(1970, 1, 1)).TotalSeconds, ProfilePic = commentor.GetColumn("ProfilePic").ToString(), PostAttachemnts = postatt.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(), }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = post.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.COMMENT_ON_POST; // add comment to post notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(acomment); notification.IsRead = false; notification.Save(); NotificationUserSettings settings = new NotificationUserSettings(); settings.LoadByPrimaryKey(creator.ComboUserID, (int)Combo.Models.NotificationType.COMMENT_ON_POST); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(creator.ComboUserID, commentor.ComboUserID, (int)Combo.Models.NotificationType.COMMENT_ON_POST); if (notify) { List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboNotification { ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), IsRead = Convert.ToBoolean(row["IsRead"]), NotificationBody = row["NotificationBody"].ToString(), NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, NotificationType = Convert.ToInt32(row["NotificationType"]) }; }).ToList(); SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), creator.DeviceID); } } /**************************/ comment.ComboCommentID = newComment.ComboCommentID; comment.CommentDate = newComment.CommentDate.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; _response.Entity = new Models.ComboComment[] { comment }; SetContentResult(_response); return; }
public void UpdatePost(Models.ComboPost post) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; BLL.ComboPost newPost = new ComboPost(); newPost.LoadByPrimaryKey(post.ComboPostID); newPost.PostText = post.PostText.Replace("\n", " "); ; newPost.PostDate = DateTime.UtcNow; newPost.Save(); JavaScriptSerializer js = new JavaScriptSerializer(); Models.Attachment[] att = js.Deserialize<Models.Attachment[]>(js.Serialize(post.Attachments)); ComboPostAttachment attachment = new ComboPostAttachment(); foreach (Models.Attachment item in att) { try { attachment.AddNew(); attachment.AttachmentID = item.AttachmentID; attachment.ComboPostID = newPost.ComboPostID; attachment.Save(); } catch (Exception ex) { } } post.PostDate = newPost.PostDate.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; _response.Entity = new Models.ComboPost[] { post }; SetContentResult(_response); return; }
public void ToggleLikePostByID(int id,int userid) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboPostAttachment att = new ComboPostAttachment(); att.GetPostAttachmentsByPostID(id); ComboPostLike likes = new ComboPostLike(); if (!likes.LoadByPrimaryKey(userid, id)) { likes.AddNew(); likes.ComboPostID = id; likes.ComboUserID = userid; likes.Save(); // save notification and push it to device ComboPost post = new ComboPost(); post.LoadByPrimaryKey(id); ComboUser creator = new ComboUser(); ComboUser liker = new ComboUser(); creator.LoadByPrimaryKey(post.ComboUserID); liker.GetUserByUserId(userid); if (creator.ComboUserID != liker.ComboUserID) { List<Models.ComboPostLike> alike = likes.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboPostLike { ComboPostID = Convert.ToInt32(row["ComboPostID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), UserName = liker.UserName, DisplayName = liker.DisplayName, PostText = post.PostText, ProfilePic = liker.GetColumn("ProfilePic").ToString(), Attachments = att.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(), }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = post.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.LIKE; // like notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(alike); notification.IsRead = false; notification.Save(); NotificationUserSettings settings = new NotificationUserSettings(); settings.LoadByPrimaryKey(creator.ComboUserID, (int)Combo.Models.NotificationType.LIKE); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(creator.ComboUserID, liker.ComboUserID, (int)Combo.Models.NotificationType.LIKE); if (notify) { List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboNotification { ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), IsRead = Convert.ToBoolean(row["IsRead"]), NotificationBody = row["NotificationBody"].ToString(), NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, NotificationType = Convert.ToInt32(row["NotificationType"]) }; } ).ToList(); string notification_response = SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), creator.DeviceID); } } } else { likes.MarkAsDeleted(); likes.Save(); } likes.GetPostLikesByPostID(id); List<Models.ComboPostLike> Alllikes = likes.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboPostLike { ComboPostID = Convert.ToInt32(row["ComboPostID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), UserName = row["UserName"].ToString(), DisplayName = row["DisplayName"].ToString(), }; }).ToList(); _response.Entity = Alllikes; SetContentResult(_response); }
public void SharePost(int PostId, int UserId) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboPostShare post = new ComboPostShare(); post.AddNew(); post.ComboPostID = PostId; post.ShareDate = DateTime.UtcNow; post.ComboUserID = UserId; post.Save(); /**************************/ // save notification and push it to device ComboPost ref_post = new ComboPost(); ref_post.LoadByPrimaryKey(PostId); ComboPostAttachment att = new ComboPostAttachment(); att.GetPostAttachmentsByPostID(PostId); ComboUser creator = new ComboUser(); ComboUser requester = new ComboUser(); creator.LoadByPrimaryKey(ref_post.ComboUserID); requester.LoadByPrimaryKey(UserId); if (creator.ComboUserID != requester.ComboUserID) { List<Models.ComboSharePost> info = post.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboSharePost { ComboFriendID = requester.ComboUserID, ComboUserID = creator.ComboUserID, ComboUserName = creator.UserName, ComboFriendName = requester.UserName, ComboFriendDisplayName = requester.DisplayName, ComboPostID = Convert.ToInt32(row["ComboPostID"].ToString()), PostText = ref_post.PostText, Attachments = att.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(), }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = creator.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.SHARE_POST; // share post notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(info); notification.IsRead = false; notification.Save(); NotificationUserSettings settings = new NotificationUserSettings(); settings.LoadByPrimaryKey(creator.ComboUserID, (int)Combo.Models.NotificationType.SHARE_POST); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(creator.ComboUserID, requester.ComboUserID, (int)Combo.Models.NotificationType.SHARE_POST); if (notify) { List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboNotification { ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), IsRead = Convert.ToBoolean(row["IsRead"]), NotificationBody = row["NotificationBody"].ToString(), NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, NotificationType = Convert.ToInt32(row["NotificationType"]) }; }).ToList(); SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), creator.DeviceID); } } /**************************/ _response.Entity = null; SetContentResult(_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 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 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); }
public void DeletePost(int id) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboPost post = new ComboPost(); post.LoadByPrimaryKey(id); post.IsDeleted = true; post.Save(); _response.Entity = null; SetContentResult(_response); }