Working on edit button for Members of Security groups

This commit is contained in:
Holger Börchers 2020-08-22 20:30:05 +02:00
parent e6822e0491
commit ca983c9d3a
5 changed files with 35 additions and 8 deletions

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace UserService.Infrastructure.DataModels
{

View File

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Blazorise;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using UserService.Infrastructure;
using UserService.Infrastructure.DataModels;
@ -12,6 +13,8 @@ namespace UserService.Pages
{
public abstract class MembersBase<T> : ComponentBase where T : Member
{
[Inject] protected IJSRuntime JsRuntime { get; set; } = null!;
protected IReadOnlyList<OrganizationUnit>? OrganizationUnits { get; set; }
protected IReadOnlyList<T>? Members { get; set; }

View File

@ -83,5 +83,10 @@ else
</Select>
</EditTemplate>
</DataGridSelectColumn>
<DataGridColumn TItem="SecurityGroup" Field="@nameof(SecurityGroup.Members)" Caption="Members" Editable="true">
<DisplayTemplate>
<Button Color="Color.Success" Block="true" Clicked="@(() => OnButtonClicked((SecurityGroup) context ))">Edit</Button>
</DisplayTemplate>
</DataGridColumn>
</DataGrid>
}

View File

@ -1,7 +1,9 @@
using System.Collections.Generic;
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;
@ -31,8 +33,17 @@ namespace UserService.Pages
/// <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 />
@ -40,10 +51,21 @@ namespace UserService.Pages
{
}
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)
{
return true;
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);
}
}
}

View File

@ -17,8 +17,6 @@ namespace UserService.Pages
[Inject] private IUsersRepository UsersRepository { get; set; } = null!;
[Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!;
[Inject] private IJSRuntime JsRuntime { get; set; } = null!;
protected override async Task OnInitializedAsync()
{
Members = await UsersRepository.GetAllAsync().ConfigureAwait(false);
@ -78,7 +76,7 @@ namespace UserService.Pages
if (arg == null) throw new ArgumentNullException(nameof(arg));
var user = arg.Item;
user.MapFields(arg.Values);
user.Parent = OrganizationUnits?.FirstOrDefault(x => x.Id == (int?) arg.Values[nameof(Node.ParentId)]);
user.Parent = OrganizationUnits?.FirstOrDefault(x => x.Id == (int?)arg.Values[nameof(Node.ParentId)]);
var result = await UsersRepository.UpdateAsync(user).ConfigureAwait(false);
arg.Cancel = !result;
}