Move GPUs call to GpusService.

This commit is contained in:
2020-05-24 18:51:24 +01:00
parent 051a1233e3
commit 4d908b7d31
3 changed files with 27 additions and 21 deletions

View File

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

View File

@@ -13,12 +13,22 @@ namespace Marechai.Services
public GpusService(MarechaiContext context) => _context = context; public GpusService(MarechaiContext context) => _context = context;
public async Task<List<GpuViewModel>> GetAsync() => await _context.Gpus.Include(g => g.Company).OrderBy(g => g.Company.Name).ThenBy(g => g.Name). public async Task<List<GpuViewModel>> GetAsync() =>
ThenBy(g => g.Introduced).Select(g => new GpuViewModel await _context.Gpus.OrderBy(g => g.Company.Name).ThenBy(g => g.Name).ThenBy(g => g.Introduced).
{ Select(g => new GpuViewModel
Id = g.Id, Company = g.Company.Name, {
Introduced = g.Introduced, Id = g.Id, Company = g.Company.Name, Introduced = g.Introduced, ModelCode = g.ModelCode,
ModelCode = g.ModelCode, Name = g.Name Name = g.Name
}).ToListAsync(); }).ToListAsync();
public async Task<List<GpuViewModel>> GetByMachineAsync(int machineId) =>
await _context.GpusByMachine.Where(g => g.MachineId == machineId).Select(g => g.Gpu).
OrderBy(g => g.Company.Name).ThenBy(g => g.Name).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();
} }
} }

View File

@@ -11,16 +11,19 @@ namespace Marechai.Services
public class MachinesService public class MachinesService
{ {
readonly MarechaiContext _context; readonly MarechaiContext _context;
readonly GpusService _gpusService;
readonly IStringLocalizer<MachinesService> _l; readonly IStringLocalizer<MachinesService> _l;
readonly ProcessorsService _processorsService; readonly ProcessorsService _processorsService;
readonly SoundSynthsService _soundSynthsService; readonly SoundSynthsService _soundSynthsService;
public MachinesService(MarechaiContext context, IStringLocalizer<MachinesService> localizer, public MachinesService(MarechaiContext context, IStringLocalizer<MachinesService> localizer,
ProcessorsService processorsService, SoundSynthsService soundSynthsService) GpusService gpusService, ProcessorsService processorsService,
SoundSynthsService soundSynthsService)
{ {
_context = context; _context = context;
_l = localizer; _l = localizer;
_processorsService = processorsService; _gpusService = gpusService;
_processorsService = processorsService;
_soundSynthsService = soundSynthsService; _soundSynthsService = soundSynthsService;
} }
@@ -70,14 +73,7 @@ namespace Marechai.Services
model.FamilyId = family.Id; model.FamilyId = family.Id;
} }
model.Gpus = await _context.GpusByMachine.Where(g => g.MachineId == machine.Id).Select(g => g.Gpu). model.Gpus = await _gpusService.GetByMachineAsync(machine.Id);
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). model.Memory = await _context.MemoryByMachine.Where(m => m.MachineId == machine.Id).
Select(m => new MemoryViewModel Select(m => new MemoryViewModel