// Make sure these 'using' directives are at the top of your file
using boilerplate.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity; // This is required for .ToListAsync()
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace boilerplate.Controllers
{
    public class HomeController : Controller
    {
        // Add an instance of your database context
        private boilerplateEntities db = new boilerplateEntities();

        // GET: Default
        public ActionResult Index()
        {
            return View();
        }

        // This action now fetches news from the database
        public async Task<ActionResult> AllNews()
        {
            // Fetch all news, order by the most recent ones
            var newsList = await db.News.OrderByDescending(n => n.News_Date).ToListAsync();
            return View(newsList);
        }



    }
}
