mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Implement news.
This commit is contained in:
@@ -28,10 +28,12 @@
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using cicm_web.Models;
|
||||
using Cicm.Database;
|
||||
using Cicm.Database.Models;
|
||||
using cicm_web.Models;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -39,8 +41,8 @@ namespace cicm_web.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
readonly IHostingEnvironment hostingEnvironment;
|
||||
readonly cicmContext _context;
|
||||
readonly IHostingEnvironment hostingEnvironment;
|
||||
|
||||
public HomeController(IHostingEnvironment env, cicmContext context)
|
||||
{
|
||||
@@ -51,22 +53,72 @@ namespace cicm_web.Controllers
|
||||
public IActionResult Index()
|
||||
{
|
||||
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
|
||||
return View(_context.News.OrderByDescending(t => t.Date).Take(10).ToList());
|
||||
|
||||
List<NewsModel> news = new List<NewsModel>();
|
||||
|
||||
foreach(News @new in _context.News.OrderByDescending(t => t.Date).Take(10))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult About()
|
||||
{
|
||||
return View();
|
||||
return View(news);
|
||||
}
|
||||
|
||||
public IActionResult Contact()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
public IActionResult About() => View();
|
||||
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
|
||||
}
|
||||
public IActionResult Contact() => View();
|
||||
|
||||
public IActionResult Error() =>
|
||||
View(new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
|
||||
}
|
||||
}
|
||||
24
cicm_web/Models/NewsModel.cs
Normal file
24
cicm_web/Models/NewsModel.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace cicm_web.Models
|
||||
{
|
||||
public class NewsModel
|
||||
{
|
||||
public readonly int AffectedId;
|
||||
public readonly string Text;
|
||||
public readonly DateTime Timestamp;
|
||||
public readonly string Controller;
|
||||
public readonly string Action;
|
||||
public readonly string ItemName;
|
||||
|
||||
public NewsModel(int affectedId, string text, DateTime timestamp, string controller, string action, string itemName)
|
||||
{
|
||||
AffectedId = affectedId;
|
||||
Text = text;
|
||||
Timestamp = timestamp;
|
||||
Controller = controller;
|
||||
Action = action;
|
||||
ItemName = itemName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,54 +33,33 @@
|
||||
}
|
||||
@using System.IO
|
||||
@using News = Cicm.Database.Models.News
|
||||
@model List<Cicm.Database.Models.News>
|
||||
@model List<NewsModel>
|
||||
|
||||
<h2>News</h2>
|
||||
|
||||
@foreach(News news in Model)
|
||||
@foreach(NewsModel news in Model)
|
||||
{
|
||||
<table border="0"
|
||||
width="100%">
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<b>@news.Date</b>
|
||||
<b>@news.Timestamp</b>
|
||||
</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"
|
||||
width="128">
|
||||
<a asp-action="View"
|
||||
asp-controller="@news.TargetView"
|
||||
asp-route-id="@news.AffectedId">
|
||||
<img height="128"
|
||||
width="128"
|
||||
src="@(news.Image + ".jpg")">
|
||||
</a>
|
||||
<td colspan="2">
|
||||
@news.Text
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>@* TODO: Image *@</td>
|
||||
<td>
|
||||
@news.Text
|
||||
</td>
|
||||
}
|
||||
else
|
||||
{
|
||||
<td colspan="2">
|
||||
@news.Text
|
||||
</td>
|
||||
}
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<a asp-action="View"
|
||||
asp-controller="@news.TargetView"
|
||||
asp-route-id="@news.AffectedId">
|
||||
@news.SubText
|
||||
<a asp-action="@news.Action"
|
||||
asp-route-id="@news.AffectedId"
|
||||
asp-controller="@news.Controller">
|
||||
@news.ItemName
|
||||
</a>
|
||||
</td>
|
||||
*@
|
||||
</tr>
|
||||
</table>
|
||||
<br />
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<Version>3.0.99.484</Version>
|
||||
<Version>3.0.99.486</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
|
||||
Reference in New Issue
Block a user