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

@@ -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
}
}