public async Task <IActionResult> Index()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var githubToken = (await _userManager.GetClaimsAsync(user)).FirstOrDefault(x => x.Type == "GithubAccessToken")?.Value;

            var model = new IndexViewModel
            {
                Username              = user.UserName,
                Email                 = user.Email,
                PhoneNumber           = user.PhoneNumber,
                IsEmailConfirmed      = user.EmailConfirmed,
                StatusMessage         = StatusMessage,
                HasPassword           = user.PasswordHash != null,
                AvailableRepositories = (await _githubService.GetAllRepositories(githubToken))?.Select(x => x.FullName).ToList() ?? new List <string>(),
                GithubAccount         = (await _githubService.GetUser(githubToken)).Username,
                GithubRepositories    = _githubService.GetUserRepositories(user.Id)?.Select(x => x.FullName).ToList(),
                Logins                = await _userManager.GetLoginsAsync(user)
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public override async Task OnConnectedAsync()
        {
            var repositories = _githubService.GetUserRepositories(_userManager.GetUserId(Context.User)).Select(x => x.FullName);

            foreach (var repo in repositories)
            {
                await Groups.AddAsync(Context.ConnectionId, repo);

                await Clients.Caller.SendAsync("groupAdded", repo);
            }

            await base.OnConnectedAsync();
        }
Exemplo n.º 3
0
        public async Task <object> GetBranches()
        {
            var user = await _userManager.GetUserAsync(User);

            var claims = await _userManager.GetClaimsAsync(user);

            var token    = claims.FirstOrDefault(x => x.Type == "GithubAccessToken")?.Value;
            var allRepos = await _githubService.GetAllRepositories(token);

            var selectedRepos = _githubService.GetUserRepositories(_userManager.GetUserId(User));

            var tasks = allRepos
                        .Where(x => selectedRepos?.Any(y => y.FullName == x.FullName) ?? false)
                        .AsParallel()
                        .Select(async x => await _githubService.CreateGithubBranches(token, x));
            var result = (await Task.WhenAll(tasks)).SelectMany(x => x).ToList();

            return(result);
        }