From f24810e8089e875c3b0648855c8f677223c6d88f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 8 Aug 2020 17:53:00 +0100 Subject: [PATCH] Add magazine issues admin page. --- Marechai/Marechai.csproj | 2 +- .../Pages/Admin/Details/MagazineIssue.razor | 191 +++++++++++++++ .../Admin/Details/MagazineIssue.razor.cs | 172 +++++++++++++ Marechai/Pages/Admin/Index.razor | 3 + Marechai/Pages/Admin/MagazineIssues.razor | 98 ++++++++ Marechai/Pages/Admin/MagazineIssues.razor.cs | 88 +++++++ .../Resources/Services/AdminService.en.resx | 3 + .../Resources/Services/AdminService.es.resx | 3 + .../Resources/Services/MagazineIssues.en.resx | 122 ++++++++++ .../Resources/Services/MagazineIssues.es.resx | 229 ++++++++++++++++++ Marechai/Services/MagazineIssuesService.cs | 121 +++++++++ Marechai/Services/MagazinesService.cs | 9 + Marechai/Services/Register.cs | 1 + Marechai/ViewModels/MagazineIssueViewModel.cs | 41 ++++ 14 files changed, 1082 insertions(+), 1 deletion(-) create mode 100644 Marechai/Pages/Admin/Details/MagazineIssue.razor create mode 100644 Marechai/Pages/Admin/Details/MagazineIssue.razor.cs create mode 100644 Marechai/Pages/Admin/MagazineIssues.razor create mode 100644 Marechai/Pages/Admin/MagazineIssues.razor.cs create mode 100644 Marechai/Resources/Services/MagazineIssues.en.resx create mode 100644 Marechai/Resources/Services/MagazineIssues.es.resx create mode 100644 Marechai/Services/MagazineIssuesService.cs create mode 100644 Marechai/ViewModels/MagazineIssueViewModel.cs diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 635aaa54..fbd872e3 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 4.0.0.1809 + 4.0.0.1810 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website diff --git a/Marechai/Pages/Admin/Details/MagazineIssue.razor b/Marechai/Pages/Admin/Details/MagazineIssue.razor new file mode 100644 index 00000000..d6268f17 --- /dev/null +++ b/Marechai/Pages/Admin/Details/MagazineIssue.razor @@ -0,0 +1,191 @@ +@{ +/****************************************************************************** +// 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/magazine_issues/details/{Id:long}" +@page "/admin/magazine_issues/edit/{Id:long}" +@page "/admin/magazine_issues/create" +@using Marechai.Database +@using Marechai.Database.Models +@inherits OwningComponentBase +@inject IStringLocalizer L +@inject MagazinesService MagazinesService +@inject NavigationManager NavigationManager +@inject IWebHostEnvironment Host +@inject IJSRuntime JSRuntime +@inject Microsoft.AspNetCore.Identity.UserManager UserManager +@inject AuthenticationStateProvider AuthenticationStateProvider +@attribute [Authorize(Roles = "UberAdmin, Admin")] + + +

@L["Magazine issue details"]

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

@L["Loading..."]

+ + return; +} + +
+ + @L["Magazine"] + + + + @L["Caption using latin script"] + + + + @L["Please enter a valid caption."] + + + + + @if (_editing || _model.NativeCaption != null) + { + + @L["Native caption, that is, caption using native script (cyrillic, chinese, etc)"] + @if (_editing) + { + @L["Unknown (native caption)"] + } + @if (!_editing || + !_unknownNativeCaption) + { + + + + @L["Please enter a valid native caption."] + + + + } + + } + @if (_editing || _model.Published != null) + { + + @L["Published"] + @if (_editing) + { + @L["Unknown (publication date)"] + } + @if (!_editing || !_unknownPublished) + { + @L["If the date of exact publication is unknown, set as first day of first month the publication applies to. E.g. July/August 1998 -> 1st July 1998"] + + + + @L["Please enter a valid publication date."] + + + + } + + } + @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.Pages.HasValue) + { + + @L["Pages"] + @if (_editing) + { + @L["Unknown (pages)"] + } + @if (!_editing || + !_unknownPages) + { + + + + @L["Please enter a valid number of pages."] + + + + } + + } + @if (_editing || _model.IssueNumber.HasValue) + { + + @L["Issue number"] + @if (_editing) + { + @L["Unknown (issue number)"] + } + @if (!_editing || + !_unknownIssueNumber) + { + + + + @L["Please enter a valid issue number."] + + + + } + + } +
+
+ @if (!_editing) + { + + } + else + { + + + } + @L["Back to list"] +
diff --git a/Marechai/Pages/Admin/Details/MagazineIssue.razor.cs b/Marechai/Pages/Admin/Details/MagazineIssue.razor.cs new file mode 100644 index 00000000..c2c3bb92 --- /dev/null +++ b/Marechai/Pages/Admin/Details/MagazineIssue.razor.cs @@ -0,0 +1,172 @@ +/****************************************************************************** +// 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.Shared; +using Marechai.ViewModels; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Authorization; + +namespace Marechai.Pages.Admin.Details +{ + public partial class MagazineIssue + { + AuthenticationState _authState; + bool _creating; + bool _editing; + bool _loaded; + List _magazines; + MagazineIssueViewModel _model; + bool _unknownIssueNumber; + bool _unknownNativeCaption; + bool _unknownPages; + bool _unknownProductCode; + bool _unknownPublished; + + [Parameter] + public long Id { get; set; } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if(_loaded) + return; + + _loaded = true; + + _creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). + StartsWith("admin/magazine_issues/create", StringComparison.InvariantCulture); + + if(Id <= 0 && + !_creating) + return; + + _magazines = await MagazinesService.GetTitlesAsync(); + _model = _creating ? new MagazineIssueViewModel() : await Service.GetAsync(Id); + _authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + + _editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). + StartsWith("admin/magazine_issues/edit/", + StringComparison.InvariantCulture); + + if(_editing) + SetCheckboxes(); + + StateHasChanged(); + } + + void SetCheckboxes() + { + _unknownProductCode = string.IsNullOrWhiteSpace(_model.ProductCode); + _unknownIssueNumber = !_model.IssueNumber.HasValue; + _unknownNativeCaption = string.IsNullOrWhiteSpace(_model.NativeCaption); + _unknownPublished = !_model.Published.HasValue; + _unknownPages = !_model.Pages.HasValue; + } + + void OnEditClicked() + { + _editing = true; + SetCheckboxes(); + StateHasChanged(); + } + + async void OnCancelClicked() + { + _editing = false; + + if(_creating) + { + NavigationManager.ToBaseRelativePath("admin/magazine_issues"); + + return; + } + + _model = await Service.GetAsync(Id); + SetCheckboxes(); + StateHasChanged(); + } + + async void OnSaveClicked() + { + if(_unknownNativeCaption) + _model.NativeCaption = null; + else if(string.IsNullOrWhiteSpace(_model.NativeCaption)) + return; + + if(_unknownPages) + _model.Pages = null; + else if(_model.Pages < 1) + return; + + if(_unknownIssueNumber) + _model.IssueNumber = null; + else if(_model.IssueNumber < 1) + return; + + if(_unknownPublished) + _model.Published = null; + else if(_model.Published?.Date >= DateTime.UtcNow.Date) + return; + + // TODO: Recognize JAN-13, EAN-13, UPC, etc + if(_unknownProductCode) + _model.ProductCode = null; + else if(string.IsNullOrWhiteSpace(_model.ProductCode)) + return; + + if(string.IsNullOrWhiteSpace(_model.Caption)) + 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 ValidateCaption(ValidatorEventArgs e) => + Validators.ValidateString(e, L["Caption must be smaller than 256 characters."], 256); + + void ValidatePublished(ValidatorEventArgs e) => Validators.ValidateDate(e); + + void ValidateNativeCaption(ValidatorEventArgs e) => + Validators.ValidateString(e, L["Native caption must be smaller than 256 characters."], 256); + + void ValidatePages(ValidatorEventArgs e) => Validators.ValidateShort(e, 1); + + void ValidateIssueNumber(ValidatorEventArgs e) => Validators.ValidateInteger(e, 1); + + void ValidateProductCode(ValidatorEventArgs e) => + Validators.ValidateString(e, L["Product code must be smaller than 18 characters."], 18); + } +} \ No newline at end of file diff --git a/Marechai/Pages/Admin/Index.razor b/Marechai/Pages/Admin/Index.razor index 79bc977f..46122cb7 100644 --- a/Marechai/Pages/Admin/Index.razor +++ b/Marechai/Pages/Admin/Index.razor @@ -98,6 +98,9 @@
  • @L["Magazines"]
  • +
  • + @L["Magazine issues"] +
  • diff --git a/Marechai/Pages/Admin/MagazineIssues.razor b/Marechai/Pages/Admin/MagazineIssues.razor new file mode 100644 index 00000000..b1d168a1 --- /dev/null +++ b/Marechai/Pages/Admin/MagazineIssues.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/magazine_issues" +@using Marechai.Database.Models +@inherits OwningComponentBase +@inject IStringLocalizer L +@inject Microsoft.AspNetCore.Identity.UserManager UserManager +@inject AuthenticationStateProvider AuthenticationStateProvider +@attribute [Authorize(Roles = "UberAdmin, Admin")] +

    @L["Magazine issues"]

    +@if (_magazineIssues is null) +{ +

    @L["Loading..."]

    + + return; +} +

    + @L["Create new"] +

    + + + + + + + + + + + @foreach (var item in _magazineIssues) + { + + + + + + + } + +
    + @L["Magazine title"] + + @L["Published"] + + @L["Caption"] +
    + @item.MagazineTitle + + @($"{item.Published:d}") + + @item.Caption + + @L["Details"] + @L["Edit"] + +
    + + + + + + @L["Delete magazine issue"] + + + + @string.Format(@L["Are you sure you want to delete the magazine issue published on {0} for magazine {1} with caption {2}?"], _currentMagazineIssue?.Published,_currentMagazineIssue?.MagazineTitle,_currentMagazineIssue?.Caption) + + + + + + + diff --git a/Marechai/Pages/Admin/MagazineIssues.razor.cs b/Marechai/Pages/Admin/MagazineIssues.razor.cs new file mode 100644 index 00000000..a24d2afb --- /dev/null +++ b/Marechai/Pages/Admin/MagazineIssues.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 MagazineIssues + { + MagazineIssueViewModel _currentMagazineIssue; + bool _deleteInProgress; + Modal _frmDelete; + bool _loaded; + List _magazineIssues; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if(_loaded) + return; + + _magazineIssues = await Service.GetAsync(); + _loaded = true; + StateHasChanged(); + } + + void ShowModal(long itemId) + { + _currentMagazineIssue = _magazineIssues.FirstOrDefault(n => n.Id == itemId); + _frmDelete.Show(); + } + + void HideModal() => _frmDelete.Hide(); + + async void ConfirmDelete() + { + if(_currentMagazineIssue is null) + return; + + _deleteInProgress = true; + _magazineIssues = null; + AuthenticationState authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + + // Yield thread to let UI to update + await Task.Yield(); + + await Service.DeleteAsync(_currentMagazineIssue.Id, (await UserManager.GetUserAsync(authState.User)).Id); + _magazineIssues = 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) => _currentMagazineIssue = null; + } +} \ No newline at end of file diff --git a/Marechai/Resources/Services/AdminService.en.resx b/Marechai/Resources/Services/AdminService.en.resx index 7071bb6a..3dc4c31d 100644 --- a/Marechai/Resources/Services/AdminService.en.resx +++ b/Marechai/Resources/Services/AdminService.en.resx @@ -35,4 +35,7 @@ Documents + + Magazine issues + \ No newline at end of file diff --git a/Marechai/Resources/Services/AdminService.es.resx b/Marechai/Resources/Services/AdminService.es.resx index 233d4465..1c68a604 100644 --- a/Marechai/Resources/Services/AdminService.es.resx +++ b/Marechai/Resources/Services/AdminService.es.resx @@ -234,4 +234,7 @@ Documentos + + Números de revistas + \ No newline at end of file diff --git a/Marechai/Resources/Services/MagazineIssues.en.resx b/Marechai/Resources/Services/MagazineIssues.en.resx new file mode 100644 index 00000000..c10e611f --- /dev/null +++ b/Marechai/Resources/Services/MagazineIssues.en.resx @@ -0,0 +1,122 @@ + + + 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 + + + Magazine issues + + + Loading... + + + Create new + + + Magazine title + + + Published + + + Caption + + + Details + + + Edit + + + Delete + + + Delete magazine issue + + + Are you sure you want to delete the magazine issue published on {0} for magazine {1} with caption {2}? + + + Cancel + + + Magazine issue details + + + Magazine + + + Caption using latin script + + + Please enter a valid caption. + + + Native caption, that is, caption using native script (cyrillic, chinese, etc) + + + Unknown + + + Please enter a valid native caption. + + + Unknown + + + If the date of exact publication is unknown, set as first day of first month the publication applies to. E.g. July/August 1998 -> 1st July 1998 + + + Please enter a valid publication date. + + + Product code + + + Unknown + + + Please enter a valid product code. + + + Pages + + + Unknown + + + Please enter a valid number of pages. + + + Issue number + + + Unknown + + + Please enter a valid issue number. + + + Save + + + Back to list + + + Caption must be smaller than 256 characters. + + + Product code must be smaller than 18 characters. + + + Native caption must be smaller than 256 characters. + + \ No newline at end of file diff --git a/Marechai/Resources/Services/MagazineIssues.es.resx b/Marechai/Resources/Services/MagazineIssues.es.resx new file mode 100644 index 00000000..f95c633f --- /dev/null +++ b/Marechai/Resources/Services/MagazineIssues.es.resx @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + Números de revista + + + Cargando... + + + Crear nuevo + + + Título de la revista + + + Publicación + + + Portada + + + Detalles + + + Editar + + + Eliminar + + + Eliminar número de revista + + + ¿Estás seguro de eliminar el número de la revista {1} publicado el {0} con la portada {2}? + + + Cancelar + + + Detalles de número de revista + + + Revista + + + Portada usando escritura latina + + + Por favor introduce un texto de portada válido. + + + Portada nativa, es decir, el text de portada usando escritura nativa (cirílico, chino, etc) + + + Desconocido + + + Por favor introduce un texto de portada nativo válido. + + + Desconocida + + + Si la fecha exacta de la publicación es desconocida, poner como el primer día del mes al que se aplica la publicación. Ej.: Julio/Agosto 1998 -> 1 de Agosto de 1998 + + + Por favor introduce una fecha de publicación válida. + + + Código de producto + + + Desconocido + + + Por favor introduce un código de producto válido. + + + Páginas + + + Desconocido + + + Por favor introduce un número de páginas válido. + + + Número de publicación + + + Desconocido + + + Por favor introduce un número de publicación válido. + + + Guardar + + + Volver a la lista + + + El texto de la portada debe contener menos de 256 caracteres. + + + La portada nativa debe contener menos de 256 caracteres. + + + El código de producto debe contener menos de 18 caracteres. + + \ No newline at end of file diff --git a/Marechai/Services/MagazineIssuesService.cs b/Marechai/Services/MagazineIssuesService.cs new file mode 100644 index 00000000..c7611cd9 --- /dev/null +++ b/Marechai/Services/MagazineIssuesService.cs @@ -0,0 +1,121 @@ +/****************************************************************************** +// 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 MagazineIssuesService + { + readonly MarechaiContext _context; + + public MagazineIssuesService(MarechaiContext context) => _context = context; + + public async Task> GetAsync() => await _context. + MagazineIssues. + OrderBy(b => b.Magazine.Title). + ThenBy(b => b.Published). + ThenBy(b => b.Caption). + Select(b => new MagazineIssueViewModel + { + Id = b.Id, + MagazineId = b.MagazineId, + MagazineTitle = b.Magazine.Title, + Caption = b.Caption, + NativeCaption = b.NativeCaption, + Published = b.Published, + ProductCode = b.ProductCode, + Pages = b.Pages, + IssueNumber = b.IssueNumber + }).ToListAsync(); + + public async Task GetAsync(long id) => + await _context.MagazineIssues.Where(b => b.Id == id).Select(b => new MagazineIssueViewModel + { + Id = b.Id, + MagazineId = b.MagazineId, + MagazineTitle = b.Magazine.Title, + Caption = b.Caption, + NativeCaption = b.NativeCaption, + Published = b.Published, + ProductCode = b.ProductCode, + Pages = b.Pages, + IssueNumber = b.IssueNumber + }).FirstOrDefaultAsync(); + + public async Task UpdateAsync(MagazineIssueViewModel viewModel, string userId) + { + MagazineIssue model = await _context.MagazineIssues.FindAsync(viewModel.Id); + + if(model is null) + return; + + model.MagazineId = viewModel.MagazineId; + model.Caption = viewModel.Caption; + model.NativeCaption = viewModel.NativeCaption; + model.Published = viewModel.Published; + model.ProductCode = viewModel.ProductCode; + model.Pages = viewModel.Pages; + model.IssueNumber = viewModel.IssueNumber; + await _context.SaveChangesWithUserAsync(userId); + } + + public async Task CreateAsync(MagazineIssueViewModel viewModel, string userId) + { + var model = new MagazineIssue + { + MagazineId = viewModel.MagazineId, + Caption = viewModel.Caption, + NativeCaption = viewModel.NativeCaption, + Published = viewModel.Published, + ProductCode = viewModel.ProductCode, + Pages = viewModel.Pages, + IssueNumber = viewModel.IssueNumber + }; + + await _context.MagazineIssues.AddAsync(model); + await _context.SaveChangesWithUserAsync(userId); + + return model.Id; + } + + public async Task DeleteAsync(long id, string userId) + { + MagazineIssue item = await _context.MagazineIssues.FindAsync(id); + + if(item is null) + return; + + _context.MagazineIssues.Remove(item); + + await _context.SaveChangesWithUserAsync(userId); + } + } +} \ No newline at end of file diff --git a/Marechai/Services/MagazinesService.cs b/Marechai/Services/MagazinesService.cs index 33678bda..c36bb318 100644 --- a/Marechai/Services/MagazinesService.cs +++ b/Marechai/Services/MagazinesService.cs @@ -54,6 +54,15 @@ namespace Marechai.Services Country = b.Country.Name }).ToListAsync(); + public async Task> GetTitlesAsync() => await _context. + Magazines.OrderBy(b => b.Title). + ThenBy(b => b.FirstPublication). + Select(b => new MagazineViewModel + { + Id = b.Id, + Title = $"{b.Title} ({b.Country.Name}" + }).ToListAsync(); + public async Task GetAsync(long id) => await _context.Magazines.Where(b => b.Id == id). Select(b => new MagazineViewModel { diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs index 19365a1d..d8523822 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -75,6 +75,7 @@ namespace Marechai.Services services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Marechai/ViewModels/MagazineIssueViewModel.cs b/Marechai/ViewModels/MagazineIssueViewModel.cs new file mode 100644 index 00000000..471ef312 --- /dev/null +++ b/Marechai/ViewModels/MagazineIssueViewModel.cs @@ -0,0 +1,41 @@ +/****************************************************************************** +// 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; + +namespace Marechai.ViewModels +{ + public class MagazineIssueViewModel : BaseViewModel + { + public long MagazineId { get; set; } + public string MagazineTitle { get; set; } + public string Caption { get; set; } + public string NativeCaption { get; set; } + public DateTime? Published { get; set; } + public string ProductCode { get; set; } + public short? Pages { get; set; } + public uint? IssueNumber { get; set; } + } +} \ No newline at end of file