コード例 #1
0
        public async Task <ActionResult> Feed(int feedId, int?follow)
        {
            var feedService    = new FeedService(db);
            var articleService = new ArticleService(db);
            var feed           = await feedService.GetByIdWithCategory(feedId);

            var isFollowed = false;

            if (User.Identity.IsAuthenticated)
            {
                var userId = User.Identity.GetUserId();
                var user   = await db.AspNetUsers.Include(u => u.Feeds).SingleOrDefaultAsync(u => u.Id == userId);

                if (follow != null)
                {
                    if (follow == 1)
                    {
                        feedService.Follow(user, feed);
                    }
                    else
                    {
                        feedService.Unfollow(user, feed);
                    }
                }
                isFollowed = user.Feeds.Contains(feed);
            }

            var dashboard = new FeedDashboard
            {
                Feed     = feed,
                Followed = isFollowed,
                Articles = await articleService.GetByFeed(feedId)
            };

            return(View(dashboard));
        }