Move all database logic in machine view out of the view into the controller.

This commit is contained in:
2020-05-22 04:43:44 +01:00
parent 113b9fbad8
commit b3414bde1d
9 changed files with 359 additions and 152 deletions

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.99.969</Version>
<Version>3.0.99.971</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>

View File

@@ -3,12 +3,12 @@
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Index.cshtml
// Filename : View.razor
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Index page (and news)
// Shows a machine information
//
// --[ License ] --------------------------------------------------------------
//
@@ -32,9 +32,8 @@
}
@page "/machine/{Id:int}"
@using Marechai.Database.Models
@using Marechai.Database
@using Marechai.Database
@inherits OwningComponentBase<MachinesService>
@inject IStringLocalizer<MachinesService> L
@inject IWebHostEnvironment Host
@@ -54,17 +53,17 @@
}
<p align="center">
@if (_machine.Company.LastLogo != null &&
File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", _machine.Company.LastLogo.Guid + ".svg")))
@if (_machine.CompanyLogo != null &&
File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", _machine.CompanyLogo + ".svg")))
{
<picture>
<source type="image/svg+xml" srcset="/assets/logos/@(_machine.Company.LastLogo.Guid).svg">
<source type="image/webp" srcset="/assets/logos/webp/1x/@(_machine.Company.LastLogo.Guid).webp,
/assets/logos/webp/2x/@(_machine.Company.LastLogo.Guid).webp 2x,
/assets/logos/webp/3x/@(_machine.Company.LastLogo.Guid).webp 3x">
<img srcset="/assets/logos/png/1x/@(_machine.Company.LastLogo.Guid).png,
/assets/logos/png/2x/@(_machine.Company.LastLogo.Guid).png 2x,
/assets/logos/png/3x/@(_machine.Company.LastLogo.Guid).png 3x" src="/assets/logos/png/1x/@(_machine.Company.LastLogo.Guid).png" alt="" height="auto" width="auto" style="max-height: 256px; max-width: 256px" />
<source type="image/svg+xml" srcset="/assets/logos/@(_machine.CompanyLogo).svg">
<source type="image/webp" srcset="/assets/logos/webp/1x/@(_machine.CompanyLogo).webp,
/assets/logos/webp/2x/@(_machine.CompanyLogo).webp 2x,
/assets/logos/webp/3x/@(_machine.CompanyLogo).webp 3x">
<img srcset="/assets/logos/png/1x/@(_machine.CompanyLogo).png,
/assets/logos/png/2x/@(_machine.CompanyLogo).png 2x,
/assets/logos/png/3x/@(_machine.CompanyLogo).png 3x" src="/assets/logos/png/1x/@(_machine.CompanyLogo).png" alt="" height="auto" width="auto" style="max-height: 256px; max-width: 256px" />
</picture>
}
</p>
@@ -78,8 +77,8 @@
</b>
}
<b>
<a asp-controller="Company" asp-action="View" asp-route-id="@_machine.Company.Id">
@_machine.Company.Name</a> @_machine.Name</b>
<a href="/company/@_machine.CompanyId">
@_machine.CompanyName</a> @_machine.Name</b>
<table width="100%">
@if (_machine.Introduced.HasValue &&
@@ -97,7 +96,7 @@
</td>
</tr>
}
@if (_machine.Family != null)
@if (_machine.FamilyId != null)
{
<tr>
<th scope=row width="37%">
@@ -106,8 +105,8 @@
</div>
</th>
<td width="63%">
<a asp-controller="Computer" asp-action="ByFamily" asp-route-id="@_machine.Family.Id">
@_machine.Family.Name</a>
<a href="/machines/family/@_machine.FamilyId">
@_machine.FamilyName</a>
</td>
</tr>
}
@@ -135,17 +134,17 @@
<td>
<table>
@{ counter = 0; }
@foreach (var processorByMachine in _machine.Processors)
@foreach (var processor in _machine.Processors)
{
<tr>
<td>
@if (processorByMachine.Speed > 0)
@if (processor.Speed > 0)
{
@(processorByMachine.Processor.GprSize > 0 ? $"{processorByMachine.Processor.Name} @ {processorByMachine.Speed}Mhz ({processorByMachine.Processor.GprSize} bits)" : $"{processorByMachine.Processor.Name} @ {processorByMachine.Speed}Mhz")
@(processor.GprSize > 0 ? $"{processor.Name} @ {processor.Speed}Mhz ({processor.GprSize} bits)" : $"{processor.Name} @ {processor.Speed}Mhz")
}
else
{
@($"{processorByMachine.Processor.Name}")
@($"{processor.Name}")
}
<a aria-controls="@($"cpuInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#cpuInfo{counter}")">
+info
@@ -153,87 +152,87 @@
<div class="collapse" id="@($"cpuInfo{counter}")">
<div class="card card-body">
<table>
@if (processorByMachine.Processor.ModelCode != null &&
processorByMachine.Processor.ModelCode != processorByMachine.Processor.Name)
@if (processor.ModelCode != null &&
processor.ModelCode != processor.Name)
{
<tr>
<td>Model</td>
<td>@processorByMachine.Processor.ModelCode</td>
<td>@processor.ModelCode</td>
</tr>
}
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company asp-action=View asp-route-id=@processorByMachine.Processor.Company.Id>
@processorByMachine.Processor.Company.Name</a>
<a href="/processors/company/@processor.CompanyId">
@processor.CompanyName</a>
</td>
</tr>
@if (processorByMachine.Processor.Introduced != DateTime.MinValue)
@if (processor.Introduced != null)
{
<tr>
<td>Introduction date</td>
<td>@($"{processorByMachine.Processor.Introduced:yyyy}")</td>
<td>@($"{processor.Introduced:yyyy}")</td>
</tr>
}
@if (processorByMachine.Processor.InstructionSet != null)
@if (processor.InstructionSet != null)
{
<tr>
<td>Instruction set</td>
<td>@processorByMachine.Processor.InstructionSet.Name</td>
<td>@processor.InstructionSet</td>
</tr>
}
@if (processorByMachine.Processor.Speed > 0)
@if (processor.Speed > 0)
{
<tr>
<td>Nominal speed</td>
<td>@processorByMachine.Processor.Speed MHz</td>
<td>@processor.Speed MHz</td>
</tr>
}
@if (processorByMachine.Processor.Gprs > 0 ||
processorByMachine.Processor.Fprs > 0 ||
processorByMachine.Processor.SimdRegisters > 0)
@if (processor.Gprs > 0 ||
processor.Fprs > 0 ||
processor.SimdRegisters > 0)
{
<tr>
<td>Registers</td>
<td>
<table>
@if (processorByMachine.Processor.Gprs > 0)
@if (processor.Gprs > 0)
{
<tr>
<td>
@processorByMachine.Processor.Gprs general purpose registers of @processorByMachine.Processor.GprSize bits
@if (processorByMachine.Processor.FprSize > 0 &&
processorByMachine.Processor.Fprs == 0)
@processor.Gprs general purpose registers of @processor.GprSize bits
@if (processor.FprSize > 0 &&
processor.Fprs == 0)
{
@($", that can be used as floating point registers of {processorByMachine.Processor.FprSize}")
@($", that can be used as floating point registers of {processor.FprSize}")
}
@if (processorByMachine.Processor.SimdSize > 0 &&
processorByMachine.Processor.SimdRegisters == 0)
@if (processor.SimdSize > 0 &&
processor.SimdRegisters == 0)
{
@($", that can be used as SIMD registers of {processorByMachine.Processor.FprSize}")
@($", that can be used as SIMD registers of {processor.FprSize}")
}
</td>
</tr>
}
@if (processorByMachine.Processor.Fprs > 0)
@if (processor.Fprs > 0)
{
<tr>
<td>
@processorByMachine.Processor.Fprs floating-point registers of @processorByMachine.Processor.FprSize bits
@if (processorByMachine.Processor.SimdSize > 0 &&
processorByMachine.Processor.SimdRegisters == 0)
@processor.Fprs floating-point registers of @processor.FprSize bits
@if (processor.SimdSize > 0 &&
processor.SimdRegisters == 0)
{
@($", that can be used as SIMD registers of {processorByMachine.Processor.FprSize}")
@($", that can be used as SIMD registers of {processor.FprSize}")
}
</td>
</tr>
}
@if (processorByMachine.Processor.SimdRegisters > 0)
@if (processor.SimdRegisters > 0)
{
<tr>
<td>
@processorByMachine.Processor.SimdRegisters
<abbr title="Single instruction, multiple data">SIMD</abbr>registers of @processorByMachine.Processor.SimdSize bits
@processor.SimdRegisters
<abbr title="Single instruction, multiple data">SIMD</abbr>registers of @processor.SimdSize bits
</td>
</tr>
}
@@ -241,48 +240,48 @@
</td>
</tr>
}
@if (processorByMachine.Processor.Cores > 1)
@if (processor.Cores > 1)
{
<tr>
<td>Multi-core</td>
<td>@processorByMachine.Processor.Cores cores</td>
<td>@processor.Cores cores</td>
</tr>
}
@if (processorByMachine.Processor.Cores > 1)
@if (processor.ThreadsPerCore > 1)
{
<tr>
<td>
<abbr title="Simultaneous multithreading">SMT</abbr>
</td>
<td>
@processorByMachine.Processor.ThreadsPerCore threads
@if (processorByMachine.Processor.Cores > 1)
@processor.ThreadsPerCore threads
@if (processor.Cores > 1)
{
@(" per core")
}
</td>
</tr>
}
@if (processorByMachine.Processor.DataBus > 0 ||
processorByMachine.Processor.AddrBus > 0)
@if (processor.DataBus > 0 ||
processor.AddrBus > 0)
{
<tr>
<td>Bus</td>
<td>
<table>
@if (processorByMachine.Processor.DataBus > 0)
@if (processor.DataBus > 0)
{
<tr>
<td>
@processorByMachine.Processor.DataBus-bit data
@processor.DataBus-bit data
</td>
</tr>
}
@if (processorByMachine.Processor.AddrBus > 0)
@if (processor.AddrBus > 0)
{
<tr>
<td>
@processorByMachine.Processor.AddrBus-bit address
@processor.AddrBus-bit address
</td>
</tr>
}
@@ -291,44 +290,44 @@
</tr>
}
@if (processorByMachine.Processor.L1Instruction > 0 ||
processorByMachine.Processor.L1Data > 0 ||
processorByMachine.Processor.L2 > 0 ||
processorByMachine.Processor.L2 > 0)
@if (processor.L1Instruction > 0 ||
processor.L1Data > 0 ||
processor.L2 > 0 ||
processor.L2 > 0)
{
<tr>
<td>Cache</td>
<td>
<table>
@if (processorByMachine.Processor.L1Instruction > 0)
@if (processor.L1Instruction > 0)
{
<tr>
<td>
@(processorByMachine.Processor.L1Data < 0 ? $"{processorByMachine.Processor.L1Instruction}KiB combined instruction-data L1" : $"{processorByMachine.Processor.L1Instruction}KiB instruction L1")
@(processor.L1Data < 0 ? $"{processor.L1Instruction}KiB combined instruction-data L1" : $"{processor.L1Instruction}KiB instruction L1")
</td>
</tr>
}
@if (processorByMachine.Processor.L1Data > 0)
@if (processor.L1Data > 0)
{
<tr>
<td>
@($"{processorByMachine.Processor.L1Data}KiB data L1")
@($"{processor.L1Data}KiB data L1")
</td>
</tr>
}
@if (processorByMachine.Processor.L2 > 0)
@if (processor.L2 > 0)
{
<tr>
<td>
@($"{processorByMachine.Processor.L2}KiB L2")
@($"{processor.L2}KiB L2")
</td>
</tr>
}
@if (processorByMachine.Processor.L3 > 0)
@if (processor.L3 > 0)
{
<tr>
<td>
@($"{processorByMachine.Processor.L3}KiB L3")
@($"{processor.L3}KiB L3")
</td>
</tr>
}
@@ -336,49 +335,49 @@
</td>
</tr>
}
@if (processorByMachine.Processor.Package != null)
@if (processor.Package != null)
{
<tr>
<td>Package</td>
<td>@processorByMachine.Processor.Package</td>
<td>@processor.Package</td>
</tr>
}
@if (processorByMachine.Processor.Process != null ||
processorByMachine.Processor.ProcessNm > 0)
@if (processor.Process != null ||
processor.ProcessNm > 0)
{
<tr>
<td>Manufacturing process</td>
<td>
@if (processorByMachine.Processor.Process != null &&
processorByMachine.Processor.ProcessNm > 0)
@if (processor.Process != null &&
processor.ProcessNm > 0)
{
@processorByMachine.Processor.Process
@processor.Process
@("@")
@(processorByMachine.Processor.ProcessNm > 100 ? $"{processorByMachine.Processor.ProcessNm / 100}µm" : $"{processorByMachine.Processor.ProcessNm}nm")
@(processor.ProcessNm > 100 ? $"{processor.ProcessNm / 100}µm" : $"{processor.ProcessNm}nm")
}
else if (processorByMachine.Processor.ProcessNm > 0)
else if (processor.ProcessNm > 0)
{
@(processorByMachine.Processor.ProcessNm > 100 ? $"{processorByMachine.Processor.ProcessNm / 100}µm" : $"{processorByMachine.Processor.ProcessNm}nm")
@(processor.ProcessNm > 100 ? $"{processor.ProcessNm / 100}µm" : $"{processor.ProcessNm}nm")
}
else
{
@processorByMachine.Processor.Process
@processor.Process
}
</td>
</tr>
}
@if (processorByMachine.Processor.DieSize > 0)
@if (processor.DieSize > 0)
{
<tr>
<td>Die size</td>
<td>@processorByMachine.Processor.DieSize mm&sup2;</td>
<td>@processor.DieSize mm&sup2;</td>
</tr>
}
@if (processorByMachine.Processor.Transistors > 0)
@if (processor.Transistors > 0)
{
<tr>
<td>Transistors</td>
<td>@processorByMachine.Processor.Transistors</td>
<td>@processor.Transistors</td>
</tr>
}
</table>
@@ -469,9 +468,9 @@
<td>
<table>
@{ counter = 0; }
@foreach (var gpuByMachine in _machine.Gpus)
@foreach (var gpu in _machine.Gpus)
{
if (gpuByMachine.Gpu.Id == -2)
if (gpu.Id == -2)
{
<td>
Framebuffer
@@ -489,78 +488,78 @@
else
{
<td>
@($"{gpuByMachine.Gpu.Name}")
@($"{gpu.Name}")
<a aria-controls="@($"gpuInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#gpuInfo{counter}")">
+info
</a>
<div class="collapse" id="@($"gpuInfo{counter}")">
<div class="card card-body">
<table>
@if (gpuByMachine.Gpu.ModelCode != null &&
gpuByMachine.Gpu.ModelCode != gpuByMachine.Gpu.Name)
@if (gpu.ModelCode != null &&
gpu.ModelCode != gpu.Name)
{
<tr>
<td>Model</td>
<td>@gpuByMachine.Gpu.ModelCode</td>
<td>@gpu.ModelCode</td>
</tr>
}
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company asp-action=View asp-route-id=@gpuByMachine.Gpu.Company.Id>
@gpuByMachine.Gpu.Company.Name</a>
<a href="/gpus/company/@gpu.CompanyId">
@gpu.Company</a>
</td>
</tr>
@if (gpuByMachine.Gpu.Introduced != DateTime.MinValue)
@if (gpu.Introduced != null)
{
<tr>
<td>Introduction date</td>
<td>@($"{gpuByMachine.Gpu.Introduced:yyyy}")</td>
<td>@($"{gpu.Introduced:yyyy}")</td>
</tr>
}
@if (gpuByMachine.Gpu.Package != null)
@if (gpu.Package != null)
{
<tr>
<td>Package</td>
<td>@gpuByMachine.Gpu.Package</td>
<td>@gpu.Package</td>
</tr>
}
@if (gpuByMachine.Gpu.Process != null ||
gpuByMachine.Gpu.ProcessNm > 0)
@if (gpu.Process != null ||
gpu.ProcessNm > 0)
{
<tr>
<td>Manufacturing process</td>
<td>
@if (gpuByMachine.Gpu.Process != null &&
gpuByMachine.Gpu.ProcessNm > 0)
@if (gpu.Process != null &&
gpu.ProcessNm > 0)
{
@gpuByMachine.Gpu.Process
@gpu.Process
@("@")
@(gpuByMachine.Gpu.ProcessNm > 100 ? $"{gpuByMachine.Gpu.ProcessNm / 100}µm" : $"{gpuByMachine.Gpu.ProcessNm}nm")
@(gpu.ProcessNm > 100 ? $"{gpu.ProcessNm / 100}µm" : $"{gpu.ProcessNm}nm")
}
else if (gpuByMachine.Gpu.ProcessNm > 0)
else if (gpu.ProcessNm > 0)
{
@(gpuByMachine.Gpu.ProcessNm > 100 ? $"{gpuByMachine.Gpu.ProcessNm / 100}µm" : $"{gpuByMachine.Gpu.ProcessNm}nm")
@(gpu.ProcessNm > 100 ? $"{gpu.ProcessNm / 100}µm" : $"{gpu.ProcessNm}nm")
}
else
{
@gpuByMachine.Gpu.Process
@gpu.Process
}
</td>
</tr>
}
@if (gpuByMachine.Gpu.DieSize > 0)
@if (gpu.DieSize > 0)
{
<tr>
<td>Die size</td>
<td>@gpuByMachine.Gpu.DieSize mm&sup2;</td>
<td>@gpu.DieSize mm&sup2;</td>
</tr>
}
@if (gpuByMachine.Gpu.Transistors > 0)
@if (gpu.Transistors > 0)
{
<tr>
<td>Transistors</td>
<td>@gpuByMachine.Gpu.Transistors</td>
<td>@gpu.Transistors</td>
</tr>
}
</table>
@@ -574,7 +573,7 @@
</td>
</tr>
}
@if (_machine.Sound.Count > 0)
@if (_machine.SoundSynthetizers.Count > 0)
{
<tr>
<th scope=row>
@@ -585,10 +584,10 @@
<td>
<table>
@{ counter = 0; }
@foreach (var soundByMachine in _machine.Sound)
@foreach (var sound in _machine.SoundSynthetizers)
{
<tr>
@if (soundByMachine.SoundSynth.Id == -2)
@if (sound.Id == -2)
{
<td>
Software
@@ -606,104 +605,104 @@
else
{
<td>
@($"{soundByMachine.SoundSynth.Name}")
@($"{sound.Name}")
<a aria-controls="@($"synthInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#synthInfo{counter}")">
+info
</a>
<div class="collapse" id="@($"synthInfo{counter}")">
<div class="card card-body">
<table>
@if (soundByMachine.SoundSynth.ModelCode != null &&
soundByMachine.SoundSynth.ModelCode != soundByMachine.SoundSynth.Name)
@if (sound.ModelCode != null &&
sound.ModelCode != sound.Name)
{
<tr>
<td>Model</td>
<td>@soundByMachine.SoundSynth.ModelCode</td>
<td>@sound.ModelCode</td>
</tr>
}
@if (soundByMachine.SoundSynth.Company != null)
@if (sound.CompanyId != null)
{
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company asp-action=View asp-route-id=@soundByMachine.SoundSynth.Company.Id>
@soundByMachine.SoundSynth.Company.Name</a>
<a href="/soundsynths/company/@sound.CompanyId">
@sound.CompanyName</a>
</td>
</tr>
}
@if (soundByMachine.SoundSynth.Introduced != DateTime.MinValue)
@if (sound.Introduced != null)
{
<tr>
<td>Introduction date</td>
<td>@($"{soundByMachine.SoundSynth.Introduced:yyyy}")</td>
<td>@($"{sound.Introduced:yyyy}")</td>
</tr>
}
@if (soundByMachine.SoundSynth.Voices != 0 ||
soundByMachine.SoundSynth.SquareWave != 0 ||
soundByMachine.SoundSynth.WhiteNoise != 0)
@if (sound.Voices != 0 ||
sound.SquareWave != 0 ||
sound.WhiteNoise != 0)
{
<tr>
<td>Generators</td>
<td>
<table>
@if (soundByMachine.SoundSynth.Voices != 0)
@if (sound.Voices != 0)
{
<tr>
<td>@soundByMachine.SoundSynth.Voices voices</td>
<td>@sound.Voices voices</td>
</tr>
}
@if (soundByMachine.SoundSynth.SquareWave != 0)
@if (sound.SquareWave != 0)
{
<tr>
<td>@soundByMachine.SoundSynth.SquareWave square wave</td>
<td>@sound.SquareWave square wave</td>
</tr>
}
@if (soundByMachine.SoundSynth.WhiteNoise != 0)
@if (sound.WhiteNoise != 0)
{
<tr>
<td>@soundByMachine.SoundSynth.WhiteNoise white noise</td>
<td>@sound.WhiteNoise white noise</td>
</tr>
}
</table>
</td>
</tr>
}
@if (soundByMachine.SoundSynth.Depth != 0 ||
soundByMachine.SoundSynth.Frequency > 0)
@if (sound.Depth != 0 ||
sound.Frequency > 0)
{
<tr>
<td>Sample rate</td>
<td>
<table>
@if (soundByMachine.SoundSynth.Depth != 0 &&
soundByMachine.SoundSynth.Frequency > 0)
@if (sound.Depth != 0 &&
sound.Frequency > 0)
{
<tr>
<td>@soundByMachine.SoundSynth.Depth bits at @(soundByMachine.SoundSynth.Frequency > 1000 ? $"{soundByMachine.SoundSynth.Frequency / 1000}KHz" : $"{soundByMachine.SoundSynth.Frequency}Hz")</td>
<td>@sound.Depth bits at @(sound.Frequency > 1000 ? $"{sound.Frequency / 1000}KHz" : $"{sound.Frequency}Hz")</td>
</tr>
}
else if (soundByMachine.SoundSynth.Depth != 0)
else if (sound.Depth != 0)
{
<tr>
<td>@soundByMachine.SoundSynth.Depth bits</td>
<td>@sound.Depth bits</td>
</tr>
}
else
{
<tr>
<td>@(soundByMachine.SoundSynth.Frequency > 1000 ? $"{soundByMachine.SoundSynth.Frequency / 1000}KHz" : $"{soundByMachine.SoundSynth.Frequency}Hz")</td>
<td>@(sound.Frequency > 1000 ? $"{sound.Frequency / 1000}KHz" : $"{sound.Frequency}Hz")</td>
</tr>
}
</table>
</td>
</tr>
}
@if (soundByMachine.SoundSynth.Type != 0)
@if (sound.Type != 0)
{
<tr>
<td>Synthetizer type</td>
<td>
@soundByMachine.SoundSynth.Type
@sound.Type
</td>
</tr>
}
@@ -811,7 +810,7 @@
[Parameter]
public int Id { get; set; }
Machine _machine;
MachineViewModel _machine;
bool _loaded;
protected override async Task OnInitializedAsync()

View File

@@ -1,5 +1,8 @@
using System.Linq;
using System.Threading.Tasks;
using Marechai.Database.Models;
using Marechai.ViewModels;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Services
@@ -15,6 +18,99 @@ namespace Marechai.Services
_l = localizer;
}
public async Task<Machine> GetMachine(int id) => await _context.Machines.FindAsync(id);
public async Task<MachineViewModel> GetMachine(int id)
{
Machine machine = await _context.Machines.FindAsync(id);
if(machine is null)
return null;
var model = new MachineViewModel
{
Introduced = machine.Introduced, Name = machine.Name, CompanyId = machine.CompanyId,
Model = machine.Model
};
Company company = await _context.Companies.FindAsync(model.CompanyId);
if(company != null)
{
model.CompanyName = company.Name;
IQueryable<CompanyLogo> logos = _context.CompanyLogos.Where(l => l.CompanyId == company.Id);
if(model.Introduced.HasValue)
model.CompanyLogo = (await logos.FirstOrDefaultAsync(l => l.Year >= model.Introduced.Value.Year))?.
Guid;
if(model.CompanyLogo is null &&
logos.Any())
model.CompanyLogo = (await logos.FirstAsync())?.Guid;
}
MachineFamily family = await _context.MachineFamilies.FindAsync(machine.FamilyId);
if(family != null)
{
model.FamilyName = family.Name;
model.FamilyId = family.Id;
}
model.Gpus = await _context.GpusByMachine.Where(g => g.MachineId == machine.Id).Select(g => g.Gpu).
Select(g => new GpuViewModel
{
Id = g.Id, Name = g.Name, Company = g.Company.Name,
CompanyId = g.Company.Id, ModelCode = g.ModelCode,
Introduced = g.Introduced, Package = g.Package, Process = g.Process,
ProcessNm = g.ProcessNm, DieSize = g.DieSize, Transistors = g.Transistors
}).ToListAsync();
model.Memory = await _context.MemoryByMachine.Where(m => m.MachineId == machine.Id).
Select(m => new MemoryViewModel
{
Type = m.Type, Usage = m.Usage, Size = m.Size, Speed = m.Speed
}).ToListAsync();
model.Processors = await _context.ProcessorsByMachine.Where(p => p.MachineId == machine.Id).
Select(p => new ProcessorViewModel
{
Name = p.Processor.Name, CompanyName = p.Processor.Company.Name,
CompanyId = p.Processor.Company.Id, ModelCode = p.Processor.ModelCode,
Introduced = p.Processor.Introduced, Speed = p.Speed,
Package = p.Processor.Package, Gprs = p.Processor.Gprs,
GprSize = p.Processor.GprSize, Fprs = p.Processor.Fprs,
FprSize = p.Processor.FprSize, Cores = p.Processor.Cores,
ThreadsPerCore = p.Processor.ThreadsPerCore,
Process = p.Processor.Process, ProcessNm = p.Processor.ProcessNm,
DieSize = p.Processor.DieSize, Transistors = p.Processor.Transistors,
DataBus = p.Processor.DataBus, AddrBus = p.Processor.AddrBus,
SimdRegisters = p.Processor.SimdRegisters,
SimdSize = p.Processor.SimdSize,
L1Instruction = p.Processor.L1Instruction,
L1Data = p.Processor.L1Data, L2 = p.Processor.L2, L3 = p.Processor.L3,
InstructionSet = p.Processor.InstructionSet.Name,
InstructionSetExtensions =
p.Processor.InstructionSetExtensions.
Select(e => e.Extension.Extension).ToList()
}).ToListAsync();
model.SoundSynthetizers =
await _context.SoundByMachine.Where(s => s.MachineId == machine.Id).Select(s => s.SoundSynth).
Select(s => new SoundSynthViewModel
{
Id = s.Id, Name = s.Name, CompanyId = s.Company.Id, CompanyName = s.Company.Name,
ModelCode = s.ModelCode, Introduced = s.Introduced, Voices = s.Voices,
Frequency = s.Frequency, Depth = s.Depth, SquareWave = s.SquareWave,
WhiteNoise = s.WhiteNoise, Type = s.Type
}).ToListAsync();
model.Storage = await _context.StorageByMachine.Where(s => s.MachineId == machine.Id).
Select(s => new StorageViewModel
{
Type = s.Type, Interface = s.Interface, Capacity = s.Capacity
}).ToListAsync();
return model;
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
namespace Marechai.ViewModels
{
public class GpuViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public int? CompanyId { get; set; }
public string Company { get; set; }
public string ModelCode { get; set; }
public DateTime? Introduced { get; set; }
public string Package { get; set; }
public string Process { get; set; }
public float? ProcessNm { get; set; }
public float? DieSize { get; set; }
public long? Transistors { get; set; }
}
}

View File

@@ -1,9 +1,23 @@
using System;
using System.Collections.Generic;
namespace Marechai.ViewModels
{
public class MachineViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public string CompanyName { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public string Model { get; set; }
public string CompanyName { get; set; }
public int CompanyId { get; set; }
public Guid? CompanyLogo { get; set; }
public DateTime? Introduced { get; set; }
public int? FamilyId { get; set; }
public string FamilyName { get; set; }
public List<GpuViewModel> Gpus { get; set; }
public List<MemoryViewModel> Memory { get; set; }
public List<ProcessorViewModel> Processors { get; set; }
public List<SoundSynthViewModel> SoundSynthetizers { get; set; }
public List<StorageViewModel> Storage { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using Marechai.Database;
namespace Marechai.ViewModels
{
public class MemoryViewModel
{
public MemoryType Type { get; set; }
public MemoryUsage Usage { get; set; }
public long? Size { get; set; }
public double? Speed { get; set; }
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
namespace Marechai.ViewModels
{
public class ProcessorViewModel
{
public string Name { get; set; }
public string CompanyName { get; set; }
public string ModelCode { get; set; }
public DateTime? Introduced { get; set; }
public double? Speed { get; set; }
public string Package { get; set; }
public int? Gprs { get; set; }
public int? GprSize { get; set; }
public int? Fprs { get; set; }
public int? FprSize { get; set; }
public int? Cores { get; set; }
public int? ThreadsPerCore { get; set; }
public string Process { get; set; }
public float? ProcessNm { get; set; }
public float? DieSize { get; set; }
public long? Transistors { get; set; }
public int? DataBus { get; set; }
public int? AddrBus { get; set; }
public int? SimdRegisters { get; set; }
public int? SimdSize { get; set; }
public float? L1Instruction { get; set; }
public float? L1Data { get; set; }
public float? L2 { get; set; }
public float? L3 { get; set; }
public string InstructionSet { get; set; }
public List<string> InstructionSetExtensions { get; set; }
public int? CompanyId { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
using System;
namespace Marechai.ViewModels
{
public class SoundSynthViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public string CompanyName { get; set; }
public int? CompanyId { get; set; }
public string ModelCode { get; set; }
public DateTime? Introduced { get; set; }
public int? Voices { get; set; }
public double? Frequency { get; set; }
public int? Depth { get; set; }
public int? SquareWave { get; set; }
public int? WhiteNoise { get; set; }
public int? Type { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
using Marechai.Database;
namespace Marechai.ViewModels
{
public class StorageViewModel
{
public StorageType Type { get; set; }
public StorageInterface Interface { get; set; }
public long? Capacity { get; set; }
}
}