Ejemplo n.º 1
1
        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);
                /**************************/
            }
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        public void ToggleNotificationIsRead(int id, bool isRead)
        {
            Models.ComboResponse _response = new Models.ComboResponse();
            _response.bool_result = true;
            _response.ErrorCode = 0;
            _response.ErrorMsg = "";

            ComboNotification notification = new ComboNotification();
            if (notification.LoadByPrimaryKey(id))
            {
                notification.IsRead = isRead;
                notification.Save();

            }

            _response.Entity = null;
            SetContentResult(_response);
        }
Ejemplo n.º 4
0
        private void SendFollowersBirthdaysNotifications(int UserID)
        {
            ProfileFollower followers = new ProfileFollower();
            ComboUser NotifiedUser = new ComboUser();
            NotifiedUser.GetUserByUserId(UserID);
            followers.GetProfileFollowersByUserID(UserID);
            for (int i = 0; i < followers.RowCount; i++)
            {
                ComboUser current = new ComboUser();
                current.GetUserByUserId(followers.ComboFollowerID);

                List<Models.ComboUser> info = current.DefaultView.Table.AsEnumerable().Select(row =>
                {
                    return new Models.ComboUser
                    {
                        ComboUserID = Convert.ToInt32(row["ComboUserID"]),
                        UserName = row["UserName"].ToString(),
                        DisplayName = row["DisplayName"].ToString(),
                        Password = row["Password"].ToString(),
                        Email = row["Email"].ToString(),
                        Bio = row["Bio"].ToString(),
                        ProfileImgID = row.IsNull("ProfileImgID") ? 0 : Convert.ToInt32(row["ProfileImgID"]),
                        CoverImgID = row.IsNull("CoverImgID") ? 0 : Convert.ToInt32(row["CoverImgID"]),
                        GenderID = row.IsNull("GenderID") ? 0 : Convert.ToInt32(row["GenderID"]),
                        IsActivated = row.IsNull("IsActivated") ? false : Convert.ToBoolean(row["IsActivated"]),
                        ExternalIDType = row.IsNull("ExternalIDType") ? 0 : Convert.ToInt32(row["ExternalIDType"]),
                        ExternalID = row["ExternalID"].ToString(),
                        DeviceID = row["DeviceID"].ToString(),
                        ProfilePic = row["ProfilePic"].ToString(),
                        CoverPic = row["CoverPic"].ToString(),
                        UserRankID = Convert.ToInt32(row["UserRankID"]),
                        BirthDate = row.IsNull("BirthDate") ? DateTime.MinValue : Convert.ToDateTime(row["BirthDate"]),
                        Country = row["Country"].ToString(),
                        Phone = row["Phone"].ToString(),
                        Website = row["Website"].ToString(),
                        CountryFlagPath = row["CountryFlagPath"].ToString(),
                        Location = row["Location"].ToString(),
                        IsPrivateAccount = row.IsNull("IsPrivateAccount") ? false : Convert.ToBoolean(row["IsPrivateAccount"]),
                    };
                }).ToList();

                ComboNotification notification = new ComboNotification();
                notification.AddNew();
                notification.ComboUserID = NotifiedUser.ComboUserID;
                notification.NotificationType = (int)Combo.Models.NotificationType.FOLLOWER_BIRTHDAY; // like
                notification.NotificationDate = DateTime.UtcNow;
                notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(info);
                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), NotifiedUser.DeviceID);

                followers.MoveNext();
            }
        }
Ejemplo n.º 5
0
        public void ToggleLikeFriend(int userId, int LikerId)
        {
            Models.ComboResponse _response = new Models.ComboResponse();
            _response.bool_result = true;
            _response.ErrorCode = 0;
            _response.ErrorMsg = "";
            bool like = false;

            ProfileLiker Liker = new ProfileLiker();
            if (!Liker.LoadByPrimaryKey(userId, LikerId))
            {
                Liker.AddNew();
                Liker.ComboLikerID = LikerId;
                Liker.ComboUserID = userId;
                Liker.Save();
                like = true;
            }
            else
            {
                Liker.MarkAsDeleted();
                Liker.Save();
            }

            /**************************/
            // save notification and push it to device
            ComboUser creator = new ComboUser();
            ComboUser P_Liker = new ComboUser();
            creator.LoadByPrimaryKey(userId);
            P_Liker.LoadByPrimaryKey(LikerId);

            ComboNotification notification = new ComboNotification();
            notification.AddNew();
            notification.ComboUserID = creator.ComboUserID;
            if (like)
                notification.NotificationType = (int)Combo.Models.NotificationType.LIKE_PROFILE; // Like friend
            else
                notification.NotificationType = (int)Combo.Models.NotificationType.UNLIKE_PROFILE; // unLike friend
            notification.NotificationDate = DateTime.UtcNow;
            notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject("[{'ComboUserID':" + creator.ComboUserID + ",'ComboFriendID':" + P_Liker.ComboUserID + ",'ComboUsername:'******'" + ",'ComboDisplayName:'" + P_Liker.DisplayName + "', 'IsFollowUser' : " + like + "}]");
            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), creator.DeviceID);
            /**************************/

            _response.Entity = null;
            SetContentResult(_response);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
        public void ToggleFollowFriend(int userId, int FollowerId)
        {
            Models.ComboResponse _response = new Models.ComboResponse();
            _response.bool_result = true;
            _response.ErrorCode = 0;
            _response.ErrorMsg = "";
            bool follow = false;

            ProfileFollower follower = new ProfileFollower();
            if (!follower.LoadByPrimaryKey(userId, FollowerId))
            {
                follower.AddNew();
                follower.ComboFollowerID = FollowerId;
                follower.ComboUserID = userId;
                follower.IsRequestApproved = true;
                follower.Save();
                follow = true;
            }
            else
            {
                follower.MarkAsDeleted();
                follower.Save();
            }

            if (follow)
            {
                /**************************/
                // save notification and push it to device
                ComboUser creator = new ComboUser();
                ComboUser commentor = new ComboUser();
                creator.GetUserByUserId(userId);
                commentor.GetUserByUserId(FollowerId);

                List<Models.FollowRequest> arequest = follower.DefaultView.Table.AsEnumerable().Select(row =>
                {
                    return new Models.FollowRequest
                    {
                        ComboFriendID = Convert.ToInt32(row["ComboFollowerID"]),
                        ComboUserID = Convert.ToInt32(row["ComboUserID"]),
                        ComboUserName = commentor.UserName,
                        ComboDisplayName = commentor.DisplayName,
                        ProfilePic = creator.GetColumn("ProfilePic").ToString(),
                        FriendProfilePic = commentor.GetColumn("ProfilePic").ToString(),
                        IsFollowUser = follow
                    };
                }).ToList();

                ComboNotification notification = new ComboNotification();
                notification.AddNew();
                notification.ComboUserID = creator.ComboUserID;
                if (follow)
                    notification.NotificationType = (int)Combo.Models.NotificationType.FOLLOW_FIREND; // follow friend
                else
                    notification.NotificationType = (int)Combo.Models.NotificationType.UNFOLLOW_FRIEND; // unfollow friend
                notification.NotificationDate = DateTime.UtcNow;
                notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(arequest);
                notification.IsRead = false;
                notification.Save();

                NotificationUserSettings settings = new NotificationUserSettings();
                settings.LoadByPrimaryKey(creator.ComboUserID, (int)Combo.Models.NotificationType.FOLLOW_FIREND);
                bool notify = false;
                if (settings.RowCount == 0)
                    notify = true;
                else
                    notify = settings.CanGetNotification(creator.ComboUserID, commentor.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), creator.DeviceID);
                }
                /**************************/
            }

            _response.Entity = null;
            SetContentResult(_response);
        }
Ejemplo n.º 9
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.º 10
0
        public void RespondToFriendRequest(int userId, int FriendId, bool isAccepted)
        {
            Models.ComboResponse _response = new Models.ComboResponse();
            _response.bool_result = true;
            _response.ErrorCode = 0;
            _response.ErrorMsg = "";

            ComboUserFriend friend = new ComboUserFriend();
            if (friend.LoadByPrimaryKey(userId, FriendId))
            {
                if (isAccepted)
                {
                    friend.RequestApproved = true;
                }
                else
                {
                    friend.MarkAsDeleted();
                }
                friend.Save();

                if (isAccepted)
                {
                    /**************************/
                    // save notification and push it to device
                    ComboUser creator = new ComboUser();
                    ComboUser requester = new ComboUser();
                    creator.LoadByPrimaryKey(userId);
                    requester.LoadByPrimaryKey(FriendId);

                    List<Models.ComboFriendRequest> arequest = friend.DefaultView.Table.AsEnumerable().Select(row =>
                    {
                        return new Models.ComboFriendRequest
                        {
                            ComboFriendID = Convert.ToInt32(row["ComboFriendID"]),
                            ComboUserID = Convert.ToInt32(row["ComboUserID"]),
                            ComboUserName = creator.UserName,
                            ComboFriendName = requester.UserName,
                            ComboFriendDisplayName = requester.DisplayName
                        };
                    }).ToList();

                    ComboNotification notification = new ComboNotification();
                    notification.AddNew();
                    notification.ComboUserID = requester.ComboUserID;
                    notification.NotificationType = (int)Combo.Models.NotificationType.ACCEPT_FRIEND; // accept friend request
                    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), requester.DeviceID);
                    /**************************/
                }
            }

            _response.Entity = null;
            SetContentResult(_response);
        }
Ejemplo n.º 11
0
        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;
        }
Ejemplo n.º 12
0
        public void GetNotifications(int userID, int pageIndex)
        {
            Models.ComboResponse _response = new Models.ComboResponse();
            _response.bool_result = true;
            _response.ErrorCode = 0;
            _response.ErrorMsg = "";

            ComboNotification notifications = new ComboNotification();
            notifications.GetNotificationsbyUserId(userID);
            List<Models.ComboNotification> allnotifications = notifications.DefaultView.Table.AsEnumerable().Select(row =>
            {
                return new Models.ComboNotification
                {
                    ComboUserID = Convert.ToInt32(row["ComboUserID"]),
                    ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]),
                    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"])
                };
            }).Skip(pageIndex * NotificationPageSize).Take(NotificationPageSize).ToList();

            _response.Entity = allnotifications;
            SetContentResult(_response);
            //return _response;
        }
Ejemplo n.º 13
0
        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;
        }