mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Retrieve computer and console information from database for news controller.
This commit is contained in:
@@ -44,6 +44,8 @@ namespace cicm_web.Models
|
|||||||
public DateTime Date;
|
public DateTime Date;
|
||||||
/// <summary>URL of image</summary>
|
/// <summary>URL of image</summary>
|
||||||
public string Image;
|
public string Image;
|
||||||
|
/// <summary>Subtext</summary>
|
||||||
|
public string SubText;
|
||||||
/// <summary>URL of target view, if applicable</summary>
|
/// <summary>URL of target view, if applicable</summary>
|
||||||
public string TargetView;
|
public string TargetView;
|
||||||
/// <summary>Text</summary>
|
/// <summary>Text</summary>
|
||||||
@@ -69,9 +71,14 @@ namespace cicm_web.Models
|
|||||||
|
|
||||||
static News TransformItem(Cicm.Database.Schemas.News dbItem)
|
static News TransformItem(Cicm.Database.Schemas.News dbItem)
|
||||||
{
|
{
|
||||||
string imageUrl;
|
string imageUrl;
|
||||||
string text;
|
string text;
|
||||||
string targetView;
|
string targetView;
|
||||||
|
string subtext;
|
||||||
|
Computer computer;
|
||||||
|
OwnComputer owncomputer;
|
||||||
|
Console console;
|
||||||
|
OwnConsole ownconsole;
|
||||||
|
|
||||||
switch(dbItem.Type)
|
switch(dbItem.Type)
|
||||||
{
|
{
|
||||||
@@ -79,46 +86,63 @@ namespace cicm_web.Models
|
|||||||
text = "New computer added to the database.";
|
text = "New computer added to the database.";
|
||||||
imageUrl = "assets/photos/computers/";
|
imageUrl = "assets/photos/computers/";
|
||||||
targetView = "computer";
|
targetView = "computer";
|
||||||
|
computer = Computer.GetItem(dbItem.AffectedId);
|
||||||
|
subtext = $"{computer.Company.Name} - {computer.Model}";
|
||||||
break;
|
break;
|
||||||
case NewsType.NewConsoleInDb:
|
case NewsType.NewConsoleInDb:
|
||||||
text = "New videoconsole added to the database.";
|
text = "New videoconsole added to the database.";
|
||||||
imageUrl = "assets/photos/consoles/";
|
imageUrl = "assets/photos/consoles/";
|
||||||
targetView = "console";
|
targetView = "console";
|
||||||
|
console = Console.GetItem(dbItem.AffectedId);
|
||||||
|
subtext = $"{console.Company.Name} - {console.Name}";
|
||||||
break;
|
break;
|
||||||
case NewsType.NewComputerInCollection:
|
case NewsType.NewComputerInCollection:
|
||||||
text = "New computer added to the museum's collection.";
|
text = "New computer added to the museum's collection.";
|
||||||
imageUrl = "assets/photos/computers/";
|
imageUrl = "assets/photos/computers/";
|
||||||
targetView = "collection_computer";
|
targetView = "collection_computer";
|
||||||
|
owncomputer = OwnComputer.GetItem(dbItem.AffectedId);
|
||||||
|
subtext = $"{owncomputer.Computer.Company.Name} - {owncomputer.Computer.Model}";
|
||||||
break;
|
break;
|
||||||
case NewsType.NewConsoleInCollection:
|
case NewsType.NewConsoleInCollection:
|
||||||
text = "New videoconsole added to the museum's collection.";
|
text = "New videoconsole added to the museum's collection.";
|
||||||
imageUrl = "assets/photos/consoles/";
|
imageUrl = "assets/photos/consoles/";
|
||||||
targetView = "collection_console";
|
targetView = "collection_console";
|
||||||
|
ownconsole = OwnConsole.GetItem(dbItem.AffectedId);
|
||||||
|
subtext = $"{ownconsole.Console.Company.Name} - {ownconsole.Console.Name}";
|
||||||
break;
|
break;
|
||||||
case NewsType.UpdatedComputerInDb:
|
case NewsType.UpdatedComputerInDb:
|
||||||
text = "Updated computer from the database.";
|
text = "Updated computer from the database.";
|
||||||
imageUrl = "assets/photos/computers/";
|
imageUrl = "assets/photos/computers/";
|
||||||
targetView = "computer";
|
targetView = "computer";
|
||||||
|
computer = Computer.GetItem(dbItem.AffectedId);
|
||||||
|
subtext = $"{computer.Company.Name} - {computer.Model}";
|
||||||
break;
|
break;
|
||||||
case NewsType.UpdatedConsoleInDb:
|
case NewsType.UpdatedConsoleInDb:
|
||||||
text = "Updated videoconsole from the database.";
|
text = "Updated videoconsole from the database.";
|
||||||
imageUrl = "assets/photos/consoles/";
|
imageUrl = "assets/photos/consoles/";
|
||||||
targetView = "console";
|
targetView = "console";
|
||||||
|
console = Console.GetItem(dbItem.AffectedId);
|
||||||
|
subtext = $"{console.Company.Name} - {console.Name}";
|
||||||
break;
|
break;
|
||||||
case NewsType.UpdatedComputerInCollection:
|
case NewsType.UpdatedComputerInCollection:
|
||||||
text = "Updated computer from museum's collection.";
|
text = "Updated computer from museum's collection.";
|
||||||
imageUrl = "assets/photos/computers/";
|
imageUrl = "assets/photos/computers/";
|
||||||
targetView = "collection_computer";
|
targetView = "collection_computer";
|
||||||
|
owncomputer = OwnComputer.GetItem(dbItem.AffectedId);
|
||||||
|
subtext = $"{owncomputer.Computer.Company.Name} - {owncomputer.Computer.Model}";
|
||||||
break;
|
break;
|
||||||
case NewsType.UpdatedConsoleInCollection:
|
case NewsType.UpdatedConsoleInCollection:
|
||||||
text = "Updated videoconsole from museum's collection.";
|
text = "Updated videoconsole from museum's collection.";
|
||||||
imageUrl = "assets/photos/consoles/";
|
imageUrl = "assets/photos/consoles/";
|
||||||
targetView = "collection_console";
|
targetView = "collection_console";
|
||||||
|
ownconsole = OwnConsole.GetItem(dbItem.AffectedId);
|
||||||
|
subtext = $"{ownconsole.Console.Company.Name} - {ownconsole.Console.Name}";
|
||||||
break;
|
break;
|
||||||
case NewsType.NewMoneyDonation:
|
case NewsType.NewMoneyDonation:
|
||||||
text = "New money donation.";
|
text = "New money donation.";
|
||||||
imageUrl = null;
|
imageUrl = null;
|
||||||
targetView = null;
|
targetView = null;
|
||||||
|
subtext = null;
|
||||||
break;
|
break;
|
||||||
default: throw new ArgumentOutOfRangeException();
|
default: throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
@@ -129,7 +153,8 @@ namespace cicm_web.Models
|
|||||||
Date = DateTime.ParseExact(dbItem.Date, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture),
|
Date = DateTime.ParseExact(dbItem.Date, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||||
Image = imageUrl == null ? null : imageUrl + $"{dbItem.AffectedId}",
|
Image = imageUrl == null ? null : imageUrl + $"{dbItem.AffectedId}",
|
||||||
Text = text,
|
Text = text,
|
||||||
TargetView = targetView
|
TargetView = targetView,
|
||||||
|
SubText = subtext
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,8 +74,7 @@
|
|||||||
<a asp-action="View"
|
<a asp-action="View"
|
||||||
asp-controller="@news.TargetView"
|
asp-controller="@news.TargetView"
|
||||||
asp-route-id="@news.AffectedId">
|
asp-route-id="@news.AffectedId">
|
||||||
<!-- TODO: Get this from models -->
|
@news.SubText
|
||||||
Company - Computer
|
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -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.38</Version>
|
<Version>3.0.99.41</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user