start working on security group view

This commit is contained in:
2020-08-21 22:23:30 +02:00
parent 8fcd1c4c44
commit 6d975599a3
15 changed files with 243 additions and 110 deletions

View File

@ -5,9 +5,6 @@ namespace UserService.Infrastructure.DataModels
{
public abstract class Member : Node
{
[EmailAddress]
public string? EMail { get; set; }
public ICollection<UserMember> Members { get; set; } = new List<UserMember>();
}
}

View File

@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace UserService.Infrastructure.DataModels
{
@ -7,7 +9,10 @@ namespace UserService.Infrastructure.DataModels
public string? FirstName { get; set; }
public string? LastName { get; set; }
public bool IsActive { get; set; }
[EmailAddress]
public string? EMail { get; set; }
public string FullName => $"{FirstName} {LastName}";
public IEnumerable<UserMember> MemberOf { get; set; } = new List<UserMember>();

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UserService.Infrastructure.DataModels;
namespace UserService.Infrastructure
{
public static class NodeExtensions
{
public static void MapFields(this User user, Dictionary<string, object> values)
{
if (user == null) throw new ArgumentNullException(nameof(user));
if (values == null) throw new ArgumentNullException(nameof(values));
var properties = user.GetType().GetProperties();
foreach (var keyValuePair in values)
{
var propertyInfo = properties.FirstOrDefault(x => x.Name == keyValuePair.Key);
if (propertyInfo == null) continue;
propertyInfo.SetValue(user, keyValuePair.Value);
}
}
}
}

View File

@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>

View File

@ -7,13 +7,13 @@ namespace UserService.Infrastructure
{
public static class Validators
{
public static bool? ValidateEmail(string mailAddress)
public static bool? ValidateEmail(string? mailAddress)
{
if (string.IsNullOrEmpty(mailAddress)) return null;
return new EmailAddressAttribute().IsValid(mailAddress);
}
public static bool? ValidateCommonName(string commonName, IReadOnlyList<User> users)
public static bool? ValidateCommonName(string? commonName, IEnumerable<Member> users)
{
if (string.IsNullOrEmpty(commonName)) return false;
return users.All(x => x.CommonName != commonName);