Added FxCop and get Organization Unit selection running
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
@ -27,14 +26,14 @@ namespace UserService.Pages
|
||||
private async void OnSelectedNodeChanged(Node? value)
|
||||
{
|
||||
if (value == null) return;
|
||||
Members = await UsersRepository.GetAllAsync(x => x.ParentId == value.Id);
|
||||
Members = await UsersRepository.GetAllAsync(x => x.ParentId == value.Id).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public IReadOnlyList<Member> Members { get; set; }
|
||||
public IReadOnlyList<Member>? Members { get; set; }
|
||||
|
||||
[Inject] public IOrganizationUnitsRepository OuRepository { get; set; }
|
||||
[Inject] public IOrganizationUnitsRepository OuRepository { get; set; } = null!;
|
||||
|
||||
[Inject] public IUsersRepository UsersRepository { get; set; }
|
||||
[Inject] public IUsersRepository UsersRepository { get; set; } = null!;
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
<h1>Table of all security groups</h1>
|
||||
|
||||
@if (SecurityGroups is null)
|
||||
@if (Groups is null)
|
||||
{
|
||||
<p>
|
||||
<em>Loading...</em>
|
||||
@ -12,7 +12,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<DataGrid TItem="SecurityGroup" Data="@SecurityGroups">
|
||||
<DataGrid TItem="SecurityGroup" Data="@Groups">
|
||||
<DataGridCommandColumn TItem="User" />
|
||||
<DataGridColumn TItem="SecurityGroup" Field="@nameof(SecurityGroup.Id)" Caption="#" Sortable="false" />
|
||||
<DataGridColumn TItem="SecurityGroup" Field="@nameof(SecurityGroup.CommonName)" Caption="CN" Editable="true" />
|
||||
|
@ -8,18 +8,18 @@ namespace UserService.Pages
|
||||
{
|
||||
public class SecurityGroupsBase : ComponentBase
|
||||
{
|
||||
[Inject] private ISecurityGroupsRepository? SecurityGroupsRepository { get; set; }
|
||||
[Inject] private IOrganizationUnitsRepository? OrganizationUnitsRepository { get; set; }
|
||||
[Inject] private ISecurityGroupsRepository SecurityGroupsRepository { get; set; } = null!;
|
||||
[Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!;
|
||||
|
||||
protected bool DialogIsOpen;
|
||||
protected SecurityGroup? SecurityGroupToEdit;
|
||||
protected bool DialogIsOpen { get; set; }
|
||||
protected SecurityGroup? SecurityGroupToEdit { get; set; }
|
||||
|
||||
protected IReadOnlyList<SecurityGroup>? SecurityGroups;
|
||||
protected IReadOnlyList<OrganizationUnit>? OrganizationUnits;
|
||||
protected IReadOnlyList<SecurityGroup>? Groups { get; set; }
|
||||
protected IReadOnlyList<OrganizationUnit>? OrganizationUnits { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
SecurityGroups = await SecurityGroupsRepository.GetAllAsync().ConfigureAwait(false);
|
||||
Groups = await SecurityGroupsRepository.GetAllAsync().ConfigureAwait(false);
|
||||
OrganizationUnits = await OrganizationUnitsRepository.GetAllAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
@ -29,24 +29,23 @@ else
|
||||
<DataGridColumn TItem="User" Field="@nameof(User.FirstName)" Caption="First Name" Editable="true"/>
|
||||
<DataGridColumn TItem="User" Field="@nameof(User.LastName)" Caption="Last Name" Editable="true"/>
|
||||
<DataGridColumn TItem="User" Field="@nameof(User.EMail)" Caption="EMail" Editable="true"/>
|
||||
<DataGridSelectColumn TItem="User" Field="@nameof(User.Parent)" Caption="Parent" Editable="true">
|
||||
<DataGridSelectColumn TItem="User" Field="@nameof(User.ParentId)" Caption="Parent" Editable="true">
|
||||
<DisplayTemplate>
|
||||
@{
|
||||
var name = ((User) context).Parent?.CommonName ?? "-";
|
||||
var name = ((User) context ).Parent?.CommonName ?? "-";
|
||||
@name
|
||||
}
|
||||
|
||||
</DisplayTemplate>
|
||||
<EditTemplate>
|
||||
@{
|
||||
<Blazorise.SelectEdit TValue="User" SelectedValue="@((User)(context.CellValue))" SelectedValueChanged="@(v => context.CellValue = v)">
|
||||
|
||||
<Select TValue="int" SelectedValue="@((int)(context.CellValue))" SelectedValueChanged="@(v => context.CellValue = v)" >
|
||||
@foreach (var item in OrganizationUnits)
|
||||
{
|
||||
|
||||
<SelectItem TValue="OrganizationUnit" Value="@(item)">@item.CommonName</SelectItem>
|
||||
<SelectItem TValue="int" Value="@(item.Id)">@item.CommonName</SelectItem>
|
||||
}
|
||||
</Blazorise.SelectEdit>
|
||||
}
|
||||
</Select>
|
||||
|
||||
|
||||
</EditTemplate>
|
||||
</DataGridSelectColumn>
|
||||
|
@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Blazorise.DataGrid;
|
||||
using Microsoft.JSInterop;
|
||||
@ -20,19 +22,21 @@ namespace UserService.Pages
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Users = await UsersRepository.GetAllAsync();
|
||||
Users = await UsersRepository.GetAllAsync().ConfigureAwait(false);
|
||||
OrganizationUnits = await OrganizationUnitsRepository.GetAllAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
protected async Task RowInsertedCallback(SavedRowItem<User, Dictionary<string, object>> arg)
|
||||
{
|
||||
if (arg == null) throw new ArgumentNullException(nameof(arg));
|
||||
var user = arg.Item;
|
||||
user.ParentId = -2;
|
||||
await UsersRepository.AddAsync(user);
|
||||
await UsersRepository.AddAsync(user).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
protected async Task RowDeletingCallback(CancellableRowChange<User> arg)
|
||||
{
|
||||
if (arg == null) throw new ArgumentNullException(nameof(arg));
|
||||
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
|
||||
$"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false);
|
||||
if (confirmed)
|
||||
@ -46,7 +50,10 @@ namespace UserService.Pages
|
||||
|
||||
protected async Task RowUpdatingCallback(CancellableRowChange<User, Dictionary<string, object>> arg)
|
||||
{
|
||||
var result = await UsersRepository.UpdateAsync(arg.Item);
|
||||
if (arg == null) throw new ArgumentNullException(nameof(arg));
|
||||
var user = arg.Item;
|
||||
user.Parent = OrganizationUnits.FirstOrDefault(x => x.Id == (int?)arg.Values[nameof(Node.ParentId)]);
|
||||
var result = await UsersRepository.UpdateAsync(user).ConfigureAwait(false);
|
||||
arg.Cancel = !result;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Blazorise;
|
||||
using Blazorise.Bootstrap;
|
||||
using Blazorise.Icons.FontAwesome;
|
||||
@ -40,6 +41,7 @@ namespace UserService
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
@ -5,6 +5,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\.editorconfig" Link=".editorconfig" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UserService.DatabaseLayer\UserService.DatabaseLayer.csproj" />
|
||||
</ItemGroup>
|
||||
@ -15,6 +19,10 @@
|
||||
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="0.9.1.2" />
|
||||
<PackageReference Include="Blazorise.Sidebar" Version="0.9.1.2" />
|
||||
<PackageReference Include="Blazorise.TreeView" Version="0.9.1.2" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user