Beispiel #1
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);
        }
Beispiel #2
0
        public void ToggleBlockUser(int userId, int BlockedUserID)
        {
            Models.ComboResponse _response = new Models.ComboResponse();
            _response.bool_result = true;
            _response.ErrorCode = 0;
            _response.ErrorMsg = "";
            bool block = false;

            BlockedUser blocked = new BlockedUser();
            if (!blocked.LoadByPrimaryKey(userId, BlockedUserID))
            {
                blocked.AddNew();
                blocked.BlockedUserID = BlockedUserID;
                blocked.ComboUserID = userId;
                blocked.Save();
                block = true;
            }
            else
            {
                blocked.MarkAsDeleted();
                blocked.Save();
            }

            if (block)
            {
                ProfileFollower _1stfollow = new ProfileFollower();
                ProfileFollower _2ndfollow = new ProfileFollower();
                if (_1stfollow.LoadByPrimaryKey(userId, BlockedUserID))
                {
                    _1stfollow.MarkAsDeleted();
                    _1stfollow.Save();
                }
                if (_2ndfollow.LoadByPrimaryKey(BlockedUserID, userId))
                {
                    _2ndfollow.MarkAsDeleted();
                    _2ndfollow.Save();
                }
            }

            _response.Entity = null;
            SetContentResult(_response);
        }