User editing fixed

This commit is contained in:
Andre Beging
2022-04-01 17:36:46 +02:00
parent 5a1c79ad20
commit 76b199e364
15 changed files with 264 additions and 152 deletions

View File

@@ -34,7 +34,7 @@
Editable
Responsive>
<DataGridColumns>
<DataGridCommandColumn TItem="User" Caption="Wololo" Width="100px" CellStyle="@(_ => "display: flex; padding-left: 0; padding-right: 0; justify-content: center; align-items: center;")">
<DataGridCommandColumn TItem="User" Width="100px" CellStyle="@(_ => "display: flex; padding-left: 0; padding-right: 0; justify-content: center; align-items: center;")">
<NewCommandTemplate>
<Button Size="Size.ExtraSmall" Color="Color.Success" Clicked="@context.Clicked" Class="mr-1" Style="min-width: auto;">
<i class="oi oi-plus"></i>
@@ -56,11 +56,14 @@
</Button>
</ClearFilterCommandTemplate>
</DataGridCommandColumn>
<DataGridColumn TItem="User" Field="@nameof(User.Name)" Caption="Name" Editable="true"></DataGridColumn>
<DataGridColumn TItem="User" Field="@nameof(User.Mail)" Caption="E-Mail" Editable="true"></DataGridColumn>
<DataGridColumn TItem="User" Field="@nameof(User.Type)" Caption="Typ" Editable="true">
<DataGridCheckColumn TItem="User" Field="@nameof(User.Verified)" Caption="Verifiziert" Editable="true" Width="100px">
<DisplayTemplate>
<Check TValue="bool" Checked="context.Verified" Disabled="true" ReadOnly="true"/>
</DisplayTemplate>
</DataGridCheckColumn>
<DataGridColumn TItem="User" Field="@nameof(User.Type)" Caption="Typ" Editable="true" Width="200px">
<EditTemplate>
<Select TValue="UserType" @bind-SelectedValue="@context.Item.Type">
<Select TValue="UserType" SelectedValue="@((UserType)context.CellValue)" SelectedValueChanged="@(v => context.CellValue = v)">
@foreach (var enumValue in Enum.GetValues<UserType>())
{
<SelectItem TValue="UserType" Value="enumValue">@enumValue</SelectItem>
@@ -68,5 +71,8 @@
</Select>
</EditTemplate>
</DataGridColumn>
<DataGridColumn TItem="User" Field="@nameof(User.Name)" Caption="Name" Editable="true" Width="250px"></DataGridColumn>
<DataGridColumn TItem="User" Field="@nameof(User.Mail)" Caption="E-Mail" Editable="true"></DataGridColumn>
</DataGridColumns>
</DataGrid>

View File

@@ -1,22 +1,50 @@
using Blazorise.DataGrid;
using Blazorise.DataGrid;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Server.Data.Service;
using Microsoft.AspNetCore.Components;
namespace FoodsharingSiegen.Server.Pages
{
/// <summary>
/// The users class (a. beging, 01.04.2022)
/// </summary>
public partial class Users
{
#region Dependencies (Injected)
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary> Gets or sets the user service. </summary>
///
/// <value> The user service. </value>
////////////////////////////////////////////////////////////////////////////////////////////////////
[Inject] public UserService UserService { get; set; } = null!;
private List<User>? UserList { get; set; }
#endregion
#region Public Properties
/// <summary>
/// Gets or sets the value of the user data grid (ab)
/// </summary>
public DataGrid<User> UserDataGrid { get; set; }
#endregion
#region Private Properties
/// <summary>
/// Gets or sets the value of the user list (ab)
/// </summary>
private List<User>? UserList { get; set; }
#endregion
#region Override OnAfterRenderAsync
/// <summary>
/// Ons the after render using the specified first render (a. beging, 01.04.2022)
/// </summary>
/// <param name="firstRender">The first render</param>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
@@ -24,7 +52,28 @@ namespace FoodsharingSiegen.Server.Pages
await base.OnAfterRenderAsync(firstRender);
}
#endregion
#region Private Method Chang
/// <summary>
/// Changs the context (a. beging, 01.04.2022)
/// </summary>
/// <param name="context">The context</param>
/// <param name="type">The type</param>
private void Chang(CellEditContext<User> context, UserType type)
{
context.Item.Type = type;
}
#endregion
#region Private Method LoadUsers
/// <summary>
/// Loads the users (a. beging, 01.04.2022)
/// </summary>
private async Task LoadUsers()
{
var usersR = await UserService.GetUsersAsync();
@@ -33,24 +82,42 @@ namespace FoodsharingSiegen.Server.Pages
await InvokeAsync(StateHasChanged);
}
private async Task RowUpdated(SavedRowItem<User, Dictionary<string, object>> arg)
{
if (arg.Item?.Id == null || arg.Item.Id.Equals(Guid.Empty) || arg.Values?.Any() != true) return;
#endregion
await UserService.Update(arg.Item);
}
#region Private Method RowInserted
/// <summary>
/// Rows the inserted using the specified arg (a. beging, 01.04.2022)
/// </summary>
/// <param name="arg">The arg</param>
private async Task RowInserted(SavedRowItem<User, Dictionary<string, object>> arg)
{
var addUserR = await UserService.AddUserAsync(arg.Item);
if (!addUserR.Success)
{
// Error Toast
//Todo Error Toast [01.04.22 - Andre Beging]
}
else
{
await LoadUsers();
}
}
#endregion
#region Private Method RowUpdated
/// <summary>
/// Rows the updated using the specified arg (a. beging, 01.04.2022)
/// </summary>
/// <param name="arg">The arg</param>
private async Task RowUpdated(SavedRowItem<User, Dictionary<string, object>> arg)
{
if (arg.Item?.Id == null || arg.Item.Id.Equals(Guid.Empty) || arg.Values?.Any() != true) return;
var result = await UserService.Update(arg.Item);
}
#endregion
}
}