예제 #1
0
        public async Task <IHttpActionResult> PostFriendRequest(int friendId)
        {
            User user = CurrentUser;

            if (user == null)
            {
                return(NotFound());
            }

            if (!db.Users.Any(u => u.UserId == friendId && u.IsArchive == false && u.IsActive == true))
            {
                return(NotFound());
            }

            if (AreFriends(user.UserId, friendId))
            {
                return(BadRequest("Users are already friend or a friend request already sent."));
            }

            int recoredscount = FriendsService.CreateFriendRequest(user.UserId, friendId);

            if (recoredscount == 1)
            {
                // send notification to the user (who is being requested for friendship)
                var message = "קיבלת בקשת חברות";// "You have received a friendship request";
                NotesMessagesRepo msgRepo = new NotesMessagesRepo();
                msgRepo.SendToUsers(new List <int>()
                {
                    friendId
                }, message, (MessageTypeEnum.PushNotifyOnly | MessageTypeEnum.Root));
                GamesNotificationsService gns = new GamesNotificationsService();
                await gns.SendPushToDevices(false);

                return(Ok());
            }
            else
            {
                return(InternalServerError());
            }
        }