diff --git a/Marechai/Pages/Admin/Details/MagazineIssue.razor b/Marechai/Pages/Admin/Details/MagazineIssue.razor
index c69a15ba..df1c8fd0 100644
--- a/Marechai/Pages/Admin/Details/MagazineIssue.razor
+++ b/Marechai/Pages/Admin/Details/MagazineIssue.razor
@@ -35,6 +35,8 @@
@inject MagazinesService MagazinesService
@inject MachineFamiliesService MachineFamiliesService
@inject MagazinesByMachineFamilyService MagazinesByMachineFamilyService
+@inject MachinesService MachinesService
+@inject MagazinesByMachineService MagazinesByMachineService
@inject NavigationManager NavigationManager
@inject IWebHostEnvironment Host
@inject IJSRuntime JSRuntime
@@ -241,6 +243,54 @@
}
+
+ @L["Machines this magazine talks about"]
+
+ @if (_addingMachine)
+ {
+
+
+ @L[""]
+
+
+
+
+
+ }
+ @if (_magazineMachines?.Count > 0)
+ {
+
+
+
+
+ |
+ @L["Machine"]
+ |
+ |
+
+
+
+ @foreach (var item in _magazineMachines)
+ {
+
+ |
+ @item.Machine
+ |
+
+
+ |
+
+ }
+
+
+
+ }
+
diff --git a/Marechai/Pages/Admin/Details/MagazineIssue.razor.cs b/Marechai/Pages/Admin/Details/MagazineIssue.razor.cs
index 6e2be447..513d0487 100644
--- a/Marechai/Pages/Admin/Details/MagazineIssue.razor.cs
+++ b/Marechai/Pages/Admin/Details/MagazineIssue.razor.cs
@@ -37,22 +37,29 @@ namespace Marechai.Pages.Admin.Details
{
public partial class MagazineIssue
{
+ bool _addingMachine;
bool _addingMachineFamily;
int? _addingMachineFamilyId;
+ int? _addingMachineId;
AuthenticationState _authState;
bool _creating;
+ MagazineByMachineViewModel _currentMagazineByMachine;
MagazineByMachineFamilyViewModel _currentMagazineByMachineFamily;
bool _deleteInProgress;
string _deleteText;
string _deleteTitle;
+ bool _deletingMagazineByMachine;
bool _deletingMagazineByMachineFamily;
bool _editing;
Modal _frmDelete;
bool _loaded;
List _machineFamilies;
+ List _machines;
List _magazineMachineFamilies;
+ List _magazineMachines;
List _magazines;
MagazineIssueViewModel _model;
+ bool _savingMachine;
bool _savingMachineFamily;
bool _unknownIssueNumber;
bool _unknownNativeCaption;
@@ -79,10 +86,13 @@ namespace Marechai.Pages.Admin.Details
_magazines = await MagazinesService.GetTitlesAsync();
_machineFamilies = await MachineFamiliesService.GetAsync();
+ _machines = await MachinesService.GetAsync();
_model = _creating ? new MagazineIssueViewModel() : await Service.GetAsync(Id);
_authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
_addingMachineFamilyId = _machineFamilies.First().Id;
_magazineMachineFamilies = await MagazinesByMachineFamilyService.GetByMagazine(Id);
+ _addingMachineId = _machines.First().Id;
+ _magazineMachines = await MagazinesByMachineService.GetByMagazine(Id);
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
StartsWith("admin/magazine_issues/edit/",
@@ -189,6 +199,8 @@ namespace Marechai.Pages.Admin.Details
_deleteInProgress = false;
_deletingMagazineByMachineFamily = false;
_currentMagazineByMachineFamily = null;
+ _deletingMagazineByMachine = false;
+ _currentMagazineByMachine = null;
}
void HideModal() => _frmDelete.Hide();
@@ -197,6 +209,8 @@ namespace Marechai.Pages.Admin.Details
{
if(_deletingMagazineByMachineFamily)
await ConfirmDeleteMagazineByMachineFamily();
+ else if(_deletingMagazineByMachine)
+ await ConfirmDeleteMagazineByMachine();
}
void OnAddFamilyClick()
@@ -281,5 +295,87 @@ namespace Marechai.Pages.Admin.Details
// Tell we finished loading
StateHasChanged();
}
+
+ void OnAddMachineClick()
+ {
+ _addingMachine = true;
+ _savingMachine = false;
+ _addingMachineId = _machines.First().Id;
+ }
+
+ void CancelAddMachine()
+ {
+ _addingMachine = false;
+ _savingMachine = false;
+ _addingMachineId = null;
+ }
+
+ async Task ConfirmAddMachine()
+ {
+ if(_addingMachineId is null ||
+ _addingMachineId <= 0)
+ {
+ CancelAddMachine();
+
+ return;
+ }
+
+ _savingMachine = true;
+
+ // Yield thread to let UI to update
+ await Task.Yield();
+
+ await MagazinesByMachineService.CreateAsync(_addingMachineId.Value, Id,
+ (await UserManager.GetUserAsync(_authState.User)).Id);
+
+ _magazineMachines = await MagazinesByMachineService.GetByMagazine(Id);
+
+ _addingMachine = false;
+ _savingMachine = false;
+ _addingMachineId = null;
+
+ // Yield thread to let UI to update
+ await Task.Yield();
+
+ // Tell we finished loading
+ StateHasChanged();
+ }
+
+ void ShowMachineDeleteModal(long itemId)
+ {
+ _currentMagazineByMachine = _magazineMachines.FirstOrDefault(n => n.Id == itemId);
+ _deletingMagazineByMachine = true;
+ _deleteTitle = L["Delete machine from this magazine"];
+
+ _deleteText = string.Format(L["Are you sure you want to delete the machine {0} from this magazine issue?"],
+ _currentMagazineByMachine?.Machine);
+
+ _frmDelete.Show();
+ }
+
+ async Task ConfirmDeleteMagazineByMachine()
+ {
+ if(_currentMagazineByMachine is null)
+ return;
+
+ _deleteInProgress = true;
+
+ // Yield thread to let UI to update
+ await Task.Yield();
+
+ await MagazinesByMachineService.DeleteAsync(_currentMagazineByMachine.Id,
+ (await UserManager.GetUserAsync(_authState.User)).Id);
+
+ _magazineMachines = await MagazinesByMachineService.GetByMagazine(Id);
+
+ _deleteInProgress = false;
+ _frmDelete.Hide();
+
+ // Yield thread to let UI to update
+ await Task.Yield();
+
+ // Tell we finished loading
+ StateHasChanged();
+ }
}
}
\ No newline at end of file
diff --git a/Marechai/Resources/Services/MagazineIssues.en.resx b/Marechai/Resources/Services/MagazineIssues.en.resx
index fdbfd220..6f711a42 100644
--- a/Marechai/Resources/Services/MagazineIssues.en.resx
+++ b/Marechai/Resources/Services/MagazineIssues.en.resx
@@ -128,4 +128,25 @@
Family
+
+ Delete machine from this magazine
+
+
+ Are you sure you want to delete the machine {0} from this magazine issue?
+
+
+ Machine
+
+
+ Add new
+
+
+ Machines this magazine issue talks about
+
+
+ Delete machine family from this magazine
+
+
+ Are you sure you want to delete the machine family {0} from this magazine issue?
+
\ No newline at end of file
diff --git a/Marechai/Resources/Services/MagazineIssues.es.resx b/Marechai/Resources/Services/MagazineIssues.es.resx
index 1f5f96b1..6dd10c7e 100644
--- a/Marechai/Resources/Services/MagazineIssues.es.resx
+++ b/Marechai/Resources/Services/MagazineIssues.es.resx
@@ -235,4 +235,25 @@
Familia
+
+ Máquinas sobre las que habla esta revista
+
+
+ Máquina
+
+
+ Eliminar máquina de esta revista
+
+
+ Añadir nueva
+
+
+ ¿Estás seguro de eliminar la máquina {0} de esta revista?
+
+
+ Eliminar familia de máquina de esta revista
+
+
+ ¿Estás seguro de eliminar la familia de máquinas {0} de esta revista?
+
\ No newline at end of file
diff --git a/Marechai/Services/MagazinesByMachineService.cs b/Marechai/Services/MagazinesByMachineService.cs
new file mode 100644
index 00000000..bc4fc932
--- /dev/null
+++ b/Marechai/Services/MagazinesByMachineService.cs
@@ -0,0 +1,77 @@
+/******************************************************************************
+// 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 MagazinesByMachineService
+ {
+ readonly MarechaiContext _context;
+
+ public MagazinesByMachineService(MarechaiContext context) => _context = context;
+
+ public async Task> GetByMagazine(long bookId) =>
+ await _context.MagazinesByMachines.Where(p => p.MagazineId == bookId).
+ Select(p => new MagazineByMachineViewModel
+ {
+ Id = p.Id,
+ MagazineId = p.MagazineId,
+ MachineId = p.MachineId,
+ Machine = p.Machine.Name
+ }).OrderBy(p => p.Machine).ThenBy(p => p.Magazine).ToListAsync();
+
+ public async Task DeleteAsync(long id, string userId)
+ {
+ MagazinesByMachine item = await _context.MagazinesByMachines.FindAsync(id);
+
+ if(item is null)
+ return;
+
+ _context.MagazinesByMachines.Remove(item);
+
+ await _context.SaveChangesWithUserAsync(userId);
+ }
+
+ public async Task CreateAsync(int machineId, long bookId, string userId)
+ {
+ var item = new MagazinesByMachine
+ {
+ MachineId = machineId,
+ MagazineId = bookId
+ };
+
+ await _context.MagazinesByMachines.AddAsync(item);
+ await _context.SaveChangesWithUserAsync(userId);
+
+ return item.Id;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs
index 333a4096..20a3f626 100644
--- a/Marechai/Services/Register.cs
+++ b/Marechai/Services/Register.cs
@@ -90,6 +90,7 @@ namespace Marechai.Services
services.AddScoped();
services.AddScoped();
services.AddScoped();
+ services.AddScoped();
}
}
}
\ No newline at end of file
diff --git a/Marechai/ViewModels/MagazineByMachineViewModel.cs b/Marechai/ViewModels/MagazineByMachineViewModel.cs
new file mode 100644
index 00000000..a6324428
--- /dev/null
+++ b/Marechai/ViewModels/MagazineByMachineViewModel.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 MagazineByMachineViewModel : BaseViewModel
+ {
+ public long MagazineId { get; set; }
+ public string Magazine { get; set; }
+ public int MachineId { get; set; }
+ public string Machine { get; set; }
+ }
+}
\ No newline at end of file