Blazorise #4
BIN
UserService.db
BIN
UserService.db
Binary file not shown.
@ -12,7 +12,7 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<DataGrid TItem="User" RowSelectable="@(u => false)" Editable="true" EditMode="DataGridEditMode.Inline" RowRemoving="RowDeletingCallback" Data="@Users" RowInserted="RowInsertedCallback" RowUpdating="RowUpdatingCallback">
|
<DataGrid TItem="User" RowSelectable="@(u => false)" Editable="true" EditMode="DataGridEditMode.Popup" RowRemoving="RowDeletingCallback" Data="@Users" RowInserted="RowInsertedCallback" RowUpdating="RowUpdatingCallback">
|
||||||
<DataGridCommandColumn TItem="User">
|
<DataGridCommandColumn TItem="User">
|
||||||
<NewCommandTemplate>
|
<NewCommandTemplate>
|
||||||
<Button Color="Color.Success" Clicked="@context.Clicked" title="Create user">
|
<Button Color="Color.Success" Clicked="@context.Clicked" title="Create user">
|
||||||
@ -40,11 +40,35 @@ else
|
|||||||
</Button>
|
</Button>
|
||||||
</CancelCommandTemplate>
|
</CancelCommandTemplate>
|
||||||
</DataGridCommandColumn>
|
</DataGridCommandColumn>
|
||||||
<DataGridColumn TItem="User" Field="@nameof(User.Id)" Caption="#" Sortable="false"/>
|
<DataGridColumn TItem="User" Field="@nameof(User.Id)" Caption="#" Sortable="false" />
|
||||||
<DataGridColumn TItem="User" Field="@nameof(User.CommonName)" Caption="CN" CellsEditableOnEditCommand="false" Editable="true"/>
|
|
||||||
|
<DataGridColumn TItem="User" Field="@nameof(User.CommonName)" Caption="CN" CellsEditableOnEditCommand="false" Editable="true">
|
||||||
|
<EditTemplate>
|
||||||
|
<Validation Validator="@ValidateCommonName">
|
||||||
|
<TextEdit Placeholder="Enter common name" Text="@((string)(((CellEditContext)context).CellValue))" TextChanged="@(v=>((CellEditContext)context).CellValue=v)">
|
||||||
|
<Feedback>
|
||||||
|
<ValidationSuccess></ValidationSuccess>
|
||||||
|
<ValidationError>Please enter a valid common name!</ValidationError>
|
||||||
|
</Feedback>
|
||||||
|
</TextEdit>
|
||||||
|
</Validation>
|
||||||
|
</EditTemplate>
|
||||||
|
</DataGridColumn>
|
||||||
<DataGridColumn TItem="User" Field="@nameof(User.FirstName)" Caption="First Name" Editable="true"/>
|
<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.LastName)" Caption="Last Name" Editable="true"/>
|
||||||
<DataGridColumn TItem="User" Field="@nameof(User.EMail)" Caption="EMail" Editable="true"/>
|
<DataGridColumn TItem="User" Field="@nameof(User.EMail)" Caption="EMail" Editable="true">
|
||||||
|
<EditTemplate>
|
||||||
|
<Validation Validator="@ValidateEmail">
|
||||||
|
<TextEdit Placeholder="Enter email" Text="@((string)(((CellEditContext)context).CellValue))" TextChanged="@(v=>((CellEditContext)context).CellValue=v)">
|
||||||
|
<Feedback>
|
||||||
|
<ValidationNone>Please enter the email.</ValidationNone>
|
||||||
|
<ValidationSuccess>Email is ok.</ValidationSuccess>
|
||||||
|
<ValidationError>Enter valid email!</ValidationError>
|
||||||
|
</Feedback>
|
||||||
|
</TextEdit>
|
||||||
|
</Validation>
|
||||||
|
</EditTemplate>
|
||||||
|
</DataGridColumn>
|
||||||
<DataGridSelectColumn TItem="User" Field="@nameof(User.ParentId)" Caption="Parent" Editable="true">
|
<DataGridSelectColumn TItem="User" Field="@nameof(User.ParentId)" Caption="Parent" Editable="true">
|
||||||
<DisplayTemplate>
|
<DisplayTemplate>
|
||||||
@{
|
@{
|
||||||
@ -55,7 +79,7 @@ else
|
|||||||
</DisplayTemplate>
|
</DisplayTemplate>
|
||||||
<EditTemplate>
|
<EditTemplate>
|
||||||
|
|
||||||
<Select TValue="int" SelectedValue="@((int)(context.CellValue))" SelectedValueChanged="@(v => context.CellValue = v)" >
|
<Select TValue="int?" SelectedValue="@((int?)(context.CellValue))" SelectedValueChanged="@(v => context.CellValue = v)" >
|
||||||
@foreach (var item in OrganizationUnits)
|
@foreach (var item in OrganizationUnits)
|
||||||
{
|
{
|
||||||
<SelectItem TValue="int" Value="@(item.Id)">@item.CommonName</SelectItem>
|
<SelectItem TValue="int" Value="@(item.Id)">@item.CommonName</SelectItem>
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Blazorise;
|
||||||
using Blazorise.DataGrid;
|
using Blazorise.DataGrid;
|
||||||
using Microsoft.JSInterop;
|
using Microsoft.JSInterop;
|
||||||
using UserService.DatabaseLayer.DataModels;
|
using UserService.DatabaseLayer.DataModels;
|
||||||
@ -47,15 +49,39 @@ namespace UserService.Pages
|
|||||||
|
|
||||||
arg.Cancel = true;
|
arg.Cancel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task RowUpdatingCallback(CancellableRowChange<User, Dictionary<string, object>> 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<User, Dictionary<string, object>> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user