public async Task AuthorizeTwitch(int userId, string authorizationCode) { string token = await _twitchClient.GetAuthorizationToken(authorizationCode); if (token != null) { var userIntegration = _unitOfWork.UserIntegrations.GetById(userId, 1); if (userIntegration != null) { _unitOfWork.UserIntegrations.Delete(userIntegration); } var channel = await _twitchClient.GetChannel(token); _unitOfWork.UserIntegrations.Add(new UserIntegration { UserID = userId, IntegrationTypeID = (int)IntegrationType.IntegrationTypes.Twitch, Token = token, UserName = channel.name, ChannelId = channel._id.ToString() }); _unitOfWork.Commit(); } }