public void DeleteMsg(int id) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboMsg msg = new ComboMsg(); msg.LoadByPrimaryKey(id); msg.IsDeleted = true; msg.Save(); _response.Entity = null; SetContentResult(_response); }
public void AddMessageComment(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.ComboMsgID != 0) newComment.ComboMsgID = comment.ComboMsgID; else { _response.ErrorCode = 31; _response.ErrorMsg = "Can't insert comment. No Msg id ."; _response.bool_result = false; SetContentResult(_response); return; } newComment.CommentText = comment.CommentText.Replace("\n", " "); ; newComment.CommentDate = DateTime.UtcNow; newComment.IsRead = false; newComment.Save(); /**************************/ // save notification and push it to device ComboMsg post = new ComboMsg(); post.LoadByPrimaryKey(comment.ComboMsgID); ComboUser creator = new ComboUser(); ComboUser commentor = new ComboUser(); creator.LoadByPrimaryKey(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 { ComboMsgID = Convert.ToInt32(row["ComboMsgID"]), 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() }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = post.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.COMMENT_ON_MESSAGE; // 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_MESSAGE); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(creator.ComboUserID, commentor.ComboUserID, (int)Combo.Models.NotificationType.COMMENT_ON_MESSAGE); 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); } } /**************************/ JavaScriptSerializer js = new JavaScriptSerializer(); Models.Attachment[] att = js.Deserialize<Models.Attachment[]>(js.Serialize(comment.Attachments)); ComboMsgAttachment attachment = new ComboMsgAttachment(); foreach (Models.Attachment item in att) { attachment.AddNew(); attachment.AttachmentID = item.AttachmentID; attachment.ComboMsgID = newComment.ComboMsgID; } attachment.Save(); 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 GetMessagesBetweenUsers(int _1stUserID,int _2ndUserID ,int Page) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboMsg Messages = new ComboMsg(); Messages.GetMessagesBetweenUsers(_1stUserID, _2ndUserID); List<Models.ComboMessage> Msgs = Messages.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboMessage { ComboMsgID = Convert.ToInt32(row["ComboMsgID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), ComboUserName = row["UserName"].ToString(), ProfilePic = row["ProfilePic"].ToString(), MsgText = row["MsgText"].ToString(), MsgDate = Convert.ToDateTime(row["MsgDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, ToIds = row["ToIds"].ToString().Replace("\"", "'") }; }).Skip(Page * MsgsPageSize).Take(MsgsPageSize).ToList(); foreach (Models.ComboMessage item in Msgs) { ComboComment totalCount = new ComboComment(); totalCount.GetMsgCommentsCount(item.ComboMsgID); item.CommentsCount = Convert.ToInt32(totalCount.GetColumn("TotalCount")); ComboComment comments = new ComboComment(); comments.GetMsgsCommentsByMsgID(item.ComboMsgID, "asc"); // get top 3 comments for each post item.Comments = comments.DefaultView.Table.AsEnumerable().Select(r => { return new Models.ComboComment { ComboCommentID = Convert.ToInt32(r["ComboCommentID"]), ComboMsgID = Convert.ToInt32(r["ComboMsgID"]), 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(Page * MsgsCommentsPageSize).Take(MsgsCommentsPageSize).ToList(); List<Models.ComboComment> _comm = item.Comments as List<Models.ComboComment>; foreach (Models.ComboComment _itemcomm in _comm) { ComboCommentAttachment c_attachments = new ComboCommentAttachment(); c_attachments.GetCommentAttachmentsByCommentID(_itemcomm.ComboCommentID); _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(); } item.Comments = _comm; ComboMsgAttachment attachments = new ComboMsgAttachment(); attachments.GetMsgAttachmentsByPostID(item.ComboMsgID); 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(); } _response.Entity = Msgs; SetContentResult(_response); //return _response; }
public void AddMessage(Models.ComboMessage msg) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; if (string.IsNullOrEmpty(msg.ToIds)) { _response.ErrorCode = 30; _response.ErrorMsg = "Can't add Msg. No to id ."; _response.bool_result = false; SetContentResult(_response); return; } if (msg.ToIds.Split(',').Length == 0) { _response.ErrorCode = 30; _response.ErrorMsg = "Can't add Msg. No to idsor error in format ."; _response.bool_result = false; SetContentResult(_response); return; } BLL.ComboMsg newMsg = new ComboMsg(); newMsg.AddNew(); if (msg.ComboUserID != 0) newMsg.ComboUserID = msg.ComboUserID; else { _response.ErrorCode = 30; _response.ErrorMsg = "Can't add Msg. No user id ."; _response.bool_result = false; SetContentResult(_response); return; } newMsg.MsgText = msg.MsgText.Replace("\n", " "); ; newMsg.MsgDate = DateTime.UtcNow; newMsg.IsRead = false; newMsg.Save(); string[] ToIds = msg.ToIds.Split(','); ComboUserMsg tomsg = new ComboUserMsg(); foreach (string item in ToIds) { tomsg.AddNew(); tomsg.ComboUserID = Convert.ToInt32(item); tomsg.ComboMsgID = newMsg.ComboMsgID; } tomsg.Save(); /**************************/ // save notification and push it to device ComboUser creator = new ComboUser(); ComboUser commentor = new ComboUser(); creator.GetUserByUserId(newMsg.ComboUserID); List<Models.ComboMessage> amsg = newMsg.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboMessage { ComboMsgID = Convert.ToInt32(row["ComboMsgID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), ComboUserName = creator.UserName, ComboUserDisplayName = creator.DisplayName, MsgText = newMsg.MsgText, MsgDate = newMsg.MsgDate.Subtract(new DateTime(1970, 1, 1)).TotalSeconds, ProfilePic = creator.GetColumn("ProfilePic").ToString() }; }).ToList(); foreach (string item in ToIds) { ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = Convert.ToInt32(item); notification.NotificationType = (int)Combo.Models.NotificationType.RECEIVE_MSG; // new Msg recieved notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(amsg); notification.IsRead = false; notification.Save(); commentor.GetUserByUserId(Convert.ToInt32(item)); NotificationUserSettings settings = new NotificationUserSettings(); settings.LoadByPrimaryKey(Convert.ToInt32(item), (int)Combo.Models.NotificationType.RECEIVE_MSG); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(commentor.ComboUserID, creator.ComboUserID, (int)Combo.Models.NotificationType.FOLLOW_FIREND); 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), commentor.DeviceID); } } /**************************/ JavaScriptSerializer js = new JavaScriptSerializer(); Models.Attachment[] att = js.Deserialize<Models.Attachment[]>(js.Serialize(msg.Attachments)); ComboMsgAttachment attachment = new ComboMsgAttachment(); foreach (Models.Attachment item in att) { attachment.AddNew(); attachment.AttachmentID = item.AttachmentID; attachment.ComboMsgID = newMsg.ComboMsgID; } attachment.Save(); msg.ComboMsgID = newMsg.ComboMsgID; msg.MsgDate = newMsg.MsgDate.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; _response.Entity = new Models.ComboMessage[] { msg }; SetContentResult(_response); return; }
public void GetCountUnReadNotificationsAndUnReadMsgComments(int userID) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboNotification notifications = new ComboNotification(); notifications.GetCountUnReadNotificationsbyUserId(userID); ComboMsg Msgs = new ComboMsg(); Msgs.GetUnReadMsgComments(userID); string result = "[{ 'TotalNotificationsCount' : " + notifications.GetColumn("TotalCount").ToString() + ", 'TotalMsgCommentsCount' : " + Msgs.GetColumn("MsgCommentsCounter").ToString() + " }]"; _response.Entity = result; SetContentResult(_response); //return _response; }