Пример #1
0
        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;
        }
Пример #2
0
        public void AddPost(Models.ComboPost post)
        {
            Models.ComboResponse _response = new Models.ComboResponse();
            _response.bool_result = true;
            _response.ErrorCode = 0;
            _response.ErrorMsg = "";

            BLL.ComboPost newPost = new ComboPost();
            newPost.AddNew();

            if (post.ComboUserID != 0)
                newPost.ComboUserID = post.ComboUserID;
            else
            {
                _response.ErrorCode = 30;
                _response.ErrorMsg = "Can't insert post. No user id .";
                _response.bool_result = false;
                SetContentResult(_response);
                return;
            }

            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));
            if (att != null)
            {
                ComboPostAttachment attachment = new ComboPostAttachment();
                foreach (Models.Attachment item in att)
                {
                    attachment.AddNew();
                    attachment.AttachmentID = item.AttachmentID;
                    attachment.ComboPostID = newPost.ComboPostID;

                }
                attachment.Save();
            }

            ComboPostAttachment notificationAtt = new ComboPostAttachment();
            notificationAtt.GetPostAttachmentsByPostID(newPost.ComboPostID);

            Models.PostUserTag[] userTags = js.Deserialize<Models.PostUserTag[]>(js.Serialize(post.UserTags));
            if (userTags != null)
            {
                PostUserTag usertag = new PostUserTag();
                foreach (Models.PostUserTag item in userTags)
                {
                    usertag.AddNew();
                    usertag.ComboUserID = item.ComboUserID;
                    usertag.ComboPostID = newPost.ComboPostID;
                    usertag.Offset = item.Offset;

                    /**************************/
                    // save notification and push it to device
                    ComboUser creator = new ComboUser();
                    ComboUser tagged = new ComboUser();
                    creator.GetUserByUserId(newPost.ComboUserID);
                    tagged.GetUserByUserId(item.ComboUserID);
                    List<Models.PostUserTag> postTag = new List<Models.PostUserTag>();
                    postTag.Add(new Models.PostUserTag
                    {
                        ComboPostID = newPost.ComboPostID,
                        CreatorUserName = creator.UserName,
                        CreatorProfilePic = creator.GetColumn("ProfilePic").ToString(),
                        ComboUserID = tagged.ComboUserID,
                        UserName = tagged.UserName,
                        ProfilePic = tagged.GetColumn("ProfilePic").ToString(),
                        PostText = newPost.PostText,
                        Offset = item.Offset,
                        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(item.ComboUserID, newPost.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.PostHashTag[] hashTags = js.Deserialize<Models.PostHashTag[]>(js.Serialize(post.HashTags));
            if (hashTags != null)
            {
                PostHashTag posthashtag = new PostHashTag();

                foreach (Models.PostHashTag item in hashTags)
                {
                    HashTag currenttag = new HashTag();

                    if (!currenttag.GetHashTagByName(item.TagName))
                    {
                        currenttag.AddNew();
                        currenttag.Name = item.TagName;
                        currenttag.Save();
                    }

                    posthashtag.AddNew();
                    posthashtag.HashTagID = currenttag.HashTagID;
                    posthashtag.ComboPostID = newPost.ComboPostID;
                    posthashtag.Offset = item.Offset;
                }
                posthashtag.Save();
            }

            post.ComboPostID = newPost.ComboPostID;
            post.PostDate = newPost.PostDate.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
            _response.Entity = new Models.ComboPost[] { post };

            SetContentResult(_response);
            return;
        }
Пример #3
0
        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);
        }