From ab24e794c3165f2c74c8e15c3cada045fad57482 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 6 Aug 2018 00:26:30 +0100 Subject: [PATCH] Move home controller to EF context. --- cicm_web/Controllers/HomeController.cs | 8 ++++++-- cicm_web/Views/Home/Index.cshtml | 6 +++++- cicm_web/cicm_web.csproj | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cicm_web/Controllers/HomeController.cs b/cicm_web/Controllers/HomeController.cs index 2f904a7d..bf788752 100644 --- a/cicm_web/Controllers/HomeController.cs +++ b/cicm_web/Controllers/HomeController.cs @@ -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() diff --git a/cicm_web/Views/Home/Index.cshtml b/cicm_web/Views/Home/Index.cshtml index 0b513eab..20e7a001 100644 --- a/cicm_web/Views/Home/Index.cshtml +++ b/cicm_web/Views/Home/Index.cshtml @@ -32,7 +32,8 @@ ViewData["Title"] = "Home Page"; } @using System.IO -@model IEnumerable +@using News = Cicm.Database.Models.News +@model List

News

@@ -46,6 +47,8 @@ + News items not yet implemented! + @* // TODO @if(news.Image != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, news.Image + ".jpg"))) { + *@
diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 1f34b1b6..84a739bb 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.0 - 3.0.99.271 + 3.0.99.279 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website