示例#1
0
        public async Task <IActionResult> updateFriendshipStatus(UpdateFriendshipStatusRequestDto updateFriendshipStatusRequestDto)
        {
            try
            {
                var userId = int.Parse(HttpContext.User.Identity.Name);
                await _friendshipService.UpdateFriendshipStatus(userId, updateFriendshipStatusRequestDto);

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
示例#2
0
        public async Task UpdateFriendshipStatus(int userId, UpdateFriendshipStatusRequestDto updateFriendshipStatusRequestDto)
        {
            var userFriend = await _unitOfWork.Users.GetUserByIdAsync(userId);

            var user = await _unitOfWork.Users.GetUserByUsernameAsync(updateFriendshipStatusRequestDto.FriendUsername);

            var friendship = await _unitOfWork.Friendships.GetFriendshipByUsers(user, userFriend);

            if (friendship == null)
            {
                throw new ArgumentException("FriendshipNotFound");
            }

            friendship.Status = (FriendRequestStatus)updateFriendshipStatusRequestDto.Status;
            await _unitOfWork.CommitAsync();
        }