Set user groups
This commit is contained in:
@@ -19,6 +19,9 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
return new OperationResult<User>(new Exception("Diese E-Mail Adresse wird bereits verwendet"));
|
||||
|
||||
user.Created = DateTime.UtcNow;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(user.Password))
|
||||
user.Password = string.Empty;
|
||||
|
||||
await Context.Users.AddAsync(user);
|
||||
|
||||
@@ -38,7 +41,15 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
{
|
||||
try
|
||||
{
|
||||
Context.Users.Update(user);
|
||||
var entityUser = await Context.Users.FirstOrDefaultAsync(x => x.Id == user.Id);
|
||||
if (entityUser == null) return new OperationResult(new Exception("User not found"));
|
||||
|
||||
entityUser.Mail = user.Mail;
|
||||
entityUser.Name = user.Name;
|
||||
entityUser.Type = user.Type;
|
||||
entityUser.Verified = user.Verified;
|
||||
entityUser.Groups = user.Groups;
|
||||
|
||||
var saveR = await Context.SaveChangesAsync();
|
||||
|
||||
if(saveR < 1) return new OperationResult(new Exception("Fehler beim speichern"));
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
|
||||
<h2>Benutzerverwaltung <span style="font-size: .5em; line-height: 0;">Admin</span></h2>
|
||||
|
||||
<div class="my-2">
|
||||
<Button Color="Color.Primary" Disabled="@(SelectedUser == null)">Passwort setzen</Button>
|
||||
</div>
|
||||
|
||||
<DataGrid TItem="User"
|
||||
@ref="UserDataGrid"
|
||||
Data="@UserList"
|
||||
@@ -31,11 +35,12 @@
|
||||
PopupTitleTemplate="PopupTitleTemplate"
|
||||
RowInserted="RowInserted"
|
||||
RowUpdated="RowUpdated"
|
||||
SelectedRow="SelectedUser"
|
||||
RowDoubleClicked="arg => UserDataGrid.Edit(arg.Item)"
|
||||
Editable
|
||||
Responsive>
|
||||
<DataGridColumns>
|
||||
<DataGridCommandColumn TItem="User" Width="100px" CellStyle="@(_ => "display: flex; padding-left: 0; padding-right: 0; justify-content: center; align-items: center;")">
|
||||
<DataGridCommandColumn TItem="User" Width="100px" CellClass="@(_ => "px-0 d-flex align-items-center justify-content-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>
|
||||
@@ -74,6 +79,31 @@
|
||||
</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>
|
||||
|
||||
<DataGridColumn TItem="User" Field="@nameof(User.GroupsList)" Caption="Gruppen" Editable="true">
|
||||
<EditTemplate>
|
||||
<Autocomplete TItem="UserGroup"
|
||||
TValue="UserGroup"
|
||||
Size="Size.ExtraSmall"
|
||||
Data="@UserGroups"
|
||||
TextField="@(( item ) => item.ToString())"
|
||||
ValueField="@(( item ) => item)"
|
||||
Multiple="true"
|
||||
SelectedValues="@((List<UserGroup>) context.CellValue)"
|
||||
SelectedValuesChanged="@(v => context.CellValue = v)"
|
||||
@bind-SelectedTexts="SelectedCompanyTexts">
|
||||
</Autocomplete>
|
||||
<small>Verfügbar: @string.Join(", ", Enum.GetValues<UserGroup>())</small>
|
||||
</EditTemplate>
|
||||
<DisplayTemplate>
|
||||
@if (string.IsNullOrWhiteSpace(context.Groups))
|
||||
{
|
||||
<span style="font-style: italic;">Keine Gruppen</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>@string.Join(", ", context.GroupsList)</span>
|
||||
}
|
||||
</DisplayTemplate>
|
||||
</DataGridColumn>
|
||||
</DataGridColumns>
|
||||
</DataGrid>
|
||||
Reference in New Issue
Block a user