コード例 #1
0
        public async Task <IActionResult> Index()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            DiscoverViewModel discoverViewModel = new DiscoverViewModel();

            discoverViewModel.Posts = await _dbService.GetAllPosts();

            discoverViewModel.LikedPostIds = await _dbService.GetLikedPostIds(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);

            discoverViewModel.ReturnUrl     = _currentUrlService.GetCurrentUrl(HttpContext);
            discoverViewModel.IndexUserName = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Name).Value;
            return(View(discoverViewModel));
        }
コード例 #2
0
        public async Task <IActionResult> User(string userName)
        {
            var user = await _dbService.FindUserByNameAsync(userName);

            UserViewModel userViewModel = new UserViewModel(user);

            userViewModel.IndexUser    = userName == _userName;
            userViewModel.Following    = user.Followers.Select(user => user.UserName).Contains(_userName);
            userViewModel.ReturnUrl    = _currentUrlService.GetCurrentUrl(HttpContext);
            userViewModel.LikedPostIds = await _dbService.GetLikedPostIds(_userId);

            _log.LogInformation($"ReturnUrl: {userViewModel.ReturnUrl}");
            return(View(userViewModel));
        }