// GET: Subreddit
 public ActionResult Index()
 {
     using (var subredditContext = new RedditCloneContext())
     {
         var subredditList = new SubredditListViewModel
         {
             Subreddits = subredditContext.Subreddits.Select(s => new SubredditViewModel
             {
                 SubredditId   = s.SubredditId,
                 SubredditName = s.SubredditName,
                 Posts         = s.Posts
             }).ToList()
         };
         return(View(subredditList));
     }
 }
Esempio n. 2
0
 // GET: Subreddit
 public ActionResult Index()
 {
     using (var subredditContext = new RedditCloneContext())
     {
         // Build a list of the subreddits currently in the database.
         var subredditList = new SubredditListViewModel
         {
             Subreddits = subredditContext.Subreddits.Select(s => new SubredditViewModel
             {
                 SubredditId   = s.SubredditId,
                 SubredditName = s.SubredditName,
                 Posts         = s.Posts
             }).ToList()
         };
         return(View(subredditList));
     }
 }