Add resolutions service.

This commit is contained in:
2020-05-26 04:17:31 +01:00
parent 249c7a7baa
commit 3d2f0b7183
5 changed files with 78 additions and 29 deletions

View File

@@ -56,33 +56,5 @@ namespace Marechai.Database.Models
public virtual ICollection<Screen> Screens { get; set; } public virtual ICollection<Screen> Screens { get; set; }
public long? PaletteView => Palette ?? Colors; public long? PaletteView => Palette ?? Colors;
public override string ToString()
{
if(Chars)
{
if(Colors == null)
return$"{Width}x{Height} characters";
if(Palette != null &&
Colors != Palette)
return Grayscale ? $"{Width}x{Height} characters at {Colors} grays from a palette of {Palette}"
: $"{Width}x{Height} characters at {Colors} colors from a palette of {Palette}";
return Colors == 2 && Grayscale ? $"{Width}x{Height} black and white characters"
: $"{Width}x{Height} characters at {Colors} colors";
}
if(Colors == null)
return$"{Width}x{Height} pixels";
if(Palette != null &&
Colors != Palette)
return Grayscale ? $"{Width}x{Height} pixels at {Colors} grays from a palette of {Palette}"
: $"{Width}x{Height} pixels at {Colors} colors from a palette of {Palette}";
return Colors == 2 && Grayscale ? $"{Width}x{Height} black and white pixels"
: $"{Width}x{Height} pixels at {Colors} colors";
}
} }
} }

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.1192</Version> <Version>3.0.99.1193</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>
@@ -115,6 +115,9 @@
<Content Update="Pages\Admin\Details\Processor.razor"> <Content Update="Pages\Admin\Details\Processor.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content> </Content>
<Content Update="Pages\Admin\Details\Screen.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<_ContentIncludedByDefault Remove="Areas\Admin\Views\BrowserTests\Delete.cshtml" /> <_ContentIncludedByDefault Remove="Areas\Admin\Views\BrowserTests\Delete.cshtml" />

View File

@@ -60,6 +60,7 @@ namespace Marechai.Services
services.AddScoped<ScreensService>(); services.AddScoped<ScreensService>();
services.AddScoped<SoundSynthsService>(); services.AddScoped<SoundSynthsService>();
services.AddScoped<Iso31661NumericService>(); services.AddScoped<Iso31661NumericService>();
services.AddScoped<ResolutionsService>();
} }
} }
} }

View File

@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Marechai.Database.Models;
using Marechai.ViewModels;
using Microsoft.EntityFrameworkCore;
namespace Marechai.Services
{
public class ResolutionsService
{
readonly MarechaiContext _context;
public ResolutionsService(MarechaiContext context) => _context = context;
public async Task<List<ResolutionViewModel>> GetAsync()
{
List<ResolutionViewModel> list = await _context.Resolutions.Select(r => new ResolutionViewModel
{
Id = r.Id, Width = r.Width, Height = r.Height, Colors = r.Colors,
Palette = r.Palette, Chars = r.Chars, Grayscale = r.Grayscale
}).ToListAsync();
return list.OrderBy(r => r.ToString()).ToList();
}
}
}

View File

@@ -0,0 +1,46 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace Marechai.ViewModels
{
public class ResolutionViewModel : BaseViewModel<int>
{
public int Width { get; set; }
public int Height { get; set; }
public long? Colors { get; set; }
public long? Palette { get; set; }
public bool Chars { get; set; }
public bool Grayscale { get; set; }
public long? PaletteView => Palette ?? Colors;
public override string ToString()
{
if(Chars)
{
if(Colors == null)
return$"{Width}x{Height} characters";
if(Palette != null &&
Colors != Palette)
return Grayscale ? $"{Width}x{Height} characters at {Colors} grays from a palette of {Palette}"
: $"{Width}x{Height} characters at {Colors} colors from a palette of {Palette}";
return Colors == 2 && Grayscale ? $"{Width}x{Height} black and white characters"
: $"{Width}x{Height} characters at {Colors} colors";
}
if(Colors == null)
return$"{Width}x{Height} pixels";
if(Palette != null &&
Colors != Palette)
return Grayscale ? $"{Width}x{Height} pixels at {Colors} grays from a palette of {Palette}"
: $"{Width}x{Height} pixels at {Colors} colors from a palette of {Palette}";
return Colors == 2 && Grayscale ? $"{Width}x{Height} black and white pixels"
: $"{Width}x{Height} pixels at {Colors} colors";
}
}
}