Ejemplo n.º 1
0
        public async Task <bool> AcceptInviteAsync(FriendRequest friendRequest)
        {
            try
            {
                if (friendRequest == null)
                {
                    throw new ArgumentNullException(nameof(friendRequest));
                }

                friendRequest.Status = FriendRequestStatusEnum.Accepted;

                await _friendRequestRepository.SaveAsync(friendRequest);

                var userLogued = await this._identityService.GetUserLoguedAsync();

                var friend = new Friend(userLogued.Id, friendRequest.IdUserSendInvitation);

                await _friendsRepository.SaveAsync(friend);

                return(true);
            }
            catch (Exception e)
            {
                await _loggerService.LogErrorAsync(e);

                throw;
            }
        }
        public async Task DeleteFriend(UserProfile friendToDelete)
        {
            try
            {
                if (friendToDelete == null)
                {
                    throw  new ArgumentNullException(nameof(friendToDelete));
                }

                var userLogued = await this._identityService.GetUserLoguedAsync();

                await _friendsRepository.DeleteFriendAsync(userLogued.Id, friendToDelete.Id);

                var request = await _friendRequestRepository.GetByUsersIdAsync(userLogued.Id, friendToDelete.Id);

                request.Status            = FriendRequestStatusEnum.DeletedFriend;
                request.DateDeletedFriend = DateTime.Now;
                await _friendRequestRepository.SaveAsync(request);
            }
            catch (Exception e)
            {
                await _loggerService.LogErrorAsync(e);

                throw;
            }
        }