Пример #1
0
        public void ToggleBanFriend(int userId, int FriendId, bool IsBanned)
        {
            Models.ComboResponse _response = new Models.ComboResponse();
            _response.bool_result = true;
            _response.ErrorCode = 0;
            _response.ErrorMsg = "";

            ComboUserFriend friend = new ComboUserFriend();
            if (friend.LoadByPrimaryKey(userId, FriendId))
            {
                friend.IsBanned = IsBanned;
                friend.Save();
            }

            _response.Entity = null;
            SetContentResult(_response);
        }
Пример #2
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);
        }