Files
marechai/cicm_web/Controllers/HomeController.cs

124 lines
5.2 KiB
C#
Raw Normal View History

2018-04-11 05:55:27 +01:00
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : HomeController.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Home controller
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
2019-05-19 16:53:18 +01:00
using System.Collections.Generic;
2018-04-11 05:55:27 +01:00
using System.Diagnostics;
2018-08-06 00:26:30 +01:00
using System.Linq;
2019-05-19 16:53:18 +01:00
using Cicm.Database;
2018-08-06 00:26:30 +01:00
using Cicm.Database.Models;
2019-05-19 16:53:18 +01:00
using cicm_web.Models;
2018-04-13 02:42:27 +01:00
using Microsoft.AspNetCore.Hosting;
2018-04-11 05:55:27 +01:00
using Microsoft.AspNetCore.Mvc;
namespace cicm_web.Controllers
{
public class HomeController : Controller
{
2019-05-19 16:53:18 +01:00
readonly cicmContext _context;
2018-04-13 02:42:27 +01:00
readonly IHostingEnvironment hostingEnvironment;
2018-08-06 00:26:30 +01:00
public HomeController(IHostingEnvironment env, cicmContext context)
2018-04-13 02:42:27 +01:00
{
hostingEnvironment = env;
2019-05-19 16:53:18 +01:00
_context = context;
2018-04-13 02:42:27 +01:00
}
2018-04-11 05:55:27 +01:00
public IActionResult Index()
{
2018-04-13 02:42:27 +01:00
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
2018-04-11 05:55:27 +01:00
2019-05-19 16:53:18 +01:00
List<NewsModel> news = new List<NewsModel>();
2018-04-11 05:55:27 +01:00
2019-05-19 16:53:18 +01:00
foreach(News @new in _context.News.OrderByDescending(t => t.Date).Take(10))
{
Machine machine = _context.Machines.Find(@new.AddedId);
2018-04-11 05:55:27 +01:00
2019-05-19 16:53:18 +01:00
if(machine is null) continue;
switch(@new.Type)
{
case NewsType.NewComputerInDb:
news.Add(new NewsModel(@new.AddedId, "New computer in database", @new.Date, "Machine", "View",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.NewConsoleInDb:
news.Add(new NewsModel(@new.AddedId, "New console in database", @new.Date, "Machine", "View",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.NewComputerInCollection:
news.Add(new NewsModel(@new.AddedId, "New computer in collection", @new.Date, "Machine", "View",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.NewConsoleInCollection:
news.Add(new NewsModel(@new.AddedId, "New console in collection", @new.Date, "Machine", "View",
$"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.UpdatedComputerInDb:
news.Add(new NewsModel(@new.AddedId, "Updated computer in database", @new.Date, "Machine",
"View", $"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.UpdatedConsoleInDb:
news.Add(new NewsModel(@new.AddedId, "Updated console in database", @new.Date, "Machine",
"View", $"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.UpdatedComputerInCollection:
news.Add(new NewsModel(@new.AddedId, "Updated computer in collection", @new.Date, "Machine",
"View", $"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.UpdatedConsoleInCollection:
news.Add(new NewsModel(@new.AddedId, "Updated console in collection", @new.Date, "Machine",
"View", $"{machine.Company.Name} {machine.Name}"));
break;
case NewsType.NewMoneyDonation:
// TODO
break;
default: continue;
}
}
return View(news);
2018-04-11 05:55:27 +01:00
}
2019-05-19 16:53:18 +01:00
public IActionResult About() => View();
public IActionResult Contact() => View();
public IActionResult Error() =>
View(new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
2018-04-11 05:55:27 +01:00
}
}