Beispiel #1
0
 public async Task AddReceivedRequest(FriendRequestDto sender)
 {
     CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         ReceivedRequests.Add(sender);
     });
 }
Beispiel #2
0
        public async Task <bool> DeleteFriendship(FriendRequestDto friendRequestDto)
        {
            string userId   = friendRequestDto.userId;
            string friendId = friendRequestDto.invetationCode;

            // Validations
            if (string.IsNullOrWhiteSpace(friendId) || string.IsNullOrWhiteSpace(userId) || userId == friendId)
            {
                throw new AppException("Not Valid");
            }

            var friend = await db.Users.Include("userFriends").FirstOrDefaultAsync(x => x.Id == friendId);

            if (friend == null)
            {
                throw new AppException("User not found");
            }

            //if friend did not add you
            //if ( !friend.userFriends.Any(x => x.friendUserId == friendRequestDto.userId))
            //     throw new AppException("None Existent");


            var Successful = await DeleteFriendsToEachothers(userId, friendId);

            return(Successful);
        }
Beispiel #3
0
        public void SendFriendRequestPush(int senderId, FriendRequestDto friendRequest)
        {
            var receiver = _userService.GetUser(friendRequest.ReceiverId);
            var sender   = _userService.GetUser(senderId);
            var message  = $"{sender.FullName} sent you a friend request.";

            PushAndroidNotification(receiver.DeviceId, message, sender.UserName, friendRequest.ReceiverId, NotificationType.FriendRequest, friendRequest);
        }
Beispiel #4
0
        public async Task <IActionResult> AcceptFriendRequest(FriendRequestDto friendRequestDto)
        {
            if (friendRequestDto.ReceiverId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            return(Ok(await _friendsService.AcceptFriendRequest(friendRequestDto)));
        }
Beispiel #5
0
        public static FriendRequestDto ConvertRequestToDto(FriendRequests request)
        {
            var requestDto = new FriendRequestDto();

            requestDto.Id       = request.Id;
            requestDto.FromUser = ConvertSingleUserToDto(request.FromUser);
            requestDto.ToUserId = request.UserId;
            requestDto.Seen     = request.Seen;

            return(requestDto);
        }
        public async Task <KeyValuePair <bool, string> > SendFriendRequest(FriendRequestDto friendRequestDto)
        {
            var response = await _unitOfWork.Friends.SendFriendRequest(friendRequestDto);

            if (response.Key)
            {
                await _unitOfWork.Complete();
            }

            return(response);
        }
Beispiel #7
0
        public async Task <ActionResult> SendRequest([FromBody] FriendRequestDto dto)
        {
            if (!_authService.CheckIfUserIsAuthorized(dto.FromId))
            {
                return(Unauthorized("Cannot access data of someone else"));
            }

            var requestEntity = _mapper.Map <FriendRequest>(dto);
            await _friendService.SendFriendRequest(requestEntity);

            return(Ok());
        }
        public FriendRequestDto UserRequest(int userId, int targetId)
        {
            var requestForUser = _friendRequestsRepository.GetFirstInclude(x => x.UserId == targetId && x.FromUserId == userId || (x.UserId == userId && x.FromUserId == targetId));

            if (requestForUser == null)
            {
                var friendRequestEmpty = new FriendRequestDto();
                return(friendRequestEmpty);
            }

            return(ModelToDTO.ConvertRequestToDto(requestForUser));
        }
        public async Task <IActionResult> AddFreindToMe([FromBody] FriendRequestDto friendRequestDto)
        {
            friendRequestDto.userId = GetTokenId();
            try
            {
                UserFriend friend = await userService.AddFreindToMe(friendRequestDto);

                return(Ok(ret(friend, "added")));
            }
            catch (AppException ex)
            {
                return(BadRequest(ree(ex.Message)));
            }
        }
        public async Task <IActionResult> DeleteFriendship([FromBody] FriendRequestDto friendRequestDto)
        {
            friendRequestDto.userId = GetTokenId();
            try
            {
                var isDeleted = await userService.DeleteFriendship(friendRequestDto);

                return(Ok(ret(isDeleted, isDeleted?"Deleted":"Error")));
            }
            catch (AppException ex)
            {
                return(BadRequest(ree(ex.Message)));
            }
        }
Beispiel #11
0
        public async Task <ActionResult> AcceptFriendRequest([FromBody] FriendRequestDto dto)
        {
            var userId = _authService.GetLoggedinUserId();

            if (dto.FromId != userId && dto.ToId != userId)
            {
                return(Unauthorized("Cannot accept friend request of someone else"));
            }

            var requestEntity = _mapper.Map <FriendRequest>(dto);
            await _friendService.AcceptFriendRequest(requestEntity);

            return(Ok());
        }
Beispiel #12
0
        public async Task <KeyValuePair <bool, string> > AcceptFriendRequest(FriendRequestDto friendRequestDto)
        {
            var friendRequest = await DataContext.Friendships
                                .Where(f => f.ReceiverId == friendRequestDto.ReceiverId && f.SenderId == friendRequestDto.SenderId)
                                .FirstOrDefaultAsync();

            if (friendRequest != null)
            {
                friendRequest.Accepted = true;
                Update(friendRequest);
                return(new KeyValuePair <bool, string>(true, "Friend request successfully accepted"));
            }

            return(new KeyValuePair <bool, string>(false, "Specified friend request doesn't exist"));
        }
Beispiel #13
0
        public IActionResult Post([FromBody] FriendRequestDto friendRequestDto)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //TODO: What error is thrown while user is not found
                    var friendRequest = friendDomain.CreateFriendRequest(friendRequestDto.FromPlayer,
                                                                         friendRequestDto.ToPlayer);

                    return(Created(this.Request.Path, friendRequest));
                }
                catch (Exception e)
                {
                    _logger.LogExceptions(e, this);
                    return(this.HandleErrors(e));
                }
            }

            return(BadRequest(new ErrorDto(ModelState)));
        }
Beispiel #14
0
        public async Task <UserFriend> AddFreindToMe(FriendRequestDto friendRequestDto)
        {
            // Validations
            if (string.IsNullOrWhiteSpace(friendRequestDto.invetationCode) || string.IsNullOrWhiteSpace(friendRequestDto.userId))
            {
                throw new AppException("Not Valid");
            }

            var invetationCode = friendRequestDto.invetationCode;
            var results        = IsInvitationValid(invetationCode);

            if (!results.isSuccessful)
            {
                throw new AppException(results.errors);
            }
            string friendId = results.userId;
            string userId   = friendRequestDto.userId;

            // Validations
            if (userId.ToLower() == friendId.ToLower())
            {
                throw new AppException("Not Valid");
            }
            var friend = await db.Users.Include("userFriends").FirstOrDefaultAsync(x => x.Id == friendId);

            if (friend == null)
            {
                throw new AppException("User not found");
            }

            //if friend already added you
            if (friend.userFriends.Any(x => x.friendUserId == userId))
            {
                throw new AppException("Friend already added you");
            }

            var objectFriends = await AddFriendsToEachothers(friend.Id, userId);

            return(objectFriends);
        }
Beispiel #15
0
        public async Task <KeyValuePair <bool, string> > SendFriendRequest(FriendRequestDto friendRequestDto)
        {
            var friendshipAlreadyExists = await DataContext.Friendships
                                          .FirstOrDefaultAsync(f => (f.SenderId == friendRequestDto.SenderId &&
                                                                     f.ReceiverId == friendRequestDto.ReceiverId) ||
                                                               (f.ReceiverId == friendRequestDto.SenderId &&
                                                                f.SenderId == friendRequestDto.ReceiverId)) != null;

            if (!friendshipAlreadyExists)
            {
                var friendship = new Friendship()
                {
                    SenderId   = friendRequestDto.SenderId,
                    ReceiverId = friendRequestDto.ReceiverId,
                    Accepted   = false
                };
                Add(friendship);

                return(new KeyValuePair <bool, string>(true, "Friend request sent successfully"));
            }

            return(new KeyValuePair <bool, string>(false, "Friend request cannot be sent"));
        }
Beispiel #16
0
 public static FriendRequestViewModel ToViewModel(this FriendRequestDto friendRequestDto) =>
 new FriendRequestViewModel(friendRequestDto.Id, friendRequestDto.UserFrom.UserName);
 public void SaveFriendRequestNotification(int senderId, FriendRequestDto friendRequest)
 {
     throw new NotImplementedException();
 }
Beispiel #18
0
 public async Task ReceiveRequest(FriendRequestDto sender)
 {
     await friendStore.AddReceivedRequest(sender);
 }