diff --git a/UserService.db b/UserService.db index cef1d65..11403be 100644 Binary files a/UserService.db and b/UserService.db differ diff --git a/UserService/Pages/Users.razor b/UserService/Pages/Users.razor index d72a398..82bbe63 100644 --- a/UserService/Pages/Users.razor +++ b/UserService/Pages/Users.razor @@ -12,7 +12,7 @@ } else { - + - - + + + + + + + + + Please enter a valid common name! + + + + + - + + + + + + Please enter the email. + Email is ok. + Enter valid email! + + + + + @{ @@ -55,7 +79,7 @@ else - @foreach (var item in OrganizationUnits) { @item.CommonName diff --git a/UserService/Pages/Users.razor.cs b/UserService/Pages/Users.razor.cs index a134c6f..ff80935 100644 --- a/UserService/Pages/Users.razor.cs +++ b/UserService/Pages/Users.razor.cs @@ -1,8 +1,10 @@ using System; using Microsoft.AspNetCore.Components; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; +using Blazorise; using Blazorise.DataGrid; using Microsoft.JSInterop; using UserService.DatabaseLayer.DataModels; @@ -47,15 +49,39 @@ namespace UserService.Pages arg.Cancel = true; } - - protected async Task RowUpdatingCallback(CancellableRowChange> arg) - { - 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; - } + protected static void ValidateCommonName(ValidatorEventArgs e) + { + if (e == null) throw new ArgumentNullException(nameof(e)); + var commonName = e.Value?.ToString(); + + if (string.IsNullOrEmpty(commonName)) + e.Status = ValidationStatus.Error; + else + e.Status = ValidationStatus.Success; + } + + protected static void ValidateEmail(ValidatorEventArgs e) + { + if (e == null) throw new ArgumentNullException(nameof(e)); + var email = e.Value?.ToString(); + + if (string.IsNullOrEmpty(email)) + e.Status = ValidationStatus.None; + else if (!new EmailAddressAttribute().IsValid(email)) + { + e.Status = ValidationStatus.Error; + } + else + e.Status = ValidationStatus.Success; + } + protected async Task RowUpdatingCallback(CancellableRowChange> arg) + { + 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; + } } } \ No newline at end of file