diff --git a/Marechai.Database/Models/SoftwareVariant.cs b/Marechai.Database/Models/SoftwareVariant.cs index 282f262e..46fb6584 100644 --- a/Marechai.Database/Models/SoftwareVariant.cs +++ b/Marechai.Database/Models/SoftwareVariant.cs @@ -60,5 +60,7 @@ namespace Marechai.Database.Models public virtual ICollection RequiredSoftware { get; set; } public virtual ICollection SupportedSound { get; set; } public virtual ICollection Files { get; set; } + public ulong? ParentId { get; set; } + public ulong SoftwareVersionId { get; set; } } } \ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index ea6257fa..23e63ae5 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 4.0.0.1816 + 4.0.0.1817 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website diff --git a/Marechai/Pages/Admin/Details/SoftwareVariant.razor b/Marechai/Pages/Admin/Details/SoftwareVariant.razor new file mode 100644 index 00000000..73f4f5f0 --- /dev/null +++ b/Marechai/Pages/Admin/Details/SoftwareVariant.razor @@ -0,0 +1,319 @@ +@{ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Author(s) : Natalia Portillo +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2020 Natalia Portillo +*******************************************************************************/ +} + +@page "/admin/software_variants/details/{Id:ulong}" +@page "/admin/software_variants/edit/{Id:ulong}" +@page "/admin/software_variants/create" +@using Marechai.Database +@using Marechai.Database.Models +@inherits OwningComponentBase +@inject IStringLocalizer L +@inject SoftwareVersionsService SoftwareVersionsService +@inject LicensesService LicensesService +@inject NavigationManager NavigationManager +@inject IWebHostEnvironment Host +@inject IJSRuntime JSRuntime +@inject Microsoft.AspNetCore.Identity.UserManager UserManager +@inject AuthenticationStateProvider AuthenticationStateProvider +@attribute [Authorize(Roles = "UberAdmin, Admin")] + + +

@L["Software variant details"]

+
+ +@if (!_loaded) +{ +

@L["Loading..."]

+ + return; +} + +
+ + @L["Software version"] + + + @if (_editing || _model.Name != null) + { + + @L["Name, if different from software version name"] + @if (_editing) + { + @L["Unknown (name)"] + } + @if (!_editing || + !_unknownName) + { + + + + @L["Please enter a valid name."] + + + + } + + } + @if (_editing || _model.Version != null) + { + + @L["Version, if different from software version's"] + @if (_editing) + { + @L["Unknown (version)"] + } + @if (!_editing || + !_unknownVersion) + { + + + + @L["Please enter a valid version."] + + + + } + + } + @if (_editing || _model.Introduced != null) + { + + @L["Introduced"] + @if (_editing) + { + @L["Unknown (introduction date)"] + } + @if (!_editing || !_unknownIntroduced) + { + + + + @L["Please enter a valid introduction date."] + + + + } + + } + @if (_editing || _model.ParentId != null) + { + + @L["Parent"] + @if (_editing) + { + @L["Unknown or none (parent variant)"] + } + @if (!_editing || + !_unknownParent) + { + + } + + } + @if (_editing || _model.MinimumMemory.HasValue) + { + + @L["Minimum memory (bytes)"] + @if (_editing) + { + @L["Unknown (minimum memory)"] + } + @if (!_editing || + !_unknownMinimumMemory) + { + + + + @L["Please enter the minimum memory size in bytes."] + + + + } + + } + @if (_editing || _model.RecommendedMemory.HasValue) + { + + @L["Recommended memory (bytes)"] + @if (_editing) + { + @L["Unknown (recommended memory)"] + } + @if (!_editing || + !_unknownRecommendedMemory) + { + + + + @L["Please enter the recommended memory size in bytes."] + + + + } + + } + @if (_editing || _model.RequiredStorage.HasValue) + { + + @L["Required storage (bytes)"] + @if (_editing) + { + @L["Unknown (required storage)"] + } + @if (!_editing || + !_unknownRequiredStorage) + { + + + + @L["Please enter the required storage size in bytes."] + + + + } + + } + @if (_editing || _model.PartNumber != null) + { + + @L["Part number"] + @if (_editing) + { + @L["Unknown (part number)"] + } + @if (!_editing || + !_unknownPartNumber) + { + + + + @L["Please enter a valid part number."] + + + + } + + } + @if (_editing || _model.SerialNumber != null) + { + + @L["Serial number"] + @if (_editing) + { + @L["Unknown (serial number)"] + } + @if(_editing) + { + @L["Serial number is NOT the serial number used to install the software, but a serial number some software manufacturers use as SKU."] + } + @if (!_editing || + !_unknownSerialNumber) + { + + + + @L["Please enter a valid serial number."] + + + + } + + } + @if (_editing || _model.ProductCode != null) + { + + @L["Product code"] + @if (_editing) + { + @L["Unknown (product code)"] + } + @if (!_editing || + !_unknownProductCode) + { + + + + @L["Please enter a valid product code."] + + + + } + + } + @if (_editing || _model.CatalogueNumber != null) + { + + @L["Catalogue number"] + @if (_editing) + { + @L["Unknown (catalogue number)"] + } + @if (!_editing || + !_unknownCatalogueNumber) + { + + + + @L["Please enter a valid catalogue number."] + + + + } + + } + + @L["Distribution mode"] + + +
+
+ @if (!_editing) + { + + } + else + { + + + } + @L["Back to list"] +
diff --git a/Marechai/Pages/Admin/Details/SoftwareVariant.razor.cs b/Marechai/Pages/Admin/Details/SoftwareVariant.razor.cs new file mode 100644 index 00000000..7b5dac01 --- /dev/null +++ b/Marechai/Pages/Admin/Details/SoftwareVariant.razor.cs @@ -0,0 +1,213 @@ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Author(s) : Natalia Portillo +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2020 Natalia Portillo +*******************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Blazorise; +using Marechai.Database; +using Marechai.Shared; +using Marechai.ViewModels; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Authorization; + +namespace Marechai.Pages.Admin.Details +{ + public partial class SoftwareVariant + { + AuthenticationState _authState; + bool _creating; + bool _editing; + bool _loaded; + SoftwareVariantViewModel _model; + List _softwareVariants; + List _softwareVersions; + bool _unknownCatalogueNumber; + bool _unknownIntroduced; + bool _unknownMinimumMemory; + bool _unknownName; + bool _unknownParent; + bool _unknownPartNumber; + bool _unknownProductCode; + bool _unknownRecommendedMemory; + bool _unknownRequiredStorage; + + bool _unknownSerialNumber; + bool _unknownVersion; + + [Parameter] + public ulong Id { get; set; } + + uint Distribution + { + get => (uint)_model.DistributionMode; + set => _model.DistributionMode = (DistributionMode)value; + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if(_loaded) + return; + + _loaded = true; + + _creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). + StartsWith("admin/software_variants/create", + StringComparison.InvariantCulture); + + if(Id <= 0 && + !_creating) + return; + + _softwareVariants = await Service.GetAsync(); + _softwareVersions = await SoftwareVersionsService.GetAsync(); + _model = _creating ? new SoftwareVariantViewModel() : await Service.GetAsync(Id); + _authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + + _editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). + StartsWith("admin/software_variants/edit/", + StringComparison.InvariantCulture); + + if(_editing) + SetCheckboxes(); + + StateHasChanged(); + } + + void SetCheckboxes() + { + _unknownName = string.IsNullOrWhiteSpace(_model.Name); + _unknownVersion = string.IsNullOrWhiteSpace(_model.Version); + _unknownParent = !_model.ParentId.HasValue; + _unknownMinimumMemory = !_model.MinimumMemory.HasValue; + _unknownRecommendedMemory = !_model.RecommendedMemory.HasValue; + _unknownRequiredStorage = !_model.RequiredStorage.HasValue; + _unknownPartNumber = string.IsNullOrWhiteSpace(_model.PartNumber); + _unknownSerialNumber = string.IsNullOrWhiteSpace(_model.SerialNumber); + _unknownProductCode = string.IsNullOrWhiteSpace(_model.ProductCode); + _unknownCatalogueNumber = string.IsNullOrWhiteSpace(_model.CatalogueNumber); + _unknownIntroduced = !_model.Introduced.HasValue; + } + + void OnEditClicked() + { + _editing = true; + SetCheckboxes(); + StateHasChanged(); + } + + async void OnCancelClicked() + { + _editing = false; + + if(_creating) + { + NavigationManager.ToBaseRelativePath("admin/software_variants"); + + return; + } + + _model = await Service.GetAsync(Id); + SetCheckboxes(); + StateHasChanged(); + } + + async void OnSaveClicked() + { + if(_unknownName) + _model.Name = null; + else if(string.IsNullOrWhiteSpace(_model.Name)) + return; + + if(_unknownVersion) + _model.Version = null; + else if(string.IsNullOrWhiteSpace(_model.Version)) + return; + + if(_unknownPartNumber) + _model.PartNumber = null; + else if(string.IsNullOrWhiteSpace(_model.PartNumber)) + return; + + if(_unknownSerialNumber) + _model.SerialNumber = null; + else if(string.IsNullOrWhiteSpace(_model.SerialNumber)) + return; + + if(_unknownProductCode) + _model.ProductCode = null; + else if(string.IsNullOrWhiteSpace(_model.ProductCode)) + return; + + if(_unknownCatalogueNumber) + _model.CatalogueNumber = null; + else if(string.IsNullOrWhiteSpace(_model.CatalogueNumber)) + return; + + if(_unknownParent) + _model.ParentId = null; + else if(_model.ParentId < 1) + return; + + if(_unknownIntroduced) + _model.Introduced = null; + else if(_model.Introduced?.Date >= DateTime.UtcNow.Date) + return; + + if(_creating) + Id = await Service.CreateAsync(_model, (await UserManager.GetUserAsync(_authState.User)).Id); + else + await Service.UpdateAsync(_model, (await UserManager.GetUserAsync(_authState.User)).Id); + + _editing = false; + _creating = false; + _model = await Service.GetAsync(Id); + SetCheckboxes(); + StateHasChanged(); + } + + void ValidateName(ValidatorEventArgs e) => + Validators.ValidateString(e, L["Name must be smaller than 256 characters."], 256); + + void ValidateVersion(ValidatorEventArgs e) => + Validators.ValidateString(e, L["Version must be smaller than 256 characters."], 256); + + void ValidatePartNumber(ValidatorEventArgs e) => + Validators.ValidateString(e, L["Part number must be smaller than 256 characters."], 256); + + void ValidateSerialNumber(ValidatorEventArgs e) => + Validators.ValidateString(e, L["Serial number must be smaller than 256 characters."], 256); + + void ValidateProductCode(ValidatorEventArgs e) => + Validators.ValidateString(e, L["Product number must be smaller than 256 characters."], 256); + + void ValidateCatalogueNumber(ValidatorEventArgs e) => + Validators.ValidateString(e, L["Catalogue number must be smaller than 256 characters."], 256); + + void ValidateIntroduced(ValidatorEventArgs e) => Validators.ValidateDate(e); + + void ValidateUnsignedLongBiggerThanZero(ValidatorEventArgs e) => Validators.ValidateUnsignedLong(e); + } +} \ No newline at end of file diff --git a/Marechai/Pages/Admin/Index.razor b/Marechai/Pages/Admin/Index.razor index 4c80d9d2..83cf97fe 100644 --- a/Marechai/Pages/Admin/Index.razor +++ b/Marechai/Pages/Admin/Index.razor @@ -137,5 +137,8 @@
  • @L["Software versions"]
  • +
  • + @L["Software variants"] +
  • diff --git a/Marechai/Pages/Admin/SoftwareVariants.razor b/Marechai/Pages/Admin/SoftwareVariants.razor new file mode 100644 index 00000000..5f9487aa --- /dev/null +++ b/Marechai/Pages/Admin/SoftwareVariants.razor @@ -0,0 +1,110 @@ +@{ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Author(s) : Natalia Portillo +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2020 Natalia Portillo +*******************************************************************************/ +} + +@page "/admin/software_variants" +@using Marechai.Database.Models +@inherits OwningComponentBase +@inject IStringLocalizer L +@inject Microsoft.AspNetCore.Identity.UserManager UserManager +@inject AuthenticationStateProvider AuthenticationStateProvider +@attribute [Authorize(Roles = "UberAdmin, Admin")] +

    @L["Software variants"]

    +@if (_softwareVariants is null) +{ +

    @L["Loading..."]

    + + return; +} +

    + @L["Create new"] +

    + + + + + + + + + + + + + @foreach (var item in _softwareVariants) + { + + + + + + + + + } + +
    + @L["Family"] + + @L["Software version"] + + @L["Name"] + + @L["Version"] + + @L["Introduced"] +
    + @item.Family + + @item.SoftwareVersion + + @item.Name + + @item.Version + + @($"{item.Introduced:d}") + + @L["Details"] + @L["Edit"] + +
    + + + + + + @L["Delete software variant"] + + + + @string.Format(@L["Are you sure you want to delete the software variant {0}?"], _currentSoftwareVariant?.Name ?? _currentSoftwareVariant?.Version) + + + + + + + diff --git a/Marechai/Pages/Admin/SoftwareVariants.razor.cs b/Marechai/Pages/Admin/SoftwareVariants.razor.cs new file mode 100644 index 00000000..9e7c3059 --- /dev/null +++ b/Marechai/Pages/Admin/SoftwareVariants.razor.cs @@ -0,0 +1,88 @@ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Author(s) : Natalia Portillo +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2020 Natalia Portillo +*******************************************************************************/ + +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Blazorise; +using Marechai.ViewModels; +using Microsoft.AspNetCore.Components.Authorization; + +namespace Marechai.Pages.Admin +{ + public partial class SoftwareVariants + { + SoftwareVariantViewModel _currentSoftwareVariant; + bool _deleteInProgress; + Modal _frmDelete; + bool _loaded; + List _softwareVariants; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if(_loaded) + return; + + _softwareVariants = await Service.GetAsync(); + _loaded = true; + StateHasChanged(); + } + + void ShowModal(ulong itemId) + { + _currentSoftwareVariant = _softwareVariants.FirstOrDefault(n => n.Id == itemId); + _frmDelete.Show(); + } + + void HideModal() => _frmDelete.Hide(); + + async void ConfirmDelete() + { + if(_currentSoftwareVariant is null) + return; + + _deleteInProgress = true; + _softwareVariants = null; + AuthenticationState authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + + // Yield thread to let UI to update + await Task.Yield(); + + await Service.DeleteAsync(_currentSoftwareVariant.Id, (await UserManager.GetUserAsync(authState.User)).Id); + _softwareVariants = await Service.GetAsync(); + + _deleteInProgress = false; + _frmDelete.Hide(); + + // Yield thread to let UI to update + await Task.Yield(); + + // Tell we finished loading + StateHasChanged(); + } + + void ModalClosing(ModalClosingEventArgs obj) => _currentSoftwareVariant = null; + } +} \ No newline at end of file diff --git a/Marechai/Resources/Services/AdminService.en.resx b/Marechai/Resources/Services/AdminService.en.resx index 838eee51..c4c8ac57 100644 --- a/Marechai/Resources/Services/AdminService.en.resx +++ b/Marechai/Resources/Services/AdminService.en.resx @@ -47,4 +47,7 @@ Software versions + + Software variants + \ No newline at end of file diff --git a/Marechai/Resources/Services/AdminService.es.resx b/Marechai/Resources/Services/AdminService.es.resx index 0a98252d..d1bbcc63 100644 --- a/Marechai/Resources/Services/AdminService.es.resx +++ b/Marechai/Resources/Services/AdminService.es.resx @@ -246,4 +246,7 @@ Versiones de software + + Variantes de software + \ No newline at end of file diff --git a/Marechai/Resources/Services/SoftwareVariantsService.en.resx b/Marechai/Resources/Services/SoftwareVariantsService.en.resx new file mode 100644 index 00000000..17d040cc --- /dev/null +++ b/Marechai/Resources/Services/SoftwareVariantsService.en.resx @@ -0,0 +1,182 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Catalogue number must be smaller than 256 characters. + + + Product code must be smaller than 256 characters. + + + Serial number must be smaller than 256 characters. + + + Part number must be smaller than 256 characters. + + + Version must be smaller than 256 characters. + + + Name must be smaller than 256 characters. + + + Back to list + + + Cancel + + + Save + + + Edit + + + Distribution mode + + + Please enter a valid catalogue number. + + + Unknown + + + Catalogue number + + + Please enter a valid product code. + + + Unknown + + + Product code + + + Please enter a valid serial number. + + + Serial number is NOT the serial number used to install the software, but a serial number some software manufacturers use as SKU. + + + Unknown + + + Serial number + + + Please enter a valid part number. + + + Unknown + + + Part number + + + Please enter the required storage size in bytes. + + + Unknown + + + Required storage (bytes) + + + Please enter the recommended memory size in bytes. + + + Unknown + + + Recommended memory (bytes) + + + Please enter the minimum memory size in bytes. + + + Unknown + + + Minimum memory (bytes) + + + Unknown or none + + + Parent + + + Please enter a valid introduction date. + + + Unknown + + + Introduced + + + Please enter a valid version. + + + Unknown + + + Version, if different from software version's + + + Please enter a valid name. + + + Unknown + + + Name, if different from software version name + + + Software version + + + Software variant details + + + Are you sure you want to delete the software variant {0}? + + + Delete software variant + + + Delete + + + Details + + + Version + + + Name + + + Family + + + Create new + + + Loading... + + + Software variants + + \ No newline at end of file diff --git a/Marechai/Resources/Services/SoftwareVariantsService.es.resx b/Marechai/Resources/Services/SoftwareVariantsService.es.resx new file mode 100644 index 00000000..ef7f6375 --- /dev/null +++ b/Marechai/Resources/Services/SoftwareVariantsService.es.resx @@ -0,0 +1,289 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + El número de catálogo debe contener menos de 256 caracteres. + + + El código de producto debe contener menos de 256 caracteres. + + + El número de serie debe contener menos de 256 caracteres. + + + El número de pieza debe contener menos de 256 caracteres. + + + La versión debe contener menos de 256 caracteres. + + + El nombre debe contener menos de 256 caracteres. + + + Volver a la lista + + + Cancelar + + + Guardar + + + Editar + + + Modo de distribución + + + Por favor introduce un número de catálogo válido. + + + Desconocido + + + Número de catálogo + + + Por favor introduce un código de producto válido. + + + Desconocido + + + Código de producto + + + Por favor introduce un número de serie válido. + + + El número de serie NO ES el número de serie utilizado para instalar el software, sino un número de serie algunos fabricantes usan como inventario. + + + Desconocido + + + Número de serie + + + Por favor introduce un número de pieza válido. + + + Desconocido + + + Número de pieza + + + Por favor introduce el tamaño de almacenamiento requerido en bytes. + + + Desconocido + + + Tamaño de almacenamiento requerido (bytes) + + + Por favor introduce la memoria recomendada en bytes. + + + Desconocida + + + Memoria recomendada (bytes) + + + Por favor introduce la memoria mínima en bytes. + + + Desconocida + + + Memoria mínima (bytes) + + + Desconocida o ninguna + + + Predecesora + + + Por favor introduce una fecha de introducción válida. + + + Desconocida + + + Introducida + + + Por favor introduce una versión válida. + + + Desconocida + + + Versión, si es diferente de la versión de software + + + Por favor introduce un nombre válido. + + + Desconocido + + + Nombre, si es diferente del nombre de la versión de software + + + Versión de software + + + Detalles de variante de software + + + ¿Estás seguro de eliminar la variante de software {0}? + + + Eliminar variante de software + + + Eliminar + + + Detalles + + + Versión + + + Nombre + + + Familia + + + Crear nueva + + + Cargando... + + + Variantes de software + + \ No newline at end of file diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs index e1bc1566..ff78ffc5 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -78,6 +78,7 @@ namespace Marechai.Services services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Marechai/Services/SoftwareVariantsService.cs b/Marechai/Services/SoftwareVariantsService.cs new file mode 100644 index 00000000..b2a502d1 --- /dev/null +++ b/Marechai/Services/SoftwareVariantsService.cs @@ -0,0 +1,156 @@ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Author(s) : Natalia Portillo +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2020 Natalia Portillo +*******************************************************************************/ + +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 SoftwareVariantsService + { + readonly MarechaiContext _context; + + public SoftwareVariantsService(MarechaiContext context) => _context = context; + + public async Task> GetAsync() => await _context. + SoftwareVariants. + OrderBy(b => b.SoftwareVersion.Family. + Name). + ThenBy(b => b.SoftwareVersion.Version). + ThenBy(b => b.Name). + ThenBy(b => b.Version). + ThenBy(b => b.Introduced). + Select(b => new SoftwareVariantViewModel + { + Id = b.Id, + Name = b.Name, + Version = b.Version, + Introduced = b.Introduced, + ParentId = b.ParentId, + Parent = + b.Parent.Name ?? b.Parent.Version, + SoftwareVersionId = + b.SoftwareVersionId, + SoftwareVersion = + b.SoftwareVersion.Name ?? + b.SoftwareVersion.Version, + MinimumMemory = b.MinimumMemory, + RecommendedMemory = + b.RecommendedMemory, + RequiredStorage = b.RequiredStorage, + PartNumber = b.PartNumber, + SerialNumber = b.SerialNumber, + ProductCode = b.ProductCode, + CatalogueNumber = b.CatalogueNumber, + DistributionMode = b.DistributionMode + }).ToListAsync(); + + public async Task GetAsync(ulong id) => + await _context.SoftwareVariants.Where(b => b.Id == id).Select(b => new SoftwareVariantViewModel + { + Id = b.Id, + Name = b.Name, + Version = b.Version, + Introduced = b.Introduced, + ParentId = b.ParentId, + Parent = b.Parent.Name ?? b.Parent.Version, + SoftwareVersionId = b.SoftwareVersionId, + SoftwareVersion = b.SoftwareVersion.Name ?? b.SoftwareVersion.Version, + MinimumMemory = b.MinimumMemory, + RecommendedMemory = b.RecommendedMemory, + RequiredStorage = b.RequiredStorage, + PartNumber = b.PartNumber, + SerialNumber = b.SerialNumber, + ProductCode = b.ProductCode, + CatalogueNumber = b.CatalogueNumber, + DistributionMode = b.DistributionMode + }).FirstOrDefaultAsync(); + + public async Task UpdateAsync(SoftwareVariantViewModel viewModel, string userId) + { + SoftwareVariant model = await _context.SoftwareVariants.FindAsync(viewModel.Id); + + if(model is null) + return; + + model.Name = viewModel.Name; + model.Version = viewModel.Version; + model.Introduced = viewModel.Introduced; + model.ParentId = viewModel.ParentId; + model.SoftwareVersionId = viewModel.SoftwareVersionId; + model.MinimumMemory = viewModel.MinimumMemory; + model.RecommendedMemory = viewModel.RecommendedMemory; + model.RequiredStorage = viewModel.RequiredStorage; + model.PartNumber = viewModel.PartNumber; + model.SerialNumber = viewModel.SerialNumber; + model.ProductCode = viewModel.ProductCode; + model.CatalogueNumber = viewModel.CatalogueNumber; + model.DistributionMode = viewModel.DistributionMode; + + await _context.SaveChangesWithUserAsync(userId); + } + + public async Task CreateAsync(SoftwareVariantViewModel viewModel, string userId) + { + var model = new SoftwareVariant + { + Name = viewModel.Name, + Version = viewModel.Version, + Introduced = viewModel.Introduced, + ParentId = viewModel.ParentId, + SoftwareVersionId = viewModel.SoftwareVersionId, + MinimumMemory = viewModel.MinimumMemory, + RecommendedMemory = viewModel.RecommendedMemory, + RequiredStorage = viewModel.RequiredStorage, + PartNumber = viewModel.PartNumber, + SerialNumber = viewModel.SerialNumber, + ProductCode = viewModel.ProductCode, + CatalogueNumber = viewModel.CatalogueNumber, + DistributionMode = viewModel.DistributionMode + }; + + await _context.SoftwareVariants.AddAsync(model); + await _context.SaveChangesWithUserAsync(userId); + + return model.Id; + } + + public async Task DeleteAsync(ulong id, string userId) + { + SoftwareVariant item = await _context.SoftwareVariants.FindAsync(id); + + if(item is null) + return; + + _context.SoftwareVariants.Remove(item); + + await _context.SaveChangesWithUserAsync(userId); + } + } +} \ No newline at end of file diff --git a/Marechai/Shared/Validators.cs b/Marechai/Shared/Validators.cs index 74b84569..52b77dc5 100644 --- a/Marechai/Shared/Validators.cs +++ b/Marechai/Shared/Validators.cs @@ -249,5 +249,16 @@ namespace Marechai.Shared else if(modulo == issn[7] - 0x30) e.Status = ValidationStatus.Success; } + + public static void ValidateUnsignedLong(ValidatorEventArgs e, ulong minValue = 0, + ulong maxValue = long.MaxValue) + { + if(!(e.Value is ulong item) || + item < minValue || + item > maxValue) + e.Status = ValidationStatus.Error; + else + e.Status = ValidationStatus.Success; + } } } \ No newline at end of file diff --git a/Marechai/ViewModels/SoftwareVariantViewModel.cs b/Marechai/ViewModels/SoftwareVariantViewModel.cs new file mode 100644 index 00000000..92f7116b --- /dev/null +++ b/Marechai/ViewModels/SoftwareVariantViewModel.cs @@ -0,0 +1,50 @@ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Author(s) : Natalia Portillo +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2020 Natalia Portillo +*******************************************************************************/ + +using System; +using Marechai.Database; + +namespace Marechai.ViewModels +{ + public class SoftwareVariantViewModel : BaseViewModel + { + public string Name { get; set; } + public string Version { get; set; } + public DateTime? Introduced { get; set; } + public ulong? ParentId { get; set; } + public string Parent { get; set; } + public ulong SoftwareVersionId { get; set; } + public string SoftwareVersion { get; set; } + public ulong? MinimumMemory { get; set; } + public ulong? RecommendedMemory { get; set; } + public ulong? RequiredStorage { get; set; } + public string PartNumber { get; set; } + public string SerialNumber { get; set; } + public string ProductCode { get; set; } + public string CatalogueNumber { get; set; } + public DistributionMode DistributionMode { get; set; } + public string Family { get; set; } + } +} \ No newline at end of file