diff --git a/UserService.DatabaseLayer/DataModels/Node.cs b/UserService.DatabaseLayer/DataModels/Node.cs index cc43df7..ff84ef4 100644 --- a/UserService.DatabaseLayer/DataModels/Node.cs +++ b/UserService.DatabaseLayer/DataModels/Node.cs @@ -1,4 +1,4 @@ -#nullable enable +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -11,7 +11,6 @@ namespace UserService.DatabaseLayer.DataModels public class SecurityGroup : Member { - } public class User : Member @@ -23,8 +22,6 @@ namespace UserService.DatabaseLayer.DataModels public string FullName => $"{FirstName} {LastName}"; public IEnumerable MemberOf { get; set; } = new List(); - - public User Clone() => (User)MemberwiseClone(); } public class UserMember @@ -45,7 +42,7 @@ namespace UserService.DatabaseLayer.DataModels public ICollection Members { get; set; } = new List(); } - public abstract class Node + public abstract class Node : ICloneable { public int Id { get; set; } [Required] public string CommonName { get; set; } = null!; @@ -58,5 +55,8 @@ namespace UserService.DatabaseLayer.DataModels { return $"[{GetType().Name}] {Id:D5} {CommonName}"; } + + /// + public virtual object Clone() => MemberwiseClone(); } } \ No newline at end of file diff --git a/UserService.DatabaseLayer/Repository/BaseRepository.cs b/UserService.DatabaseLayer/Repository/BaseRepository.cs index 5072183..d5364ca 100644 --- a/UserService.DatabaseLayer/Repository/BaseRepository.cs +++ b/UserService.DatabaseLayer/Repository/BaseRepository.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; +using System.Runtime.CompilerServices; +using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; @@ -8,7 +10,7 @@ using UserService.DatabaseLayer.DataModels; namespace UserService.DatabaseLayer.Repository { - public class BaseRepository where T : class + public class BaseRepository where T : Node { private readonly Func> _context; @@ -20,7 +22,7 @@ namespace UserService.DatabaseLayer.Repository public async Task> GetAllAsync(CancellationToken token = default) { await using var db = new UserServiceDbContext(); - return await _context(db).ToListAsync(token); + return await _context(db).Include(x => x.Parent).ToListAsync(token); } public async Task GetAsync(Expression> predicate, CancellationToken token = default) diff --git a/UserService.db b/UserService.db index d2cb7d3..ba9c441 100644 Binary files a/UserService.db and b/UserService.db differ diff --git a/UserService/Pages/Counter.razor b/UserService/Pages/Counter.razor deleted file mode 100644 index e90f305..0000000 --- a/UserService/Pages/Counter.razor +++ /dev/null @@ -1,65 +0,0 @@ -@page "/counter" -@using UserService.DatabaseLayer.DataModels -@using UserService.DatabaseLayer.Repository -@using System.Collections -@inject IOrganizationUnitsRepository OuRepository - -

Tree

- -@if (_organizationUnits == null) -{ -

- Loading... -

-} -else -{ - - - - - - - - - - - -} -@code { - private IReadOnlyList _organizationUnits; - private OrganizationUnit _selectedOu; - - protected override async Task OnInitializedAsync() - { - _organizationUnits = (await OuRepository.GetAllAsync().ConfigureAwait(false)).Where(x=> x.Parent is null).ToList(); - } - - private void OnSelectionChanged(TreeViewNodeEventArgs args) - { - _selectedOu = args.NodeInfo.DataItem as OrganizationUnit; - } - - private IEnumerable GetNodeChildren(object dataItem) - { - if (dataItem is OrganizationUnit organizationUnit) - { - foreach (var organizationUnitChild in organizationUnit.Children) - { - yield return organizationUnitChild; - } - } - } - -} \ No newline at end of file diff --git a/UserService/Pages/Directory.razor b/UserService/Pages/Directory.razor new file mode 100644 index 0000000..4ba6e41 --- /dev/null +++ b/UserService/Pages/Directory.razor @@ -0,0 +1,29 @@ +@page "/directory" +@using UserService.DatabaseLayer.DataModels +@using UserService.DatabaseLayer.Repository +@inject IOrganizationUnitsRepository OuRepository + +

TODO

+ +@if (_organizationUnits == null) +{ +

+ Loading... +

+} +else +{ + + +} +@code { + private IReadOnlyList _organizationUnits; + private OrganizationUnit _selectedOu; + + protected override async Task OnInitializedAsync() + { + _organizationUnits = (await OuRepository.GetAllAsync().ConfigureAwait(false)).Where(x=> x.Parent is null).ToList(); + } + + +} \ No newline at end of file diff --git a/UserService/Pages/Index.razor b/UserService/Pages/Index.razor index 5a13a53..e5d682f 100644 --- a/UserService/Pages/Index.razor +++ b/UserService/Pages/Index.razor @@ -1,105 +1,8 @@ @page "/" -@using UserService.DatabaseLayer.DataModels -@using UserService.DatabaseLayer.Repository -@inject IUsersRepository UsersRepository -

User service

-@if (_users == null) -{ -

- Loading... -

-} -else -{ - - - - - - - - - - - - - - @foreach (var user in _users) - { - - - - - - - - - - - } - -
Common NameFull nameDescriptionE-MailIs active
@user.CommonName@user.FullName@user.Description@user.EMail@user.IsActiveeditdelete
- Create user -} - - - @if (_userToEdit != null) - { - @(_userToEdit.Id == 0 ? "New" : "Edit") @_userToEdit.CommonName (@_userToEdit.Id) - - -

- - -

- -

- - - - } - else - { - No securityGroup selected - } - - No Thanks - OK - - - - @code { - bool _dialogIsOpen; - User? _userToEdit; - - private IReadOnlyList _users; - - protected override async Task OnInitializedAsync() - { - _users = await UsersRepository.GetAllAsync(); - } - - private void EditUser(User user) - { - _dialogIsOpen = true; - _userToEdit = user.Clone(); - } - - async Task OkClick() - { - await UsersRepository.UpdateAsync(_userToEdit).ConfigureAwait(false); - await OnInitializedAsync().ConfigureAwait(false); - _dialogIsOpen = false; - } - - private async Task DeleteUser(User user) - { - await UsersRepository.DeleteAsync(user).ConfigureAwait(false); - await OnInitializedAsync().ConfigureAwait(false); - } + } \ No newline at end of file diff --git a/UserService/Pages/SecurityGroups.razor b/UserService/Pages/SecurityGroups.razor new file mode 100644 index 0000000..4b3ac83 --- /dev/null +++ b/UserService/Pages/SecurityGroups.razor @@ -0,0 +1,95 @@ +@page "/securitygroups" +@using UserService.DatabaseLayer.DataModels +@using UserService.DatabaseLayer.Repository +@inject ISecurityGroupsRepository SecurityGroupsRepository +@inject IOrganizationUnitsRepository OrganizationUnits + + +

Table of all security groups

+ +@if (_securityGroups == null) +{ +

+ Loading... +

+} +else +{ + + + Common Name + Description + E-Mail + Parent + + + + + @context.CommonName + @context.Description + @context.EMail + @context.Parent + edit + delete + + + + Create new group +} + + + @if (_securityGroupToEdit != null) + { + @(_securityGroupToEdit.Id == 0 ? "New" : "Edit") @_securityGroupToEdit.CommonName (@_securityGroupToEdit.Id) + + +

+ + +

+ + + } + else + { + No securityGroup selected + } + + No Thanks + OK + + + + +@code { + bool _dialogIsOpen; + SecurityGroup _securityGroupToEdit; + + private IReadOnlyList _securityGroups; + private IReadOnlyList _organizationUnits; + + protected override async Task OnInitializedAsync() + { + _securityGroups = await SecurityGroupsRepository.GetAllAsync(); + _organizationUnits = await OrganizationUnits.GetAllAsync().ConfigureAwait(false); + } + + private void EditSecurityGroup(SecurityGroup securityGroup) + { + _dialogIsOpen = true; + _securityGroupToEdit = (SecurityGroup)securityGroup.Clone(); + } + + async Task OkClick() + { + await SecurityGroupsRepository.UpdateAsync(_securityGroupToEdit).ConfigureAwait(false); + await OnInitializedAsync().ConfigureAwait(false); + _dialogIsOpen = false; + } + + private async Task DeleteSecurityGroup(SecurityGroup securityGroup) + { + await SecurityGroupsRepository.DeleteAsync(securityGroup).ConfigureAwait(false); + await OnInitializedAsync().ConfigureAwait(false); + } +} \ No newline at end of file diff --git a/UserService/Pages/Users.razor b/UserService/Pages/Users.razor new file mode 100644 index 0000000..09d15e9 --- /dev/null +++ b/UserService/Pages/Users.razor @@ -0,0 +1,66 @@ +@page "/users" +@using UserService.DatabaseLayer.DataModels +@inherits UsersBase + +

List of all users

+ +@if (Users == null) +{ +

+ Loading... +

+} +else +{ + + + Common Name + Full name + Description + E-Mail + Parent + Is active + + + + + @context.CommonName + @context.FullName + @context.Description + @context.EMail + @context.Parent + @context.IsActive + edit + delete + + + + Create user +} + + + @if (UserToEdit != null) + { + @(UserToEdit.Id == 0 ? "New" : "Edit") @UserToEdit.CommonName (@UserToEdit.Id) + + + +

+ + +

+ + +

+ + + } + else + { + No securityGroup selected + } + + No Thanks + OK + + \ No newline at end of file diff --git a/UserService/Pages/Users.razor.cs b/UserService/Pages/Users.razor.cs new file mode 100644 index 0000000..e7b9666 --- /dev/null +++ b/UserService/Pages/Users.razor.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using UserService.DatabaseLayer.DataModels; +using UserService.DatabaseLayer.Repository; + +namespace UserService.Pages +{ + public class UsersBase : ComponentBase + { + [Inject] private IUsersRepository UsersRepository { get; set; } = null!; + [Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!; + + protected bool DialogIsOpen { get; set; } + protected User? UserToEdit { get; private set; } + + protected IReadOnlyList? Users { get; private set; } + protected IReadOnlyList? OrganizationUnits { get; private set; } + + protected override async Task OnInitializedAsync() + { + Users = await UsersRepository.GetAllAsync(); + OrganizationUnits = await OrganizationUnitsRepository.GetAllAsync().ConfigureAwait(false); + } + + protected void EditUser(User user) + { + DialogIsOpen = true; + UserToEdit = user; + } + + protected async Task OkClick() + { + if (UserToEdit is null) return; + await UsersRepository.UpdateAsync(UserToEdit).ConfigureAwait(false); + await OnInitializedAsync().ConfigureAwait(false); + DialogIsOpen = false; + } + + protected async Task DeleteUser(User user) + { + await UsersRepository.DeleteAsync(user).ConfigureAwait(false); + await OnInitializedAsync().ConfigureAwait(false); + } + } +} \ No newline at end of file diff --git a/UserService/Pages/_Host.cshtml b/UserService/Pages/_Host.cshtml index 69260ac..8b3f80a 100644 --- a/UserService/Pages/_Host.cshtml +++ b/UserService/Pages/_Host.cshtml @@ -16,7 +16,6 @@ - diff --git a/UserService/Shared/NavMenu.razor b/UserService/Shared/NavMenu.razor index 05f5ee3..86cbcad 100644 --- a/UserService/Shared/NavMenu.razor +++ b/UserService/Shared/NavMenu.razor @@ -5,6 +5,7 @@ +

@code { - private bool collapseNavMenu = true; + private bool _collapseNavMenu = true; - private string NavMenuCssClass => collapseNavMenu ? "collapse" : null; + private string NavMenuCssClass => _collapseNavMenu ? "collapse" : null; private void ToggleNavMenu() { - collapseNavMenu = !collapseNavMenu; + _collapseNavMenu = !_collapseNavMenu; } } diff --git a/UserService/Shared/OrgUnitItem.razor b/UserService/Shared/OrgUnitItem.razor deleted file mode 100644 index 5ce2d9c..0000000 --- a/UserService/Shared/OrgUnitItem.razor +++ /dev/null @@ -1,15 +0,0 @@ -@using UserService.DatabaseLayer.DataModels - - -   @OrganizationUnit.CommonName - - - Item 6.A - Item 6.B - Item 6.C - - -@code { - [Parameter] - public OrganizationUnit OrganizationUnit { get; set; } -} diff --git a/UserService/Startup.DevExpress.cs b/UserService/Startup.DevExpress.cs deleted file mode 100644 index be84994..0000000 --- a/UserService/Startup.DevExpress.cs +++ /dev/null @@ -1,27 +0,0 @@ -//------------------------------------------------------------------------------ -// Generated by the DevExpress.Blazor package. -// To prevent this operation, add the DxExtendStartupHost property to the project and set this property to False. -// -// UserService.csproj: -// -// -// -// netcoreapp3.1 -// False -// -//------------------------------------------------------------------------------ -using System; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Hosting; - -[assembly: HostingStartup(typeof(UserService.DevExpressHostingStartup))] - -namespace UserService { - public partial class DevExpressHostingStartup : IHostingStartup { - void IHostingStartup.Configure(IWebHostBuilder builder) { - builder.ConfigureServices((serviceCollection) => { - serviceCollection.AddDevExpressBlazor(); - }); - } - } -} diff --git a/UserService/Startup.cs b/UserService/Startup.cs index ece0d57..e43811c 100644 --- a/UserService/Startup.cs +++ b/UserService/Startup.cs @@ -1,3 +1,4 @@ +using System.Net.Http; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -25,7 +26,7 @@ namespace UserService services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - //services.AddSingleton(); + services.AddScoped(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/UserService/UserService.csproj b/UserService/UserService.csproj index 6788a02..1217d5d 100644 --- a/UserService/UserService.csproj +++ b/UserService/UserService.csproj @@ -6,7 +6,6 @@ - diff --git a/UserService/_Imports.razor b/UserService/_Imports.razor index 1fcb4a1..2e8ba2a 100644 --- a/UserService/_Imports.razor +++ b/UserService/_Imports.razor @@ -7,5 +7,4 @@ @using Microsoft.JSInterop @using UserService @using UserService.Shared -@using MatBlazor -@using DevExpress.Blazor \ No newline at end of file +@using MatBlazor \ No newline at end of file