diff --git a/Marechai.Database/Models/Resolution.cs b/Marechai.Database/Models/Resolution.cs index db37d864..d1682090 100644 --- a/Marechai.Database/Models/Resolution.cs +++ b/Marechai.Database/Models/Resolution.cs @@ -56,33 +56,5 @@ namespace Marechai.Database.Models public virtual ICollection Screens { 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"; - } } } \ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 50eb2304..3346c5bd 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.1192 + 3.0.99.1193 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website @@ -115,6 +115,9 @@ true + + true + <_ContentIncludedByDefault Remove="Areas\Admin\Views\BrowserTests\Delete.cshtml" /> diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs index e69c14ee..3189df36 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -60,6 +60,7 @@ namespace Marechai.Services services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Marechai/Services/ResolutionsService.cs b/Marechai/Services/ResolutionsService.cs new file mode 100644 index 00000000..1aa271db --- /dev/null +++ b/Marechai/Services/ResolutionsService.cs @@ -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> GetAsync() + { + List 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(); + } + } +} \ No newline at end of file diff --git a/Marechai/ViewModels/ResolutionViewModel.cs b/Marechai/ViewModels/ResolutionViewModel.cs new file mode 100644 index 00000000..db18f6ce --- /dev/null +++ b/Marechai/ViewModels/ResolutionViewModel.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Marechai.ViewModels +{ + public class ResolutionViewModel : BaseViewModel + { + 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"; + } + } +} \ No newline at end of file