mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add code to delete licenses.
This commit is contained in:
@@ -1,56 +0,0 @@
|
|||||||
@model Marechai.Database.Models.License
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Delete";
|
|
||||||
}
|
|
||||||
<h1>Delete</h1>
|
|
||||||
<h3>Are you sure you want to delete this?</h3>
|
|
||||||
<div>
|
|
||||||
<h4>License</h4>
|
|
||||||
<hr />
|
|
||||||
<dl class="row">
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.Name)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.Name)
|
|
||||||
</dd>
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.SPDX)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.SPDX)
|
|
||||||
</dd>
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.FsfApproved)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.FsfApproved)
|
|
||||||
</dd>
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.OsiApproved)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.OsiApproved)
|
|
||||||
</dd>
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.Link)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.Link)
|
|
||||||
</dd>
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.Text)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.Text)
|
|
||||||
</dd>
|
|
||||||
</dl>
|
|
||||||
<form asp-action="Delete">
|
|
||||||
<input type="hidden" asp-for="Id" />
|
|
||||||
<input class="btn btn-danger" type="submit" value="Delete" />
|
|
||||||
<a asp-action="Index" class="btn btn-secondary">
|
|
||||||
Back to List
|
|
||||||
</a>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
@@ -31,7 +31,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@page "/admin/licenses"
|
@page "/admin/licenses"
|
||||||
@using Marechai.Database.Models
|
|
||||||
@inherits OwningComponentBase<LicensesService>
|
@inherits OwningComponentBase<LicensesService>
|
||||||
@inject IStringLocalizer<LicensesService> L
|
@inject IStringLocalizer<LicensesService> L
|
||||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||||
@@ -99,21 +98,26 @@
|
|||||||
<span class="btn btn-secondary">
|
<span class="btn btn-secondary">
|
||||||
@L["Edit"]
|
@L["Edit"]
|
||||||
</span>
|
</span>
|
||||||
<span class="btn btn-danger">
|
<Button Color="Color.Danger" Clicked="() => {ShowModal(item.Id);}">@L["Delete"]</Button>
|
||||||
@L["Delete"]
|
|
||||||
</span>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@code
|
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
|
||||||
{
|
<ModalBackdrop/>
|
||||||
List<License> _licenses;
|
<ModalContent Centered="true">
|
||||||
|
<ModalHeader>
|
||||||
protected override async Task OnInitializedAsync()
|
<ModalTitle>@L["Delete license"]</ModalTitle>
|
||||||
{
|
<CloseButton Clicked="@HideModal"/>
|
||||||
_licenses = await Service.GetAsync();
|
</ModalHeader>
|
||||||
}
|
<ModalBody>
|
||||||
}
|
<Text>@string.Format(@L["Are you sure you want to delete {0}?"], _license?.Name)</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>
|
||||||
|
|||||||
52
Marechai/Pages/Admin/Licenses.razor.cs
Normal file
52
Marechai/Pages/Admin/Licenses.razor.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Blazorise;
|
||||||
|
using Marechai.Database.Models;
|
||||||
|
|
||||||
|
namespace Marechai.Pages.Admin
|
||||||
|
{
|
||||||
|
public partial class Licenses
|
||||||
|
{
|
||||||
|
bool _deleteInProgress;
|
||||||
|
Modal _frmDelete;
|
||||||
|
License _license;
|
||||||
|
List<License> _licenses;
|
||||||
|
|
||||||
|
void ShowModal(int itemId)
|
||||||
|
{
|
||||||
|
_license = _licenses.FirstOrDefault(n => n.Id == itemId);
|
||||||
|
_frmDelete.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HideModal() => _frmDelete.Hide();
|
||||||
|
|
||||||
|
async void ConfirmDelete()
|
||||||
|
{
|
||||||
|
if(_license is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_deleteInProgress = true;
|
||||||
|
_licenses = null;
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
await Service.DeleteAsync(_license.Id);
|
||||||
|
_licenses = 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) => _license = null;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync() => _licenses = await Service.GetAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -162,4 +162,16 @@
|
|||||||
<value>Eliminar</value>
|
<value>Eliminar</value>
|
||||||
<comment>Delete</comment>
|
<comment>Delete</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Delete license" xml:space="preserve">
|
||||||
|
<value>Eliminar licencia</value>
|
||||||
|
<comment>Delete license</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Are you sure you want to delete {0}?" xml:space="preserve">
|
||||||
|
<value>¿Está seguro de que desea borrar {0}?</value>
|
||||||
|
<comment>{0} license name</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Cancel" xml:space="preserve">
|
||||||
|
<value>Cancelar</value>
|
||||||
|
<comment>Cancel</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -13,6 +13,22 @@ namespace Marechai.Services
|
|||||||
public LicensesService(MarechaiContext context) => _context = context;
|
public LicensesService(MarechaiContext context) => _context = context;
|
||||||
|
|
||||||
public async Task<List<License>> GetAsync() =>
|
public async Task<List<License>> GetAsync() =>
|
||||||
await _context.Licenses.OrderBy(l => l.Name).Select(l => new License(){FsfApproved = l.FsfApproved, Id= l.Id, Link = l.Link, Name = l.Name, OsiApproved = l.OsiApproved, SPDX = l.SPDX}).ToListAsync();
|
await _context.Licenses.OrderBy(l => l.Name).Select(l => new License
|
||||||
|
{
|
||||||
|
FsfApproved = l.FsfApproved, Id = l.Id, Link = l.Link, Name = l.Name,
|
||||||
|
OsiApproved = l.OsiApproved, SPDX = l.SPDX
|
||||||
|
}).ToListAsync();
|
||||||
|
|
||||||
|
public async Task DeleteAsync(int id)
|
||||||
|
{
|
||||||
|
License item = await _context.Licenses.FindAsync(id);
|
||||||
|
|
||||||
|
if(item is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_context.Licenses.Remove(item);
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user