示例#1
0
        public async Task <ActionResult> AddFriendAsync(
            int id,
            [FromBody] AddFriendRequest request)
        {
            try
            {
                var friend = await _userManager.AddUserFriendAsync(new AddUserFriendModel
                {
                    FriendId = request.UserId,
                    UserId   = id,
                });

                return(new JsonResult(new FriendRequestResponse
                {
                    Accepted = friend.Accepted,
                    Id = friend.Id,
                    Receiver = new BasicUserResponse {
                        Id = friend.User2Id
                    },
                    Sender = new BasicUserResponse {
                        Id = friend.User1Id
                    },
                }));
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, $"Could not add user ({request.UserId}) as friend to user ({id}).");
                return(BadRequest());
            }
        }