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

@@ -2,7 +2,7 @@
// This is auto-generated code.
//------------------------------------------------------------------------------
// This code was generated by Entity Developer tool using EF Core template.
// Code is generated on: 01.04.2022 16:25:00
// Code is generated on: 01.04.2022 16:41:05
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -129,8 +129,9 @@ namespace FoodsharingSiegen.Server.Data
{
modelBuilder.Entity<Interaction>().ToTable(@"Interactions");
modelBuilder.Entity<Interaction>().Property(x => x.Id).HasColumnName(@"Id").IsRequired().ValueGeneratedOnAdd();
modelBuilder.Entity<Interaction>().Property(x => x.Date).HasColumnName(@"Date").IsRequired().ValueGeneratedNever();
modelBuilder.Entity<Interaction>().Property(x => x.UserId).HasColumnName(@"UserId").ValueGeneratedNever();
modelBuilder.Entity<Interaction>().Property(x => x.Date).HasColumnName(@"Date").IsRequired().ValueGeneratedNever();
modelBuilder.Entity<Interaction>().Property(x => x.Info).HasColumnName(@"Info").ValueGeneratedNever();
modelBuilder.Entity<Interaction>().Property(x => x.Type).HasColumnName(@"Type").IsRequired().ValueGeneratedNever();
modelBuilder.Entity<Interaction>().Property(x => x.ProspectId).HasColumnName(@"ProspectId").ValueGeneratedNever();
modelBuilder.Entity<Interaction>().HasKey(@"Id");

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

View File

@@ -9,7 +9,7 @@
<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
</div>
<article class="content px-4">

View File

@@ -9,16 +9,16 @@
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="fas fa-tasks mr-1" aria-hidden="true" style="font-size: 1.4em;"></span> Übersicht
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="fas fa-users mr-1" aria-hidden="true" style="font-size: 1.4em;"></span> Benutzer
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="fas fa-tasks mr-1" aria-hidden="true" style="font-size: 1.4em;"></span> Verifizierung
</NavLink>
</div>
</nav>
</div>

Binary file not shown.

Binary file not shown.