Ejemplo n.º 1
0
        public async void OnGetAsync()
        {
            DateTime now       = DateTime.Now;
            string   githubId  = "";
            string   name      = "";
            string   username  = "";
            string   avatarUrl = "";

            foreach (Claim claim in User.Claims)
            {
                if (claim.Type == ClaimTypes.NameIdentifier)
                {
                    githubId = claim.Value;
                }
                else if (claim.Type == ClaimTypes.Name)
                {
                    name = claim.Value;
                }
                else if (claim.Type == "urn:github:login")
                {
                    username = claim.Value;
                }
                else if (claim.Type == "urn:github:avatar")
                {
                    avatarUrl = claim.Value;
                }
            }

            ThisUser = await _context.GetUserByGithubId(githubId);

            int userId;

            if (ThisUser != null)
            {
                userId = ThisUser.Id;
            }
            else
            {
                ThisUser = new User {
                    Username   = username,
                    Name       = name,
                    GithubId   = githubId,
                    CreateDate = now,
                    AvatarUrl  = avatarUrl
                };

                var dbResponse = _context.AddUser(ThisUser);
                await _context.SaveChangesAsync();

                userId = dbResponse.Entity.Id;
            }

            Bookmarks = await _context.GetBookmarksByUserIdAsync(userId);

            FavoriteBookmarks = await _context.GetFavoriteBookmarksByUserIdAsync(userId);

            FollowingBookmarks = await _context.GetBookmarksByFollowersAsync(userId);
        }