Update DB to version 9 (company descriptions).

This commit is contained in:
2018-04-20 03:06:57 +01:00
parent 544cbd5e54
commit a96c093757
10 changed files with 898 additions and 336 deletions

View File

@@ -394,6 +394,10 @@ namespace Cicm.Database
entry.LastLogo = entry.Logos[0];
}
if(GetCompanyDescriptionsByCompany(out List<CompanyDescription> descriptions, entry.Id))
if(descriptions != null && descriptions.Count > 0)
entry.Description = descriptions[0].Text;
entries.Add(entry);
}

View File

@@ -0,0 +1,329 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : CompanyDescription.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains operations to manage company descriptions.
//
// --[ 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
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using Cicm.Database.Schemas;
using Console = System.Console;
namespace Cicm.Database
{
public partial class Operations
{
/// <summary>
/// Gets all company descriptions
/// </summary>
/// <param name="entries">All company descriptions</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetCompanyDescriptions(out List<CompanyDescription> entries)
{
#if DEBUG
Console.WriteLine("Getting all company descriptions...");
#endif
try
{
const string SQL = "SELECT * from company_descriptions";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = CompanyDescriptionsFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting company descriptions.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets the specified number of company descriptions since the specified start
/// </summary>
/// <param name="entries">List of company_descriptions</param>
/// <param name="start">Start of query</param>
/// <param name="count">How many entries to retrieve</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetCompanyDescriptions(out List<CompanyDescription> entries, ulong start, ulong count)
{
#if DEBUG
Console.WriteLine("Getting {0} company descriptions from {1}...", count, start);
#endif
try
{
string sql = $"SELECT * FROM company_descriptions LIMIT {start}, {count}";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = CompanyDescriptionsFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting company descriptions.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets company description by specified id
/// </summary>
/// <param name="id">Id</param>
/// <returns>CompanyDescription with specified id, <c>null</c> if not found or error</returns>
public CompanyDescription GetCompanyDescription(int id)
{
#if DEBUG
Console.WriteLine("Getting company description with id {0}...", id);
#endif
try
{
string sql = $"SELECT * from company_descriptions WHERE id = '{id}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
List<CompanyDescription> entries = CompanyDescriptionsFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
Console.WriteLine("Error getting company.");
Console.WriteLine(ex);
return null;
}
}
/// <summary>
/// Gets company description by specified id
/// </summary>
/// <param name="entries">List of company_descriptions</param>
/// <param name="company">Company id</param>
/// <returns>CompanyDescription with specified id, <c>null</c> if not found or error</returns>
public bool GetCompanyDescriptionsByCompany(out List<CompanyDescription> entries, int company)
{
#if DEBUG
Console.WriteLine("Getting company descriptions for company {0}...", company);
#endif
try
{
string sql = $"SELECT * FROM company_descriptions WHERE company_id = {company}";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = CompanyDescriptionsFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting company descriptions.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Counts the number of company descriptions in the database
/// </summary>
/// <returns>Entries in database</returns>
public long CountCompanyDescriptions()
{
#if DEBUG
Console.WriteLine("Counting company descriptions...");
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
dbcmd.CommandText = "SELECT COUNT(*) FROM company_descriptions";
object count = dbcmd.ExecuteScalar();
dbcmd.Dispose();
try { return Convert.ToInt64(count); }
catch { return 0; }
}
/// <summary>
/// Adds a new company description to the database
/// </summary>
/// <param name="entry">Entry to add</param>
/// <param name="id">ID of added entry</param>
/// <returns><c>true</c> if added correctly, <c>false</c> otherwise</returns>
public bool AddCompanyDescription(CompanyDescription entry, out long id)
{
#if DEBUG
Console.Write("Adding description for company id `{0}`...", entry.CompanyId);
#endif
IDbCommand dbcmd = GetCommandCompanyDescription(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
const string SQL =
"INSERT INTO company_descriptions (company_id, text) VALUES (@company_id, @text)";
dbcmd.CommandText = SQL;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
id = dbCore.LastInsertRowId;
#if DEBUG
Console.WriteLine(" id {0}", id);
#endif
return true;
}
/// <summary>
/// Updated a company description in the database
/// </summary>
/// <param name="entry">Updated entry</param>
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
public bool UpdateCompanyDescription(CompanyDescription entry)
{
#if DEBUG
Console.WriteLine("Updating company description id `{0}`...", entry.Id);
#endif
IDbCommand dbcmd = GetCommandCompanyDescription(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = "UPDATE company_descriptions SET company_id = @company_id, text = @text " +
$"WHERE id = {entry.Id}";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
/// <summary>
/// Removes a company description from the database
/// </summary>
/// <param name="id">ID of entry to remove</param>
/// <returns><c>true</c> if removed correctly, <c>false</c> otherwise</returns>
public bool RemoveCompanyDescription(long id)
{
#if DEBUG
Console.WriteLine("Removing company description with id `{0}`...", id);
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = $"DELETE FROM company_descriptions WHERE id = '{id}';";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
IDbCommand GetCommandCompanyDescription(CompanyDescription entry)
{
IDbCommand dbcmd = dbCon.CreateCommand();
IDbDataParameter param1 = dbcmd.CreateParameter();
IDbDataParameter param2 = dbcmd.CreateParameter();
param1.ParameterName = "@company_id";
param2.ParameterName = "@text";
param1.DbType = DbType.String;
param2.DbType = DbType.String;
param1.Value = entry.CompanyId;
param2.Value = entry.Text;
dbcmd.Parameters.Add(param1);
dbcmd.Parameters.Add(param2);
return dbcmd;
}
static List<CompanyDescription> CompanyDescriptionsFromDataTable(DataTable dataTable)
{
List<CompanyDescription> entries = new List<CompanyDescription>();
foreach(DataRow dataRow in dataTable.Rows)
{
CompanyDescription entry = new CompanyDescription
{
Id = int.Parse(dataRow["id"].ToString()),
CompanyId = int.Parse(dataRow["company_id"].ToString()),
Text = dataRow["text"].ToString()
};
entries.Add(entry);
}
return entries;
}
}
}

View File

@@ -35,7 +35,7 @@ namespace Cicm.Database
public partial class Operations
{
/// <summary>Last known database version</summary>
const int DB_VERSION = 8;
const int DB_VERSION = 9;
readonly IDbConnection dbCon;
readonly IDbCore dbCore;

View File

@@ -108,6 +108,11 @@ namespace Cicm.Database
UpdateDatabaseToV8();
break;
}
case 8:
{
UpdateDatabaseToV9();
break;
}
}
OptimizeDatabase();
@@ -804,6 +809,26 @@ namespace Cicm.Database
dbCmd.Dispose();
}
void UpdateDatabaseToV9()
{
Console.WriteLine("Updating database to version 9");
Console.WriteLine("Creating table `company_descriptions`");
IDbCommand dbCmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = V9.CompanyDescriptions;
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Setting new database version to 9...");
dbCmd = dbCon.CreateCommand();
dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('9')";
dbCmd.ExecuteNonQuery();
dbCmd.Dispose();
}
void OptimizeDatabase()
{
IDbCommand dbCmd = dbCon.CreateCommand();

View File

@@ -67,5 +67,7 @@ namespace Cicm.Database.Schemas
public string Twitter;
/// <summary>Website</summary>
public string Website;
/// <summary>Description</summary>
public string Description;
}
}

View File

@@ -0,0 +1,45 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Company.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// High level representation of a company.
//
// --[ 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
*******************************************************************************/
using System;
namespace Cicm.Database.Schemas
{
/// <summary>Company description</summary>
public class CompanyDescription
{
/// <summary>ID</summary>
public int Id;
/// <summary>Company ID</summary>
public int CompanyId;
/// <summary>Description</summary>
public string Text;
}
}

View File

@@ -0,0 +1,97 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : V8.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains SQL queries to create the database version 7.
//
// --[ 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
*******************************************************************************/
namespace Cicm.Database.Schemas.Sql
{
public static class V9
{
public static readonly string Admins = V8.Admins;
public static readonly string BrowserTests = V8.BrowserTests;
public static readonly string CicmDb = "CREATE TABLE `cicm_db` (\n" +
"`id` int(11) NOT NULL AUTO_INCREMENT,\n" +
"`version` int(11) NOT NULL,\n" +
"`updated` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
"PRIMARY KEY (`id`)\n" + ");\n" +
"INSERT INTO cicm_db (version) VALUES ('9');";
public static readonly string Companies = V8.Companies;
public static readonly string Computers = V8.Computers;
public static readonly string Consoles = V8.Consoles;
public static readonly string DiskFormats = V8.DiskFormats;
public static readonly string Forbidden = V8.Forbidden;
public static readonly string Gpus = V8.Gpus;
public static readonly string Logs = V8.Logs;
public static readonly string MoneyDonations = V8.MoneyDonations;
public static readonly string MusicSynths = V8.MusicSynths;
public static readonly string News = V8.News;
public static readonly string OwnedComputers = V8.OwnedComputers;
public static readonly string OwnedConsoles = V8.OwnedConsoles;
public static readonly string Processors = V8.Processors;
public static readonly string SoundSynths = V8.SoundSynths;
public static readonly string ComputersForeignKeys = V8.ComputersForeignKeys;
public static readonly string ConsolesForeignKeys = V8.ConsolesForeignKeys;
public static readonly string Iso3166Numeric = V8.Iso3166Numeric;
public static readonly string Iso3166NumericValues = V8.Iso3166NumericValues;
public static readonly string CompaniesForeignKeys = V8.CompaniesForeignKeys;
public static readonly string CompanyLogos = V8.CompanyLogos;
public static readonly string CompanyDescriptions =
"CREATE TABLE `company_descriptions` (\n" +
"`id` INT NOT NULL AUTO_INCREMENT,\n" +
"`company_id` INT NOT NULL,\n" +
"`text` text,\n" +
"PRIMARY KEY (`id`),\n" +
"INDEX `idx_company_id` (`company_id` ASC),\n" +
"FULLTEXT KEY `idx_text` (`text`),\n" +
"CONSTRAINT `fk_company_id` FOREIGN KEY (`id`) REFERENCES `companies` (`id`) ON DELETE CASCADE ON UPDATE CASCADE\n" +
")";
}
}

View File

@@ -55,6 +55,7 @@ namespace cicm_web.Models
public CompanyStatus Status;
public string Twitter;
public string Website;
public string Description;
public static CompanyWithItems GetItem(int id)
{
@@ -81,7 +82,8 @@ namespace cicm_web.Models
Twitter = dbItem.Twitter,
Website = dbItem.Website,
Logos = dbItem.Logos,
LastLogo = dbItem.LastLogo
LastLogo = dbItem.LastLogo,
Description = dbItem.Description
};
}
@@ -110,7 +112,8 @@ namespace cicm_web.Models
Twitter = t.Twitter,
Website = t.Website,
Logos = t.Logos,
LastLogo = t.LastLogo
LastLogo = t.LastLogo,
Description = t.Description
}).OrderBy(t => t.Name).ToArray();
}
@@ -141,7 +144,8 @@ namespace cicm_web.Models
Twitter = t.Twitter,
Website = t.Website,
Logos = t.Logos,
LastLogo = t.LastLogo
LastLogo = t.LastLogo,
Description = t.Description
}).OrderBy(t => t.Name).ToArray();
}
}

View File

@@ -37,347 +37,403 @@
@if(Model != null)
{
<div class="container">
<p align=center>
@if(Model.LastLogo != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.LastLogo.Guid + ".svg")))
{
<picture>
<source type="image/svg+xml"
srcset="/assets/logos/@(Model.LastLogo.Guid).svg">
<source type="image/webp"
srcset="/assets/logos/webp/1x/@(Model.LastLogo.Guid).webp,
/assets/logos/webp/1x/@(Model.LastLogo.Guid).webp 2x,
/assets/logos/webp/1x/@(Model.LastLogo.Guid).webp 3x">
<img srcset="/assets/logos/png/1x/@(Model.LastLogo.Guid).png,
/assets/logos/png/1x/@(Model.LastLogo.Guid).png 2x,
/assets/logos/png/1x/@(Model.LastLogo.Guid).webp 3x"
src="/assets/logos/png/1x@(Model.LastLogo.Guid).png")
alt=""
height="auto"
width="auto"
style="max-height: 256px; max-width: 256px" />
</picture>
}
</p>
<div class="row">
@{
string carrouselActive = "active";
}
@if(Model.Logos != null && Model.Logos.Length > 1)
{
<div class="col-3">
<div class="carousel slide"
data-ride="carousel"
id="logosCarousel">
<div class="carousel-inner">
@foreach(CompanyLogo logo in Model.Logos)
{
if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", logo.Guid + ".svg")))
{
<div class="carousel-item @carrouselActive">
<picture>
<source type="image/svg+xml"
srcset="/assets/logos/@(logo.Guid).svg">
<source type="image/webp"
srcset="/assets/logos/webp/1x/@(logo.Guid).webp,
/assets/logos/webp/1x/@(logo.Guid).webp 2x,
/assets/logos/webp/1x/@(logo.Guid).webp 3x">
<img class="d-block w-100"
srcset="/assets/logos/png/1x/@(logo.Guid).png,
/assets/logos/png/1x/@(logo.Guid).png 2x,
/assets/logos/png/1x/@(logo.Guid).webp 3x"
src="/assets/logos/png/1x@(logo.Guid).png")
alt=""
height="auto"
width="auto"
style="max-height: 256px; max-width: 256px" />
</picture>
</div>
carrouselActive = null;
}
}
</div>
<a class="carousel-control-prev"
data-slide="prev"
href="#logosCarousel"
role="button">
<span aria-hidden="true"
class="carousel-control-prev-icon">
</span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next"
data-slide="next"
href="#logosCarousel"
role="button">
<span aria-hidden="true"
class="carousel-control-next-icon">
</span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
}
<div class="col-md">
<table>
<tr>
<th colspan="2">
<b>@Model.Name</b>
</th>
</tr>
@if(Model.Founded > DateTime.MinValue)
{
<tr>
<th>Founded</th>
<td>@Model.Founded.ToLongDateString().</td>
</tr>
}
<tr>
<th>Country</th>
<td>
@if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/flags/countries", Model.Country.Id + ".svg")))
<div class="container-fluid">
<p align=center>
@if(Model.LastLogo != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.LastLogo.Guid + ".svg")))
{
<picture>
<source type="image/svg+xml"
srcset="/assets/flags/countries/@(Model.Country.Id).svg">
srcset="/assets/logos/@(Model.LastLogo.Guid).svg">
<source type="image/webp"
srcset="/assets/flags/countries/webp/1x/@(Model.Country.Id).webp,
/assets/flags/countries/webp/1x/@(Model.Country.Id).webp 2x,
/assets/flags/countries/webp/1x/@(Model.Country.Id).webp 3x">
<img srcset="/assets/flags/countries/png/1x/@(Model.Country.Id).png,
/assets/flags/countries/png/1x/@(Model.Country.Id).png 2x,
/assets/flags/countries/png/1x/@(Model.Country.Id).webp 3x"
src="/assets/flags/countries/png/1x@(Model.Country.Id).png")
srcset="/assets/logos/webp/1x/@(Model.LastLogo.Guid).webp,
/assets/logos/webp/1x/@(Model.LastLogo.Guid).webp 2x,
/assets/logos/webp/1x/@(Model.LastLogo.Guid).webp 3x">
<img srcset="/assets/logos/png/1x/@(Model.LastLogo.Guid).png,
/assets/logos/png/1x/@(Model.LastLogo.Guid).png 2x,
/assets/logos/png/1x/@(Model.LastLogo.Guid).webp 3x"
src="/assets/logos/png/1x@(Model.LastLogo.Guid).png")
alt=""
height="32" />
height="auto"
width="auto"
style="max-height: 256px; max-width: 256px" />
</picture>
}
@Model.Country.Name
</td>
</tr>
<tr>
<th>Status</th>
@switch(Model.Status)
{
case CompanyStatus.Unknown:
<td>Current company status is unknown.</td>
break;
case CompanyStatus.Active:
<td>Company is active.</td>
break;
case CompanyStatus.Sold:
if(Model.Sold != DateTime.MinValue)
{
if(Model.SoldTo != null)
{
<td>
Company was sold to
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a> on @Model.Sold.ToLongDateString().
</td>
}
else
{
<td>Company was sold on @Model.Sold.ToLongDateString() to an unknown company.</td>
}
}
else
{
if(Model.SoldTo != null)
{
<td>
Company was sold to
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a> on an unknown date.
</td>
}
else
{
<td>Company was sold to an unknown company on an unknown date.</td>
}
}
break;
case CompanyStatus.Merged:
if(Model.Sold != DateTime.MinValue)
{
if(Model.SoldTo != null)
{
<td>
Company was merged on @Model.Sold.ToLongDateString() to form
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a>.
</td>
}
else
{
<td>Company was merge on @Model.Sold.ToLongDateString() to form an unknown company.</td>
}
}
else
{
if(Model.SoldTo != null)
{
<td>
Company was merged on an unknown date to form
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a>.
</td>
}
else
{
<td>Company was merged to form an unknown company on an unknown date.</td>
}
}
break;
case CompanyStatus.Bankrupt:
if(Model.Sold != DateTime.MinValue)
{
<td>Company declared bankruptcy on @Model.Sold.ToLongDateString().</td>
}
else
{
<td>Company declared bankruptcy on an unknown date.</td>
}
break;
case CompanyStatus.Defunct:
if(Model.Sold != DateTime.MinValue)
{
<td>Company ceased operations on @Model.Sold.ToLongDateString().</td>
}
else
{
<td>Company ceased operations on an unknown date.</td>
}
break;
case CompanyStatus.Renamed:
if(Model.Sold != DateTime.MinValue)
{
if(Model.SoldTo != null)
{
<td>
Company was renamed to
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a> on @Model.Sold.ToLongDateString().
</td>
}
else
{
<td>Company was renamed on @Model.Sold.ToLongDateString() to an unknown name.</td>
}
}
else
{
if(Model.SoldTo != null)
{
<td>
Company was renamed to
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a> on an unknown date.
</td>
}
else
{
<td>Company was renamed to an unknown name on an unknown date.</td>
}
}
break;
default:
throw new ArgumentOutOfRangeException();
}
</tr>
<tr>
<th>Address</th>
<td>
@Model.Address<br>
@if(Model.City != Model.Province)
{
@Model.City<br>
</p>
<div class="row">
@{
string carrouselActive = "active";
}
@Model.PostalCode @Model.Province</td>
</tr>
@if(!string.IsNullOrEmpty(Model.Website) || !string.IsNullOrEmpty(Model.Twitter) || !string.IsNullOrEmpty(Model.Facebook))
@if(Model.Logos != null && Model.Logos.Length > 1)
{
<div class="col-3">
<div class="carousel slide"
data-ride="carousel"
id="logosCarousel">
<div class="carousel-inner">
@foreach(CompanyLogo logo in Model.Logos)
{
if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", logo.Guid + ".svg")))
{
<div class="carousel-item @carrouselActive">
<picture>
<source type="image/svg+xml"
srcset="/assets/logos/@(logo.Guid).svg">
<source type="image/webp"
srcset="/assets/logos/webp/1x/@(logo.Guid).webp,
/assets/logos/webp/1x/@(logo.Guid).webp 2x,
/assets/logos/webp/1x/@(logo.Guid).webp 3x">
<img class="d-block w-100"
srcset="/assets/logos/png/1x/@(logo.Guid).png,
/assets/logos/png/1x/@(logo.Guid).png 2x,
/assets/logos/png/1x/@(logo.Guid).webp 3x"
src="/assets/logos/png/1x@(logo.Guid).png")
alt=""
height="auto"
width="auto"
style="max-height: 256px; max-width: 256px" />
</picture>
</div>
carrouselActive = null;
}
}
</div>
<a class="carousel-control-prev"
data-slide="prev"
href="#logosCarousel"
role="button">
<span aria-hidden="true"
class="carousel-control-prev-icon">
</span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next"
data-slide="next"
href="#logosCarousel"
role="button">
<span aria-hidden="true"
class="carousel-control-next-icon">
</span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
}
<div class="col-md">
<table>
<tr>
<th colspan="2">
<b>@Model.Name</b>
</th>
</tr>
@if(Model.Founded > DateTime.MinValue)
{
<tr>
<th>Founded</th>
<td>@Model.Founded.ToLongDateString().</td>
</tr>
}
<tr>
<th>Country</th>
<td>
@if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/flags/countries", Model.Country.Id + ".svg")))
{
<picture>
<source type="image/svg+xml"
srcset="/assets/flags/countries/@(Model.Country.Id).svg">
<source type="image/webp"
srcset="/assets/flags/countries/webp/1x/@(Model.Country.Id).webp,
/assets/flags/countries/webp/1x/@(Model.Country.Id).webp 2x,
/assets/flags/countries/webp/1x/@(Model.Country.Id).webp 3x">
<img srcset="/assets/flags/countries/png/1x/@(Model.Country.Id).png,
/assets/flags/countries/png/1x/@(Model.Country.Id).png 2x,
/assets/flags/countries/png/1x/@(Model.Country.Id).webp 3x"
src="/assets/flags/countries/png/1x@(Model.Country.Id).png")
alt=""
height="32" />
</picture>
}
@Model.Country.Name
</td>
</tr>
<tr>
<th>Status</th>
@switch(Model.Status)
{
case CompanyStatus.Unknown:
<td>Current company status is unknown.</td>
break;
case CompanyStatus.Active:
<td>Company is active.</td>
break;
case CompanyStatus.Sold:
if(Model.Sold != DateTime.MinValue)
{
if(Model.SoldTo != null)
{
<td>
Company was sold to
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a> on @Model.Sold.ToLongDateString().
</td>
}
else
{
<td>Company was sold on @Model.Sold.ToLongDateString() to an unknown company.</td>
}
}
else
{
if(Model.SoldTo != null)
{
<td>
Company was sold to
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a> on an unknown date.
</td>
}
else
{
<td>Company was sold to an unknown company on an unknown date.</td>
}
}
break;
case CompanyStatus.Merged:
if(Model.Sold != DateTime.MinValue)
{
if(Model.SoldTo != null)
{
<td>
Company was merged on @Model.Sold.ToLongDateString() to form
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a>.
</td>
}
else
{
<td>Company was merge on @Model.Sold.ToLongDateString() to form an unknown company.</td>
}
}
else
{
if(Model.SoldTo != null)
{
<td>
Company was merged on an unknown date to form
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a>.
</td>
}
else
{
<td>Company was merged to form an unknown company on an unknown date.</td>
}
}
break;
case CompanyStatus.Bankrupt:
if(Model.Sold != DateTime.MinValue)
{
<td>Company declared bankruptcy on @Model.Sold.ToLongDateString().</td>
}
else
{
<td>Company declared bankruptcy on an unknown date.</td>
}
break;
case CompanyStatus.Defunct:
if(Model.Sold != DateTime.MinValue)
{
<td>Company ceased operations on @Model.Sold.ToLongDateString().</td>
}
else
{
<td>Company ceased operations on an unknown date.</td>
}
break;
case CompanyStatus.Renamed:
if(Model.Sold != DateTime.MinValue)
{
if(Model.SoldTo != null)
{
<td>
Company was renamed to
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a> on @Model.Sold.ToLongDateString().
</td>
}
else
{
<td>Company was renamed on @Model.Sold.ToLongDateString() to an unknown name.</td>
}
}
else
{
if(Model.SoldTo != null)
{
<td>
Company was renamed to
<a asp-controller="Company"
asp-action="View"
asp-route-id="@Model.SoldTo.Id">
@Model.SoldTo.Name</a> on an unknown date.
</td>
}
else
{
<td>Company was renamed to an unknown name on an unknown date.</td>
}
}
break;
default:
throw new ArgumentOutOfRangeException();
}
</tr>
<tr>
<th>Address</th>
<td>
@Model.Address<br>
@if(Model.City != Model.Province)
{
@Model.City<br>
}
@Model.PostalCode @Model.Province</td>
</tr>
@if(!string.IsNullOrEmpty(Model.Website) || !string.IsNullOrEmpty(Model.Twitter) || !string.IsNullOrEmpty(Model.Facebook))
{
<tr>
<th>Links</th>
<td>
@if(!string.IsNullOrEmpty(Model.Website))
{
<a href="@Model.Website">Website</a>
<br />
}
@if(!string.IsNullOrEmpty(Model.Twitter))
{
<a href="https://www.twitter.com/@Model.Twitter">Twitter</a>
<br />
}
@if(!string.IsNullOrEmpty(Model.Facebook))
{
<a href="https://www.facebook.com/@Model.Facebook">Facebook</a>
<br />
}
</td>
</tr>
}
</table>
</div>
</div>
<div class="row"
id="itemsAccordion">
<div class="card">
@if(Model.Computers.Any())
{
<div class="card-header"
id="headingComputers">
<h5 class="mb-0">
<button aria-controls="collapseComputers"
aria-expanded="false"
class="btn btn-info"
data-target="#collapseComputers"
data-toggle="collapse">
<span class="badge badge-success">@Model.Computers.Count()</span> computers known.
</button>
</h5>
</div>
<div aria-labelledby="headingComputers"
class="collapse"
data-parent="#itemsAccordion"
id="collapseComputers">
<div class="card-body">
@foreach(ComputerMini computer in Model.Computers)
{
<a asp-controller="Computer"
asp-action="View"
asp-route-id="@computer.Id">
@computer.Model</a>
<br />
}
</div>
</div>
}
else
{
<div class="card-header"
id="headingComputers">
<h5 class="mb-0">
<button class="btn btn-info">
<span class="badge badge-danger">No</span> computers known.
</button>
</h5>
</div>
}
@if(Model.Consoles.Any())
{
<div class="card-header"
id="headingConsoles">
<h5 class="mb-0">
<button aria-controls="collapseConsoles"
aria-expanded="false"
class="btn btn-info"
data-target="#collapseConsoles"
data-toggle="collapse">
<span class="badge badge-success">@Model.Consoles.Count()</span> videogame consoles known.
</button>
</h5>
</div>
<div aria-labelledby="headingConsoles"
class="collapse"
data-parent="#itemsAccordion"
id="collapseConsoles">
<div class="card-body">
@foreach(ConsoleMini console in Model.Consoles)
{
<a asp-controller="Console"
asp-action="View"
asp-route-id="@console.Id">
@console.Model</a>
<br />
}
</div>
</div>
}
else
{
<div class="card-header"
id="headingComputers">
<h5 class="mb-0">
<button class="btn btn-info">
<span class="badge badge-danger">No</span> videogame consoles known.
</button>
</h5>
</div>
}
</div>
</div>
@if(Model.Description != null)
{
<tr>
<th>Links</th>
<td>
@if(!string.IsNullOrEmpty(Model.Website))
{
<a href="@Model.Website">Website</a>
<br />
}
@if(!string.IsNullOrEmpty(Model.Twitter))
{
<a href="https://www.twitter.com/@Model.Twitter">Twitter</a>
<br />
}
@if(!string.IsNullOrEmpty(Model.Facebook))
{
<a href="https://www.facebook.com/@Model.Facebook">Facebook</a>
<br />
}
</td>
</tr>
<div class="row container-fluid">
@Model.Description
</div>
}
</table>
</div>
</div>
<div class="row">
@if(Model.Computers.Any())
{
<p>
@Model.Computers.Count() computers made by this company found in the database.<br />
@foreach(ComputerMini computer in Model.Computers)
{
<a asp-controller="Computer"
asp-action="View"
asp-route-id="@computer.Id">
@computer.Model</a>
<br />
}
</p>
}
else
{
<p>There are no computers made by this company in the database.</p>
}
</div>
<div class="row">
@if(Model.Consoles.Any())
{
<p>
@Model.Consoles.Count() videogame consoles made by this company found in the database.<br />
@foreach(ConsoleMini console in Model.Consoles)
{
<a asp-controller="Console"
asp-action="View"
asp-route-id="@console.Id">
@console.Model</a>
<br />
}
</p>
}
else
{
<p>There are no videogame consoles made by this company found in the database.</p>
}
</div>
</div>
}
else

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<Version>3.0.99.149</Version>
<Version>3.0.99.150</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>