mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Addes News MVC.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -440,3 +440,6 @@ $RECYCLE.BIN/
|
|||||||
# Windows shortcuts
|
# Windows shortcuts
|
||||||
*.lnk
|
*.lnk
|
||||||
|
|
||||||
|
|
||||||
|
# Assets
|
||||||
|
cicm_web/wwwroot/assets/
|
||||||
|
|||||||
@@ -30,15 +30,24 @@
|
|||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using cicm_web.Models;
|
using cicm_web.Models;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace cicm_web.Controllers
|
namespace cicm_web.Controllers
|
||||||
{
|
{
|
||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
|
readonly IHostingEnvironment hostingEnvironment;
|
||||||
|
|
||||||
|
public HomeController(IHostingEnvironment env)
|
||||||
|
{
|
||||||
|
hostingEnvironment = env;
|
||||||
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
return View();
|
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
|
||||||
|
return View(News.GetLastItems());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult About()
|
public IActionResult About()
|
||||||
|
|||||||
106
cicm_web/Models/News.cs
Normal file
106
cicm_web/Models/News.cs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using Cicm.Database.Schemas;
|
||||||
|
|
||||||
|
namespace cicm_web.Models
|
||||||
|
{
|
||||||
|
public class News
|
||||||
|
{
|
||||||
|
/// <summary>Affected ID</summary>
|
||||||
|
public int AffectedId;
|
||||||
|
/// <summary>Date</summary>
|
||||||
|
public DateTime Date;
|
||||||
|
/// <summary>URL of image</summary>
|
||||||
|
public string Image;
|
||||||
|
/// <summary>URL of target view, if applicable</summary>
|
||||||
|
public string TargetView;
|
||||||
|
/// <summary>Text</summary>
|
||||||
|
public string Text;
|
||||||
|
|
||||||
|
public static News[] GetAllItems()
|
||||||
|
{
|
||||||
|
List<Cicm.Database.Schemas.News> dbItems = null;
|
||||||
|
bool? result = Program.Database?.Operations.GetNews(out dbItems);
|
||||||
|
if(result == null || result.Value == false || dbItems == null) return null;
|
||||||
|
|
||||||
|
return dbItems.OrderByDescending(i => i.Id).Select(TransformItem) as News[];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static News[] GetLastItems(int count = 10)
|
||||||
|
{
|
||||||
|
List<Cicm.Database.Schemas.News> dbItems = null;
|
||||||
|
bool? result = Program.Database?.Operations.GetNews(out dbItems);
|
||||||
|
if(result == null || result.Value == false || dbItems == null) return null;
|
||||||
|
|
||||||
|
return dbItems.OrderByDescending(i => i.Id).Take(count).Select(TransformItem).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
static News TransformItem(Cicm.Database.Schemas.News dbItem)
|
||||||
|
{
|
||||||
|
string imageUrl;
|
||||||
|
string text;
|
||||||
|
string targetView;
|
||||||
|
|
||||||
|
switch(dbItem.Type)
|
||||||
|
{
|
||||||
|
case NewsType.NewComputerInDb:
|
||||||
|
text = "New computer added to the database.";
|
||||||
|
imageUrl = "assets/photos/computers/";
|
||||||
|
targetView = "computer";
|
||||||
|
break;
|
||||||
|
case NewsType.NewConsoleInDb:
|
||||||
|
text = "New videoconsole added to the database.";
|
||||||
|
imageUrl = "assets/photos/consoles/";
|
||||||
|
targetView = "console";
|
||||||
|
break;
|
||||||
|
case NewsType.NewComputerInCollection:
|
||||||
|
text = "New computer added to the museum's collection.";
|
||||||
|
imageUrl = "assets/photos/computers/";
|
||||||
|
targetView = "collection_computer";
|
||||||
|
break;
|
||||||
|
case NewsType.NewConsoleInCollection:
|
||||||
|
text = "New videoconsole added to the museum's collection.";
|
||||||
|
imageUrl = "assets/photos/consoles/";
|
||||||
|
targetView = "collection_console";
|
||||||
|
break;
|
||||||
|
case NewsType.UpdatedComputerInDb:
|
||||||
|
text = "Updated computer from the database.";
|
||||||
|
imageUrl = "assets/photos/computers/";
|
||||||
|
targetView = "computer";
|
||||||
|
break;
|
||||||
|
case NewsType.UpdatedConsoleInDb:
|
||||||
|
text = "Updated videoconsole from the database.";
|
||||||
|
imageUrl = "assets/photos/consoles/";
|
||||||
|
targetView = "console";
|
||||||
|
break;
|
||||||
|
case NewsType.UpdatedComputerInCollection:
|
||||||
|
text = "Updated computer from museum's collection.";
|
||||||
|
imageUrl = "assets/photos/computers/";
|
||||||
|
targetView = "collection_computer";
|
||||||
|
break;
|
||||||
|
case NewsType.UpdatedConsoleInCollection:
|
||||||
|
text = "Updated videoconsole from museum's collection.";
|
||||||
|
imageUrl = "assets/photos/consoles/";
|
||||||
|
targetView = "collection_console";
|
||||||
|
break;
|
||||||
|
case NewsType.NewMoneyDonation:
|
||||||
|
text = "New money donation.";
|
||||||
|
imageUrl = null;
|
||||||
|
targetView = null;
|
||||||
|
break;
|
||||||
|
default: throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new News
|
||||||
|
{
|
||||||
|
AffectedId = dbItem.AffectedId,
|
||||||
|
Date = DateTime.ParseExact(dbItem.Date, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||||
|
Image = imageUrl == null ? null : imageUrl + $"{dbItem.AffectedId}",
|
||||||
|
Text = text,
|
||||||
|
TargetView = targetView
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,11 +31,54 @@
|
|||||||
|
|
||||||
ViewData["Title"] = "Home Page";
|
ViewData["Title"] = "Home Page";
|
||||||
}
|
}
|
||||||
|
@using System.IO
|
||||||
|
@model IEnumerable<News>
|
||||||
|
|
||||||
<h2>News</h2>
|
<h2>News</h2>
|
||||||
|
|
||||||
<ul>
|
@foreach(News news in Model)
|
||||||
<li>News should be fetch from the database</li>
|
{
|
||||||
<li>But this is currently not implemented!</li>
|
<table border="0"
|
||||||
<li>TODO: TODO</li>
|
width="100%">
|
||||||
</ul>
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<b>@news.Date</b>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
@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>
|
||||||
|
<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">
|
||||||
|
<!-- TODO: Get this from models -->
|
||||||
|
Company - Computer
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br />
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
<Version>3.0.99.23</Version>
|
<Version>3.0.99.36</Version>
|
||||||
<Company>Canary Islands Computer Museum</Company>
|
<Company>Canary Islands Computer Museum</Company>
|
||||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||||
<Product>Canary Islands Computer Museum Website</Product>
|
<Product>Canary Islands Computer Museum Website</Product>
|
||||||
@@ -24,7 +24,6 @@
|
|||||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
|
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Database" />
|
|
||||||
<Folder Include="wwwroot\lib" />
|
<Folder Include="wwwroot\lib" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user