Move news to Blazor.

This commit is contained in:
2020-05-21 17:23:46 +01:00
parent a6e5702141
commit 4e1a99ea8c
27 changed files with 14118 additions and 118 deletions

View File

@@ -28,10 +28,7 @@
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Marechai.Database;
using Marechai.Database.Models;
using Marechai.Models;
using Microsoft.AspNetCore.Hosting;
@@ -50,79 +47,6 @@ namespace Marechai.Controllers
_context = context;
}
public IActionResult Index()
{
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
List<NewsModel> news = new List<NewsModel>();
foreach(News @new in _context.News.OrderByDescending(t => t.Date).Take(10).ToList())
{
Machine machine = _context.Machines.Find(@new.AddedId);
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);
}
public IActionResult About() => View();
public IActionResult Contact() => View();