Move home controller to EF context.

This commit is contained in:
2018-08-06 00:26:30 +01:00
parent bfbb203888
commit ab24e794c3
3 changed files with 12 additions and 4 deletions

View File

@@ -29,7 +29,9 @@
*******************************************************************************/
using System.Diagnostics;
using System.Linq;
using cicm_web.Models;
using Cicm.Database.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
@@ -38,16 +40,18 @@ namespace cicm_web.Controllers
public class HomeController : Controller
{
readonly IHostingEnvironment hostingEnvironment;
readonly cicmContext _context;
public HomeController(IHostingEnvironment env)
public HomeController(IHostingEnvironment env, cicmContext context)
{
hostingEnvironment = env;
_context = context;
}
public IActionResult Index()
{
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
return View(News.GetLastItems());
return View(_context.News.OrderByDescending(t => t.Date).Take(10).ToList());
}
public IActionResult About()

View File

@@ -32,7 +32,8 @@
ViewData["Title"] = "Home Page";
}
@using System.IO
@model IEnumerable<News>
@using News = Cicm.Database.Models.News
@model List<Cicm.Database.Models.News>
<h2>News</h2>
@@ -46,6 +47,8 @@
</td>
</tr>
<tr>
News items not yet implemented!
@* // TODO
@if(news.Image != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, news.Image + ".jpg")))
{
<td height="128"
@@ -77,6 +80,7 @@
@news.SubText
</a>
</td>
*@
</tr>
</table>
<br />

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<Version>3.0.99.271</Version>
<Version>3.0.99.279</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>