diff --git a/Marechai.Database/Models/CurrencyInflation.cs b/Marechai.Database/Models/CurrencyInflation.cs index 5fd8ee67..306cd283 100644 --- a/Marechai.Database/Models/CurrencyInflation.cs +++ b/Marechai.Database/Models/CurrencyInflation.cs @@ -31,7 +31,8 @@ namespace Marechai.Database.Models { [Required] public virtual Iso4217 Currency { get; set; } - public uint Year { get; set; } - public float Inflation { get; set; } + public uint Year { get; set; } + public float Inflation { get; set; } + public string CurrencyCode { get; set; } } } \ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 51df85de..8cf49d82 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 4.0.0.1792 + 4.0.0.1800 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website diff --git a/Marechai/Pages/Admin/CurrencyInflation.razor b/Marechai/Pages/Admin/CurrencyInflation.razor new file mode 100644 index 00000000..52708628 --- /dev/null +++ b/Marechai/Pages/Admin/CurrencyInflation.razor @@ -0,0 +1,98 @@ +@{ +/****************************************************************************** +// 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/currency_inflation" +@using Marechai.Database.Models +@inherits OwningComponentBase +@inject IStringLocalizer L +@inject Microsoft.AspNetCore.Identity.UserManager UserManager +@inject AuthenticationStateProvider AuthenticationStateProvider +@attribute [Authorize(Roles = "UberAdmin, Admin")] +

@L["Currency inflation"]

+@if (_inflations is null) +{ +

@L["Loading..."]

+ + return; +} +

+ @L["Create new"] +

+ + + + + + + + + + + @foreach (var item in _inflations) + { + + + + + + + } + +
+ @L["Currency"] + + @L["Year"] + + @L["Inflation"] +
+ @item.CurrencyName + + @item.Year + + @($"{item.Inflation:F2}") + + @L["Details"] + @L["Edit"] + +
+ + + + + + @L["Delete currency inflation"] + + + + @string.Format(@L["Are you sure you want to delete the inflation of {0:F} happened to currency {1} on {2}?"], _currentInflation?.Inflation, _currentInflation?.CurrencyName, _currentInflation?.Year) + + + + + + + diff --git a/Marechai/Pages/Admin/CurrencyInflation.razor.cs b/Marechai/Pages/Admin/CurrencyInflation.razor.cs new file mode 100644 index 00000000..9c1f62c7 --- /dev/null +++ b/Marechai/Pages/Admin/CurrencyInflation.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 CurrencyInflation + { + CurrencyInflationViewModel _currentInflation; + bool _deleteInProgress; + Modal _frmDelete; + List _inflations; + bool _loaded; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if(_loaded) + return; + + _inflations = await Service.GetAsync(); + _loaded = true; + StateHasChanged(); + } + + void ShowModal(long itemId) + { + _currentInflation = _inflations.FirstOrDefault(n => n.Id == itemId); + _frmDelete.Show(); + } + + void HideModal() => _frmDelete.Hide(); + + async void ConfirmDelete() + { + if(_currentInflation is null) + return; + + _deleteInProgress = true; + _inflations = null; + AuthenticationState authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + + // Yield thread to let UI to update + await Task.Yield(); + + await Service.DeleteAsync(_currentInflation.Id, (await UserManager.GetUserAsync(authState.User)).Id); + _inflations = 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) => _currentInflation = null; + } +} \ No newline at end of file diff --git a/Marechai/Pages/Admin/Details/CurrencyInflation.razor b/Marechai/Pages/Admin/Details/CurrencyInflation.razor new file mode 100644 index 00000000..f72e8f25 --- /dev/null +++ b/Marechai/Pages/Admin/Details/CurrencyInflation.razor @@ -0,0 +1,94 @@ +@{ +/****************************************************************************** +// 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/currency_inflation/details/{Id:int}" +@page "/admin/currency_inflation/edit/{Id:int}" +@page "/admin/currency_inflation/create" +@using Marechai.Database.Models +@inherits OwningComponentBase +@inject IStringLocalizer L +@inject Iso4217Service CurrenciesService +@inject NavigationManager NavigationManager +@inject IWebHostEnvironment Host +@inject Microsoft.AspNetCore.Identity.UserManager UserManager +@inject AuthenticationStateProvider AuthenticationStateProvider +@attribute [Authorize(Roles = "UberAdmin, Admin")] + + +

@L["Currency inflation details"]

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

@L["Loading..."]

+ + return; +} + +
+ + @L["Currency"] + + + + @L["Year"] + + + + @L["Please enter a valid year."] + + + + + + @L["Inflation (ratio)"] + + + + @L["Please enter a valid inflation."] + + + + +
+
+ @if (!_editing) + { + + } + else + { + + + } + @L["Back to list"] +
diff --git a/Marechai/Pages/Admin/Details/CurrencyInflation.razor.cs b/Marechai/Pages/Admin/Details/CurrencyInflation.razor.cs new file mode 100644 index 00000000..9e43a23d --- /dev/null +++ b/Marechai/Pages/Admin/Details/CurrencyInflation.razor.cs @@ -0,0 +1,140 @@ +/****************************************************************************** +// 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.Models; +using Marechai.ViewModels; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Authorization; + +namespace Marechai.Pages.Admin.Details +{ + public partial class CurrencyInflation + { + AuthenticationState _authState; + bool _creating; + List _currencies; + bool _editing; + bool _loaded; + CurrencyInflationViewModel _model; + + [Parameter] + public int Id { get; set; } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if(_loaded) + return; + + _loaded = true; + + _creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). + StartsWith("admin/currency_inflation/create", + StringComparison.InvariantCulture); + + if(Id <= 0 && + !_creating) + return; + + _currencies = await CurrenciesService.GetAsync(); + _model = _creating ? new CurrencyInflationViewModel() : await Service.GetAsync(Id); + _authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + + _editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). + StartsWith("admin/currency_inflation/edit/", + StringComparison.InvariantCulture); + + StateHasChanged(); + } + + void OnEditClicked() + { + _editing = true; + StateHasChanged(); + } + + async void OnCancelClicked() + { + _editing = false; + + if(_creating) + { + NavigationManager.ToBaseRelativePath("admin/currency_inflation"); + + return; + } + + _model = await Service.GetAsync(Id); + StateHasChanged(); + } + + async void OnSaveClicked() + { + if(string.IsNullOrWhiteSpace(_model.CurrencyCode)) + return; + + if(_model.Year > DateTime.UtcNow.Year) + return; + + if(_model.Inflation == 0) + 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); + StateHasChanged(); + } + + void ValidateYear(ValidatorEventArgs e) + { + e.Status = ValidationStatus.Success; + + if((uint)e.Value <= DateTime.UtcNow.Year) + return; + + e.Status = ValidationStatus.Error; + e.ErrorText = L["Year must be before current one."]; + } + + void ValidateInflation(ValidatorEventArgs e) + { + e.Status = ValidationStatus.Success; + + if((float)e.Value != 0) + return; + + e.Status = ValidationStatus.Error; + e.ErrorText = L["Inflation must be bigger than 0."]; + } + } +} \ No newline at end of file diff --git a/Marechai/Pages/Admin/Index.razor b/Marechai/Pages/Admin/Index.razor index 98e0599b..b48cb8d6 100644 --- a/Marechai/Pages/Admin/Index.razor +++ b/Marechai/Pages/Admin/Index.razor @@ -99,4 +99,12 @@

@L["User administrative pages"]

-
\ No newline at end of file + +
+

@L["Administrative pages for currencies"]

+ +
diff --git a/Marechai/Resources/Services/AdminService.en.resx b/Marechai/Resources/Services/AdminService.en.resx index 2ace1d53..02ce3d05 100644 --- a/Marechai/Resources/Services/AdminService.en.resx +++ b/Marechai/Resources/Services/AdminService.en.resx @@ -14,4 +14,10 @@ Books + + Administrative pages for currencies + + + Currency inflation + \ No newline at end of file diff --git a/Marechai/Resources/Services/AdminService.es.resx b/Marechai/Resources/Services/AdminService.es.resx index 70163ca6..3c3e4b71 100644 --- a/Marechai/Resources/Services/AdminService.es.resx +++ b/Marechai/Resources/Services/AdminService.es.resx @@ -213,4 +213,10 @@ Libros + + Páginas de administración para divisas + + + Inflación de divisa + \ No newline at end of file diff --git a/Marechai/Resources/Services/CurrencyInflationService.en.resx b/Marechai/Resources/Services/CurrencyInflationService.en.resx new file mode 100644 index 00000000..cbd9c075 --- /dev/null +++ b/Marechai/Resources/Services/CurrencyInflationService.en.resx @@ -0,0 +1,74 @@ + + + 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 + + + Currency inflation + + + Create new + + + Loading... + + + Currency + + + Year + + + Inflation + + + Details + + + Edit + + + Delete + + + Delete currency inflation + + + Are you sure you want to delete the inflation of {0:F} happened to currency {1} on {2}? + + + Currency inflation details + + + Please enter a valid year. + + + Inflation (ratio) + + + Please enter a valid inflation. + + + Save + + + Cancel + + + Back to list + + + Year must be before current one. + + + Inflation must be different than 0. + + \ No newline at end of file diff --git a/Marechai/Resources/Services/CurrencyInflationService.es.resx b/Marechai/Resources/Services/CurrencyInflationService.es.resx new file mode 100644 index 00000000..751ea812 --- /dev/null +++ b/Marechai/Resources/Services/CurrencyInflationService.es.resx @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + Inflación de divisa + + + Cargando... + + + Crear nueva + + + Divisa + + + Año + + + Inflación + + + Detalles + + + Editar + + + Eliminar + + + Eliminar inflación de divisa + + + ¿Estás seguro de querer eliminar la inflación de {0:F} ocurrida a la divisa {2} en {3} + + + Detalles de inflación de divisa + + + Por favor introduce un año válido. + + + Inflación (relación) + + + Por favor introduce una inflación válida. + + + Guardar + + + Cancelar + + + Volver a la lista + + + El año debe ser anterior al actual. + + + La inflación debe ser distinta de 0. + + \ No newline at end of file diff --git a/Marechai/Services/CurrencyInflationService.cs b/Marechai/Services/CurrencyInflationService.cs new file mode 100644 index 00000000..289593bc --- /dev/null +++ b/Marechai/Services/CurrencyInflationService.cs @@ -0,0 +1,104 @@ +/****************************************************************************** +// 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 CurrencyInflationService + { + readonly MarechaiContext _context; + + public CurrencyInflationService(MarechaiContext context) => _context = context; + + public async Task> GetAsync() => await _context. + CurrenciesInflation. + OrderBy(i => i.Currency.Name). + ThenBy(i => i.Year). + Select(i => new CurrencyInflationViewModel + { + Id = i.Id, + CurrencyCode = i.Currency.Code, + CurrencyName = i.Currency.Name, + Year = i.Year, + Inflation = i.Inflation + }).ToListAsync(); + + public async Task GetAsync(int id) => + await _context.CurrenciesInflation.Where(b => b.Id == id).Select(i => new CurrencyInflationViewModel + { + Id = i.Id, + CurrencyCode = i.Currency.Code, + CurrencyName = i.Currency.Name, + Year = i.Year, + Inflation = i.Inflation + }).FirstOrDefaultAsync(); + + public async Task UpdateAsync(CurrencyInflationViewModel viewModel, string userId) + { + CurrencyInflation model = await _context.CurrenciesInflation.FindAsync(viewModel.Id); + + if(model is null) + return; + + model.CurrencyCode = viewModel.CurrencyCode; + model.Year = viewModel.Year; + model.Inflation = viewModel.Inflation; + await _context.SaveChangesWithUserAsync(userId); + } + + public async Task CreateAsync(CurrencyInflationViewModel viewModel, string userId) + { + var model = new CurrencyInflation + { + CurrencyCode = viewModel.CurrencyCode, + Year = viewModel.Year, + Inflation = viewModel.Inflation + }; + + await _context.CurrenciesInflation.AddAsync(model); + await _context.SaveChangesWithUserAsync(userId); + + return model.Id; + } + + public async Task DeleteAsync(int id, string userId) + { + CurrencyInflation item = await _context.CurrenciesInflation.FindAsync(id); + + if(item is null) + return; + + _context.CurrenciesInflation.Remove(item); + + await _context.SaveChangesWithUserAsync(userId); + } + } +} \ No newline at end of file diff --git a/Marechai/Services/Iso4217Service.cs b/Marechai/Services/Iso4217Service.cs new file mode 100644 index 00000000..e76db84c --- /dev/null +++ b/Marechai/Services/Iso4217Service.cs @@ -0,0 +1,42 @@ +/****************************************************************************** +// 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 Microsoft.EntityFrameworkCore; + +namespace Marechai.Services +{ + public class Iso4217Service + { + readonly MarechaiContext _context; + + public Iso4217Service(MarechaiContext context) => _context = context; + + public async Task> GetAsync() => await _context.Iso4217.OrderBy(c => c.Name).ToListAsync(); + } +} \ No newline at end of file diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs index 087bf2be..573c731a 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -68,6 +68,8 @@ namespace Marechai.Services services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Marechai/ViewModels/CurrencyInflationViewModel.cs b/Marechai/ViewModels/CurrencyInflationViewModel.cs new file mode 100644 index 00000000..3f4011a5 --- /dev/null +++ b/Marechai/ViewModels/CurrencyInflationViewModel.cs @@ -0,0 +1,35 @@ +/****************************************************************************** +// 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 +*******************************************************************************/ + +namespace Marechai.ViewModels +{ + public class CurrencyInflationViewModel : BaseViewModel + { + public string CurrencyCode { get; set; } + public string CurrencyName { get; set; } + public uint Year { get; set; } + public float Inflation { get; set; } + } +} \ No newline at end of file