public async Task <IActionResult> Index()
        {
            PostsFeedLoaderViewModel postsFeedLoader = null;

            if (User.Identity.IsAuthenticated)
            {
                ApplicationUser currentUser = await userManager.FindByNameAsync(User.Identity.Name);

                IEnumerable <PostViewModel> posts = repository.GetPostsByFollowerId(currentUser?.Id, postsFeedCount).ToViewModels();

                if (posts.Any())
                {
                    postsFeedLoader       = new PostsFeedLoaderViewModel();
                    postsFeedLoader.Posts = posts;

                    if (posts.Count() == postsFeedCount)
                    {
                        postsFeedLoader.HasLoader    = true;
                        postsFeedLoader.LoaderLink   = "/PostsFeed/";
                        postsFeedLoader.LoaderCount  = postsFeedCount;
                        postsFeedLoader.LoaderCursor = posts.Last().Id;
                    }
                }
            }

            return(View("Home", postsFeedLoader));
        }
        public async Task <IActionResult> Index(string userName)
        {
            UserViewModel user = repository.GetUserByUserName(userName)?.ToViewModel;

            if (user != null)
            {
                ApplicationUser currentUser = null;

                if (User.Identity.IsAuthenticated)
                {
                    currentUser = await userManager.FindByNameAsync(User.Identity.Name);

                    if (currentUser.Id == user.Id)
                    {
                        user.IsCurrentUser = true;
                    }
                    else
                    {
                        user.IsFollowedByCurrentUser = repository.GetUserFollow(currentUser.Id, user.Id) != null;
                    }
                }

                var posts = repository.GetPostsAndFavoritesByUserName(userName, postsFeedCount).ToViewModels();

                if (posts.Any())
                {
                    posts = AddFavoritedBy(posts, user.Name);

                    var postsFeedLoader = new PostsFeedLoaderViewModel
                    {
                        Posts = posts
                    };

                    if (posts.Count() == postsFeedCount)
                    {
                        postsFeedLoader.HasLoader    = true;
                        postsFeedLoader.LoaderLink   = user.UserName + "/PostsFeed/";
                        postsFeedLoader.LoaderCount  = postsFeedCount;
                        postsFeedLoader.LoaderCursor = posts.Last().Id;
                    }
                    user.PostsFeedLoader = postsFeedLoader;
                }
            }

            return(View("User", user));
        }
Exemple #3
0
        public IActionResult Index()
        {
            IEnumerable <PostViewModel> posts = repository.GetPosts(postsFeedCount).ToViewModels();
            var postsFeedLoader = new PostsFeedLoaderViewModel();

            postsFeedLoader.Posts = posts;

            if (posts.Count() == postsFeedCount)
            {
                postsFeedLoader.HasLoader    = true;
                postsFeedLoader.LoaderLink   = "/Explore/PostsFeed/";
                postsFeedLoader.LoaderCount  = postsFeedCount;
                postsFeedLoader.LoaderCursor = posts.Last().Id;
            }

            return(View("Explore", postsFeedLoader));
        }
Exemple #4
0
        public IActionResult Index(string tagName)
        {
            PostsFeedLoaderViewModel    postsFeedLoader = null;
            IEnumerable <PostViewModel> posts           = repository.GetPostsByTag(tagName, postsFeedCount).ToViewModels();

            if (posts.Any())
            {
                postsFeedLoader       = new PostsFeedLoaderViewModel();
                postsFeedLoader.Posts = posts;

                if (posts.Count() == postsFeedCount)
                {
                    postsFeedLoader.HasLoader    = true;
                    postsFeedLoader.LoaderLink   = "/Tag/" + tagName + "/PostsFeed/";
                    postsFeedLoader.LoaderCount  = postsFeedCount;
                    postsFeedLoader.LoaderCursor = posts.Last().Id;
                }
            }

            return(View("Tag", postsFeedLoader));
        }