Пример #1
0
        public async Task <IActionResult> AddUser([FromBody] AddUserToNetworkInput addUserInput)
        {
            var user = new UserEntity {
                Token1 = addUserInput.UserId
            };
            var network = new NetworkEntity {
                NetworkId = addUserInput.NetworkId
            };

            var connected = await _networkService.IsUserConnectedToThisNetwork(user, network);

            if (!connected)
            {
                await _networkService.AddUserToNetwork(network, user, addUserInput.NetworkPassword);
            }

            return(Ok());
        }
Пример #2
0
        public async Task <bool> AddUserToNetwork(string networkId, string networkPass)
        {
            var obj = new AddUserToNetworkInput
            {
                NetworkId       = Guid.Parse(networkId),
                NetworkPassword = networkPass,
                UserId          = GetCurrentUser().Token1
            };

            var response = await _client.PostAsync(
                Configuration.AddUserToNetworkRelativeEndpoint,
                new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json"),
                CancellationToken.None);

            if (!response.IsSuccessStatusCode)
            {
                throw new OperationFailedException("Failed to add user to network, API call unsuccessful");
            }

            _currentUser.NetworkId = obj.NetworkId;
            return(true);
        }