示例#1
0
        public async Task <ResponseMessage> ConnectPerson([FromBody] string userId)
        {
            //get current user from jwt token
            var userName = HttpContext?.User.Claims.FirstOrDefault(c => c.Type == System.Security.Claims.ClaimTypes.NameIdentifier).Value;
            var user     = await _userManager.FindByNameAsync(userName);

            var isConnected = _appUserService.CheckIfIsConnectedPerson(user.Id, userId);

            if (isConnected)
            {
                return new ResponseMessage {
                           Message = "You have already been connected with this person", IsSuccess = false
                }
            }
            ;
            else
            {
                _appUserService.ConnectUser(new ConnectedUserViewModel {
                    AppUserId = user.Id, ConnectedAppUserId = userId
                });

                _appUserService.ConnectUser(new ConnectedUserViewModel {
                    AppUserId = userId, ConnectedAppUserId = user.Id
                });
            }

            return(new ResponseMessage {
                IsSuccess = true
            });
        }