Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void DeleteSharedPost(int UserID, int PostID)
        {
            Models.ComboResponse _response = new Models.ComboResponse();
            _response.bool_result = true;
            _response.ErrorCode = 0;
            _response.ErrorMsg = "";

            ComboPostShare post = new ComboPostShare();
            post.GetPostByUserIDAndPostID(UserID, PostID);
            post.MarkAsDeleted();
            post.Save();
            _response.Entity = null;
            SetContentResult(_response);
        }