Add new database fields for companies to model and view.

This commit is contained in:
2018-04-19 00:30:29 +01:00
parent d0e4c3f9e4
commit e25f5eacec
3 changed files with 291 additions and 32 deletions

View File

@@ -31,15 +31,28 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Cicm.Database.Schemas;
namespace cicm_web.Models namespace cicm_web.Models
{ {
public class CompanyWithItems public class CompanyWithItems
{ {
public string Address;
public string City;
public ComputerMini[] Computers; public ComputerMini[] Computers;
public ConsoleMini[] Consoles; public ConsoleMini[] Consoles;
public Iso3166 Country;
public string Facebook;
public DateTime Founded;
public int Id; public int Id;
public string Name; public string Name;
public string PostalCode;
public string Province;
public DateTime Sold;
public Cicm.Database.Schemas.Company SoldTo;
public CompanyStatus Status;
public string Twitter;
public string Website;
public static CompanyWithItems GetItem(int id) public static CompanyWithItems GetItem(int id)
{ {
@@ -52,7 +65,19 @@ namespace cicm_web.Models
Name = dbItem.Name, Name = dbItem.Name,
Id = dbItem.Id, Id = dbItem.Id,
Computers = ComputerMini.GetItemsWithCompany(id, dbItem.Name), Computers = ComputerMini.GetItemsWithCompany(id, dbItem.Name),
Consoles = ConsoleMini.GetItemsWithCompany(id, dbItem.Name) Consoles = ConsoleMini.GetItemsWithCompany(id, dbItem.Name),
Address = dbItem.Address,
City = dbItem.City,
Country = dbItem.Country,
Facebook = dbItem.Facebook,
Founded = dbItem.Founded,
PostalCode = dbItem.PostalCode,
Province = dbItem.Province,
Sold = dbItem.Sold,
SoldTo = dbItem.SoldTo,
Status = dbItem.Status,
Twitter = dbItem.Twitter,
Website = dbItem.Website
}; };
} }
@@ -62,7 +87,25 @@ namespace cicm_web.Models
bool? result = Program.Database?.Operations.GetCompanies(out dbItems); bool? result = Program.Database?.Operations.GetCompanies(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null; if(result == null || result.Value == false || dbItems == null) return null;
return dbItems.Select(t => new CompanyWithItems {Id = t.Id, Name = t.Name}).OrderBy(t => t.Name).ToArray(); return dbItems.Select(t => new CompanyWithItems
{
Id = t.Id,
Name = t.Name,
Computers = ComputerMini.GetItemsWithCompany(t.Id, t.Name),
Consoles = ConsoleMini.GetItemsWithCompany(t.Id, t.Name),
Address = t.Address,
City = t.City,
Country = t.Country,
Facebook = t.Facebook,
Founded = t.Founded,
PostalCode = t.PostalCode,
Province = t.Province,
Sold = t.Sold,
SoldTo = t.SoldTo,
Status = t.Status,
Twitter = t.Twitter,
Website = t.Website
}).OrderBy(t => t.Name).ToArray();
} }
public static CompanyWithItems[] GetItemsStartingWithLetter(char letter) public static CompanyWithItems[] GetItemsStartingWithLetter(char letter)
@@ -73,7 +116,25 @@ namespace cicm_web.Models
return dbItems return dbItems
.Where(t => t.Name.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase)) .Where(t => t.Name.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
.Select(t => new CompanyWithItems {Id = t.Id, Name = t.Name}).OrderBy(t => t.Name).ToArray(); .Select(t => new CompanyWithItems
{
Id = t.Id,
Name = t.Name,
Computers = ComputerMini.GetItemsWithCompany(t.Id, t.Name),
Consoles = ConsoleMini.GetItemsWithCompany(t.Id, t.Name),
Address = t.Address,
City = t.City,
Country = t.Country,
Facebook = t.Facebook,
Founded = t.Founded,
PostalCode = t.PostalCode,
Province = t.Province,
Sold = t.Sold,
SoldTo = t.SoldTo,
Status = t.Status,
Twitter = t.Twitter,
Website = t.Website
}).OrderBy(t => t.Name).ToArray();
} }
} }

View File

@@ -32,36 +32,231 @@
ViewData["Title"] = "Companies"; ViewData["Title"] = "Companies";
} }
@using System.IO @using System.IO
@using Cicm.Database.Schemas
@model CompanyWithItems @model CompanyWithItems
<p>Search results:</p>
<p align=center>
@if(Model != null) @if(Model != null)
{ {
if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.Id + ".gif"))) <p align=center>
@if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.Id + ".gif")))
{ {
<img src="@(System.IO.Path.Combine("/assets/logos", Model.Id + ".gif"))" <img src="@(System.IO.Path.Combine("/assets/logos", Model.Id + ".gif"))"
alt=""> alt="">
} }
if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.Id + ".jpg"))) @if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.Id + ".jpg")))
{ {
<img src="@(System.IO.Path.Combine("/assets/logos", Model.Id + ".jpg"))" <img src="@(System.IO.Path.Combine("/assets/logos", Model.Id + ".jpg"))"
alt=""> alt="">
} }
if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.Id + ".png"))) @if(File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.Id + ".png")))
{ {
<img src="@(System.IO.Path.Combine("/assets/logos", Model.Id + ".png"))" <img src="@(System.IO.Path.Combine("/assets/logos", Model.Id + ".png"))"
alt=""> alt="">
} }
</p>
<div>
<table>
<tr>
<th colspan="2">
<b>@Model.Name</b> <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>@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 /> <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>
if(Model.Computers.Any()) <div>
@if(Model.Computers.Any())
{ {
<p> <p>
@Model.Computers.Count() computers found in the database.<br /> @Model.Computers.Count() computers made by this company found in the database.<br />
@foreach(ComputerMini computer in Model.Computers) @foreach(ComputerMini computer in Model.Computers)
{ {
<a asp-controller="Computer" <a asp-controller="Computer"
@@ -74,13 +269,15 @@
} }
else else
{ {
<p>There are no computers found in the database that belong to that company.</p> <p>There are no computers made by this company in the database.</p>
} }
</div>
if(Model.Consoles.Any()) <div>
@if(Model.Consoles.Any())
{ {
<p> <p>
@Model.Consoles.Count() videoconsoles found in the database.<br /> @Model.Consoles.Count() videogame consoles made by this company found in the database.<br />
@foreach(ConsoleMini console in Model.Consoles) @foreach(ConsoleMini console in Model.Consoles)
{ {
<a asp-controller="Console" <a asp-controller="Console"
@@ -93,11 +290,12 @@
} }
else else
{ {
<p>There are no videoconsoles found in the database that belong to that company.</p> <p>There are no videogame consoles made by this company found in the database.</p>
} }
</div>
} }
else else
{ {
<p>Company not found!</p> <p>Company not found!</p>
} }
</p>

View File

@@ -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.121</Version> <Version>3.0.99.123</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>