71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Blazorise.DataGrid;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using UserService.DatabaseLayer.Repository;
|
|
using UserService.Infrastructure.DataModels;
|
|
|
|
namespace UserService.Pages
|
|
{
|
|
public class SecurityGroupsBase : MembersBase<SecurityGroup>
|
|
{
|
|
[Inject] private ISecurityGroupsRepository SecurityGroupsRepository { get; set; } = null!;
|
|
[Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Members = await SecurityGroupsRepository.GetAllAsync().ConfigureAwait(false);
|
|
OrganizationUnits = await OrganizationUnitsRepository.GetAllAsync().ConfigureAwait(false);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task RowInsertingCallback(CancellableRowChange<SecurityGroup, Dictionary<string, object>> arg)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task RowInsertedCallback(SavedRowItem<SecurityGroup, Dictionary<string, object>> arg)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task RowDeletingCallback(CancellableRowChange<SecurityGroup> arg)
|
|
{
|
|
if (arg == null) throw new ArgumentNullException(nameof(arg));
|
|
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
|
|
$"You are about to delete the security group {arg.Item.CommonName}. Are you sure?").ConfigureAwait(false);
|
|
if (confirmed)
|
|
{
|
|
await SecurityGroupsRepository.DeleteAsync(arg.Item).ConfigureAwait(false);
|
|
return;
|
|
}
|
|
|
|
arg.Cancel = true;
|
|
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task RowUpdatingCallback(CancellableRowChange<SecurityGroup, Dictionary<string, object>> arg)
|
|
{
|
|
}
|
|
|
|
protected async void OnButtonClicked(SecurityGroup securityGroup)
|
|
{
|
|
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
|
|
$"You are about to delete the security group {securityGroup.CommonName}. Are you sure?").ConfigureAwait(false);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override bool OnCustomFilter(SecurityGroup model)
|
|
{
|
|
if (model == null) throw new ArgumentNullException(nameof(model));
|
|
// We want to accept empty value as valid or otherwise
|
|
// datagrid will not show anything.
|
|
if (string.IsNullOrEmpty(CustomFilterValue)) return true;
|
|
|
|
return model.CommonName.Contains(CustomFilterValue, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
}
|
|
} |