Add magazines admin page.

This commit is contained in:
2020-08-08 14:30:04 +01:00
parent a1249878e8
commit ce99d8a184
14 changed files with 939 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Exiftool/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=flif/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=heif/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ISSN/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=kibibytes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Marechai/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Portillo/@EntryIndexedValue">True</s:Boolean>

View File

@@ -0,0 +1,159 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
}
@page "/admin/magazines/details/{Id:long}"
@page "/admin/magazines/edit/{Id:long}"
@page "/admin/magazines/create"
@using Marechai.Database
@using Marechai.Database.Models
@inherits OwningComponentBase<MagazinesService>
@inject IStringLocalizer<MagazinesService> L
@inject Iso31661NumericService CountriesService
@inject NavigationManager NavigationManager
@inject IWebHostEnvironment Host
@inject IJSRuntime JSRuntime
@inject Microsoft.AspNetCore.Identity.UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Magazine details"]</h3>
<hr />
@if (!_loaded)
{
<p align="center">@L["Loading..."]</p>
return;
}
<div>
<Field>
<FieldLabel>@L["Title using latin script"]</FieldLabel>
<Validation Validator="@ValidateTitle">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Title">
<Feedback>
<ValidationError>@L["Please enter a valid title."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
</Field>
@if (_editing || _model.NativeTitle != null)
{
<Field>
<FieldLabel>@L["Native title, that is, title using native script (cyrillic, chinese, etc)"]</FieldLabel>
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownNativeTitle">@L["Unknown (native title)"]</Check>
}
@if (!_editing ||
!_unknownNativeTitle)
{
<Validation Validator="@ValidateNativeTitle">
<TextEdit Disabled="!_editing" @bind-Text="@_model.NativeTitle">
<Feedback>
<ValidationError>@L["Please enter a valid native title."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
@if (_editing || _model.FirstPublication != null)
{
<Field>
<FieldLabel>@L["First publication"]</FieldLabel>
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownFirstPublication">@L["Unknown (first publication date)"]</Check>
}
@if (!_editing || !_unknownFirstPublication)
{
<Validation Validator="@ValidateFirstPublication">
<DateEdit TValue="DateTime?" ReadOnly="!_editing" @bind-Date="@_model.FirstPublication" >
<Feedback>
<ValidationError>@L["Please enter a valid first publication date."]</ValidationError>
</Feedback>
</DateEdit>
</Validation>
}
</Field>
}
@if (_editing || _model.CountryId != null)
{
<Field>
<FieldLabel>@L["Country of publication"]</FieldLabel>
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownCountry">@L["Unknown (country of publication)"]</Check>
}
@if (!_editing ||
!_unknownCountry)
{
<Select Disabled="!_editing" TValue="short?" @bind-SelectedValue="@_model.CountryId">
@foreach (var country in _countries)
{
<SelectItem TValue="short?" Value="@country.Id">@country.Name</SelectItem>
}
</Select>
}
</Field>
}
@if (_editing || _model.Issn != null)
{
<Field>
<FieldLabel>@L["ISSN"]</FieldLabel>
@if (_editing)
{
<Check TValue="bool" @bind-Checked="@_unknownIssn">@L["Unknown (ISSN)"]</Check>
}
@if (!_editing ||
!_unknownIssn)
{
<Validation Validator="@ValidateIssn">
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Issn">
<Feedback>
<ValidationError>@L["Please enter a valid ISSN."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
</div>
<div>
@if (!_editing)
{
<Button Color="Color.Primary" Clicked="@OnEditClicked">@L["Edit"]</Button>
}
else
{
<Button Color="Color.Success" Clicked="@OnSaveClicked">@L["Save"]</Button>
<Button Color="Color.Danger" Clicked="@OnCancelClicked">@L["Cancel"]</Button>
}
<a href="/admin/magazines" class="btn btn-secondary">@L["Back to list"]</a>
</div>

View File

@@ -0,0 +1,160 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Blazorise;
using Marechai.Database.Models;
using Marechai.Shared;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
namespace Marechai.Pages.Admin.Details
{
public partial class Magazine
{
AuthenticationState _authState;
List<Iso31661Numeric> _countries;
bool _creating;
bool _editing;
bool _loaded;
MagazineViewModel _model;
bool _unknownCountry;
bool _unknownFirstPublication;
bool _unknownIssn;
bool _unknownNativeTitle;
[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/magazines/create", StringComparison.InvariantCulture);
if(Id <= 0 &&
!_creating)
return;
_countries = await CountriesService.GetAsync();
_model = _creating ? new MagazineViewModel() : await Service.GetAsync(Id);
_authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
StartsWith("admin/magazines/edit/",
StringComparison.InvariantCulture);
if(_editing)
SetCheckboxes();
StateHasChanged();
}
void SetCheckboxes()
{
_unknownCountry = !_model.CountryId.HasValue;
_unknownNativeTitle = string.IsNullOrWhiteSpace(_model.NativeTitle);
_unknownFirstPublication = !_model.FirstPublication.HasValue;
_unknownIssn = string.IsNullOrWhiteSpace(_model.Issn);
}
void OnEditClicked()
{
_editing = true;
SetCheckboxes();
StateHasChanged();
}
async void OnCancelClicked()
{
_editing = false;
if(_creating)
{
NavigationManager.ToBaseRelativePath("admin/magazines");
return;
}
_model = await Service.GetAsync(Id);
SetCheckboxes();
StateHasChanged();
}
async void OnSaveClicked()
{
if(_unknownNativeTitle)
_model.NativeTitle = null;
else if(string.IsNullOrWhiteSpace(_model.NativeTitle))
return;
if(_unknownCountry)
_model.CountryId = null;
else if(_model.CountryId < 0)
return;
if(_unknownFirstPublication)
_model.FirstPublication = null;
else if(_model.FirstPublication?.Date >= DateTime.UtcNow.Date)
return;
if(_unknownIssn)
_model.Issn = null;
else if(string.IsNullOrWhiteSpace(_model.Issn))
return;
if(string.IsNullOrWhiteSpace(_model.Title))
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 ValidateTitle(ValidatorEventArgs e) =>
Validators.ValidateString(e, L["Title must be smaller than 256 characters."], 256);
void ValidateFirstPublication(ValidatorEventArgs e) => Validators.ValidateDate(e);
void ValidateNativeTitle(ValidatorEventArgs e) =>
Validators.ValidateString(e, L["Native title must be smaller than 256 characters."], 256);
void ValidateIssn(ValidatorEventArgs e) => Validators.ValidateIssn(e);
}
}

View File

@@ -92,6 +92,12 @@
<li>
<a href="/admin/books">@L["Books"]</a>
</li>
<li>
<a href="/admin/documents">@L["Documents"]</a>
</li>
<li>
<a href="/admin/magazines">@L["Magazines"]</a>
</li>
</ul>
</div>
<div class="content">

View File

@@ -0,0 +1,110 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
}
@page "/admin/magazines"
@using Marechai.Database.Models
@inherits OwningComponentBase<MagazinesService>
@inject IStringLocalizer<MagazinesService> L
@inject Microsoft.AspNetCore.Identity.UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Magazines"]</h3>
@if (_magazines is null)
{
<p>@L["Loading..."]</p>
return;
}
<p>
<a class="btn btn-primary" href="/admin/magazines/create">@L["Create new"]</a>
</p>
<table class="table table-striped">
<thead>
<tr>
<th>
@L["Title"]
</th>
<th>
@L["Native title"]
</th>
<th>
@L["First publication"]
</th>
<th>
@L["Country"]
</th>
<th>
@L["ISSN"]
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in _magazines)
{
<tr>
<td>
@item.Title
</td>
<td>
@item.NativeTitle
</td>
<td>
@($"{item.FirstPublication:d}")
</td>
<td>
@item.Country
</td>
<td>
@item.Issn
</td>
<td>
<a class="btn btn-primary" href="/admin/magazines/details/@item.Id">@L["Details"]</a>
<a class="btn btn-secondary" href="/admin/magazines/edit/@item.Id">@L["Edit"]</a>
<Button Color="Color.Danger" Clicked="() => {ShowModal(item.Id);}">@L["Delete"]</Button>
</td>
</tr>
}
</tbody>
</table>
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
<ModalBackdrop/>
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["Delete magazine"]</ModalTitle>
<CloseButton Clicked="@HideModal"/>
</ModalHeader>
<ModalBody>
<Text>@string.Format(@L["Are you sure you want to delete the magazine {0}?"], _currentMagazine?.Title)</Text>
</ModalBody>
<ModalFooter>
<Button Color="Color.Primary" Clicked="@HideModal" Disabled="@_deleteInProgress">@L["Cancel"]</Button>
<Button Color="Color.Danger" Clicked="@ConfirmDelete" Disabled="@_deleteInProgress">@L["Delete"]</Button>
</ModalFooter>
</ModalContent>
</Modal>

View File

@@ -0,0 +1,88 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// 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 Magazines
{
MagazineViewModel _currentMagazine;
bool _deleteInProgress;
Modal _frmDelete;
bool _loaded;
List<MagazineViewModel> _magazines;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(_loaded)
return;
_magazines = await Service.GetAsync();
_loaded = true;
StateHasChanged();
}
void ShowModal(long itemId)
{
_currentMagazine = _magazines.FirstOrDefault(n => n.Id == itemId);
_frmDelete.Show();
}
void HideModal() => _frmDelete.Hide();
async void ConfirmDelete()
{
if(_currentMagazine is null)
return;
_deleteInProgress = true;
_magazines = null;
AuthenticationState authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
// Yield thread to let UI to update
await Task.Yield();
await Service.DeleteAsync(_currentMagazine.Id, (await UserManager.GetUserAsync(authState.User)).Id);
_magazines = 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) => _currentMagazine = null;
}
}

View File

@@ -29,4 +29,10 @@
<data name="Administrative pages for media dumps" xml:space="preserve">
<value>Administrative pages for media dumps</value>
</data>
<data name="Magazines" xml:space="preserve">
<value>Magazines</value>
</data>
<data name="Documents" xml:space="preserve">
<value>Documents</value>
</data>
</root>

View File

@@ -228,4 +228,10 @@
<data name="Administrative pages for media dumps" xml:space="preserve">
<value>Páginas de administración de volcados</value>
</data>
<data name="Magazines" xml:space="preserve">
<value>Revistas</value>
</data>
<data name="Documents" xml:space="preserve">
<value>Documentos</value>
</data>
</root>

View File

@@ -0,0 +1,104 @@
<root>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Native title must be smaller than 256 characters." xml:space="preserve">
<value>Native title must be smaller than 256 characters.</value>
</data>
<data name="Title must be smaller than 256 characters." xml:space="preserve">
<value>Title must be smaller than 256 characters.</value>
</data>
<data name="Back to list" xml:space="preserve">
<value>Back to list</value>
</data>
<data name="Save" xml:space="preserve">
<value>Save</value>
</data>
<data name="Please enter a valid ISSN." xml:space="preserve">
<value>Please enter a valid ISSN.</value>
</data>
<data name="Unknown (ISSN)" xml:space="preserve">
<value>Unknown</value>
</data>
<data name="ISSN" xml:space="preserve">
<value>ISSN</value>
</data>
<data name="Unknown (country of publication)" xml:space="preserve">
<value>Unknown</value>
</data>
<data name="Country of publication" xml:space="preserve">
<value>Country of publication</value>
</data>
<data name="Please enter a valid first publication date." xml:space="preserve">
<value>Please enter a valid first publication date.</value>
</data>
<data name="Unknown (first publication date)" xml:space="preserve">
<value>Unknown</value>
</data>
<data name="First publication" xml:space="preserve">
<value>First publication</value>
</data>
<data name="Please enter a valid native title." xml:space="preserve">
<value>Please enter a valid native title.</value>
</data>
<data name="Unknown (native title)" xml:space="preserve">
<value>Unknown</value>
</data>
<data name="Native title, that is, title using native script (cyrillic, chinese, etc)" xml:space="preserve">
<value>Native title, that is, title using native script (cyrillic, chinese, etc)</value>
</data>
<data name="Please enter a valid title." xml:space="preserve">
<value>Please enter a valid title.</value>
</data>
<data name="Title using latin script" xml:space="preserve">
<value>Title using latin script</value>
</data>
<data name="Loading..." xml:space="preserve">
<value>Loading...</value>
</data>
<data name="Magazine details" xml:space="preserve">
<value>Magazine details</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="Are you sure you want to delete the magazine {0}?" xml:space="preserve">
<value>Are you sure you want to delete the magazine {0}?</value>
</data>
<data name="Delete magazine" xml:space="preserve">
<value>Delete magazine</value>
</data>
<data name="Delete" xml:space="preserve">
<value>Delete</value>
</data>
<data name="Edit" xml:space="preserve">
<value>Edit</value>
</data>
<data name="Details" xml:space="preserve">
<value>Details</value>
</data>
<data name="Country" xml:space="preserve">
<value>Country</value>
</data>
<data name="Native title" xml:space="preserve">
<value>Native title</value>
</data>
<data name="Title" xml:space="preserve">
<value>Title</value>
</data>
<data name="Create new" xml:space="preserve">
<value>Create new</value>
</data>
<data name="Magazines" xml:space="preserve">
<value>Magazines</value>
</data>
</root>

View File

@@ -0,0 +1,104 @@
<root>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Are you sure you want to delete the magazine {0}?" xml:space="preserve">
<value>¿Estás seguro de eliminar la revista {0}?</value>
</data>
<data name="Back to list" xml:space="preserve">
<value>Volver a la lista</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancelar</value>
</data>
<data name="Country" xml:space="preserve">
<value>País</value>
</data>
<data name="Country of publication" xml:space="preserve">
<value>País de publicación</value>
</data>
<data name="Create new" xml:space="preserve">
<value>Crear nueva</value>
</data>
<data name="Delete" xml:space="preserve">
<value>Eliminar</value>
</data>
<data name="Delete magazine" xml:space="preserve">
<value>Eliminar revista</value>
</data>
<data name="Details" xml:space="preserve">
<value>Detalles</value>
</data>
<data name="Edit" xml:space="preserve">
<value>Editar</value>
</data>
<data name="First publication" xml:space="preserve">
<value>Primera publicación</value>
</data>
<data name="ISSN" xml:space="preserve">
<value>ISSN</value>
</data>
<data name="Loading..." xml:space="preserve">
<value>Cargando...</value>
</data>
<data name="Magazine details" xml:space="preserve">
<value>Detalles de revista</value>
</data>
<data name="Magazines" xml:space="preserve">
<value>Revistas</value>
</data>
<data name="Native title" xml:space="preserve">
<value>Título nativo</value>
</data>
<data name="Native title must be smaller than 256 characters." xml:space="preserve">
<value>El título nativo debe contener menos de 256 caracteres.</value>
</data>
<data name="Native title, that is, title using native script (cyrillic, chinese, etc)" xml:space="preserve">
<value>Título nativo, es decir, usando escritura nativa (cirílico, chino, etc)</value>
</data>
<data name="Please enter a valid first publication date." xml:space="preserve">
<value>Por favor introduce una fecha de primera publicación válida.</value>
</data>
<data name="Please enter a valid ISSN." xml:space="preserve">
<value>Por favor introduce un ISSN válido.</value>
</data>
<data name="Please enter a valid native title." xml:space="preserve">
<value>Por favor introduce un título nativo válido.</value>
</data>
<data name="Please enter a valid title." xml:space="preserve">
<value>Por favor introduce un título válido.</value>
</data>
<data name="Save" xml:space="preserve">
<value>Guardar</value>
</data>
<data name="Title" xml:space="preserve">
<value>Título</value>
</data>
<data name="Title must be smaller than 256 characters." xml:space="preserve">
<value>El título debe contener menos de 256 caracteres.</value>
</data>
<data name="Title using latin script" xml:space="preserve">
<value>Título usando escritura latina</value>
</data>
<data name="Unknown (country of publication)" xml:space="preserve">
<value>Desconocido</value>
</data>
<data name="Unknown (first publication date)" xml:space="preserve">
<value>Desconocida</value>
</data>
<data name="Unknown (ISSN)" xml:space="preserve">
<value>Desconocido</value>
</data>
<data name="Unknown (native title)" xml:space="preserve">
<value>Desconocido</value>
</data>
</root>

View File

@@ -0,0 +1,119 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// 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 MagazinesService
{
readonly MarechaiContext _context;
public MagazinesService(MarechaiContext context) => _context = context;
public async Task<List<MagazineViewModel>> GetAsync() => await _context.
Magazines.OrderBy(b => b.NativeTitle).
ThenBy(b => b.FirstPublication).
ThenBy(b => b.Title).
Select(b => new MagazineViewModel
{
Id = b.Id,
Title = b.Title,
NativeTitle = b.NativeTitle,
FirstPublication = b.FirstPublication,
Synopsis = b.Synopsis,
Issn = b.Issn,
CountryId = b.CountryId,
Country = b.Country.Name
}).ToListAsync();
public async Task<MagazineViewModel> GetAsync(long id) => await _context.Magazines.Where(b => b.Id == id).
Select(b => new MagazineViewModel
{
Id = b.Id,
Title = b.Title,
NativeTitle = b.NativeTitle,
FirstPublication = b.FirstPublication,
Synopsis = b.Synopsis,
Issn = b.Issn,
CountryId = b.CountryId,
Country = b.Country.Name
}).FirstOrDefaultAsync();
public async Task UpdateAsync(MagazineViewModel viewModel, string userId)
{
Magazine model = await _context.Magazines.FindAsync(viewModel.Id);
if(model is null)
return;
model.Title = viewModel.Title;
model.NativeTitle = viewModel.NativeTitle;
model.FirstPublication = viewModel.FirstPublication;
model.Synopsis = viewModel.Synopsis;
model.CountryId = viewModel.CountryId;
model.Issn = viewModel.Issn;
await _context.SaveChangesWithUserAsync(userId);
}
public async Task<long> CreateAsync(MagazineViewModel viewModel, string userId)
{
var model = new Magazine
{
Title = viewModel.Title,
NativeTitle = viewModel.NativeTitle,
FirstPublication = viewModel.FirstPublication,
Synopsis = viewModel.Synopsis,
CountryId = viewModel.CountryId,
Issn = viewModel.Issn
};
await _context.Magazines.AddAsync(model);
await _context.SaveChangesWithUserAsync(userId);
return model.Id;
}
public async Task<string> GetSynopsisTextAsync(int id) =>
(await _context.Magazines.FirstOrDefaultAsync(d => d.Id == id))?.Synopsis;
public async Task DeleteAsync(long id, string userId)
{
Magazine item = await _context.Magazines.FindAsync(id);
if(item is null)
return;
_context.Magazines.Remove(item);
await _context.SaveChangesWithUserAsync(userId);
}
}
}

View File

@@ -74,6 +74,7 @@ namespace Marechai.Services
services.AddScoped<DocumentsService>();
services.AddScoped<DumpsService>();
services.AddScoped<MediaService>();
services.AddScoped<MagazinesService>();
}
}
}

View File

@@ -209,5 +209,45 @@ namespace Marechai.Shared
if(modulo == isbn[12] - 0x30)
e.Status = ValidationStatus.Success;
}
public static void ValidateIssn(ValidatorEventArgs e)
{
e.Status = ValidationStatus.Error;
if(!(e.Value is string issn))
return;
if(issn.Length != 8)
return;
for(int c = 0; c < 7; c++)
{
if(issn[c] < 0x30 ||
issn[c] > 0x39)
return;
}
if((issn[7] < 0x30 || issn[7] > 0x39) &&
issn[7] != 'x' &&
issn[7] != 'X')
return;
int sum = 0;
int modulo = 0;
for(int i = 0; i < 7; i++)
{
modulo += issn[i] - 0x30;
sum += modulo;
}
modulo = sum % 11;
if((issn[7] == 'x' || issn[7] == 'X') &&
modulo == 10)
e.Status = ValidationStatus.Success;
else if(modulo == issn[7] - 0x30)
e.Status = ValidationStatus.Success;
}
}
}

View File

@@ -0,0 +1,35 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
using System;
namespace Marechai.ViewModels
{
public class MagazineViewModel : DocumentBaseViewModel
{
public string Issn { get; set; }
public DateTime? FirstPublication { get; set; }
}
}