Addet Employye get logic
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
</div>
|
||||
</FluentLayoutItem>
|
||||
</FluentLayout>
|
||||
<FluentDialogProvider />
|
||||
|
||||
<div id="blazor-error-ui" data-nosnippet>
|
||||
An unhandled error has occurred.
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
@page "/settings/employees"
|
||||
@inject IDialogService DialogService
|
||||
@rendermode InteractiveServer
|
||||
@using Database.Models
|
||||
@using Pos.Service
|
||||
@inject EmployeeService EmployeeService
|
||||
|
||||
<Header />
|
||||
|
||||
@@ -11,40 +15,26 @@
|
||||
Opret medarbejder
|
||||
</FluentButton>
|
||||
</div>
|
||||
|
||||
<FluentDataGrid TGridItem="EmployeeRow"
|
||||
Items="@_employees.AsQueryable()"
|
||||
GridTemplateColumns="1fr 180px">
|
||||
|
||||
<PropertyColumn Property="@(item => item.Name)"
|
||||
Title="Navn"
|
||||
Sortable="true" />
|
||||
|
||||
<TemplateColumn Title="Handling" Context="employee">
|
||||
<FluentButton Class="deactivate-button"
|
||||
Appearance="@ButtonAppearance.Outline"
|
||||
OnClick="@(() => DeactivateEmployee(employee))">
|
||||
Deaktivér
|
||||
</FluentButton>
|
||||
</TemplateColumn>
|
||||
</FluentDataGrid>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<EmployeeRow> _employees =
|
||||
[
|
||||
new EmployeeRow { Name = "Anna Jensen" },
|
||||
new EmployeeRow { Name = "Peter Hansen" },
|
||||
new EmployeeRow { Name = "Maria Nielsen" }
|
||||
];
|
||||
|
||||
private void DeactivateEmployee(EmployeeRow employee)
|
||||
@if (_isLoading)
|
||||
{
|
||||
_employees.Remove(employee);
|
||||
}
|
||||
|
||||
private class EmployeeRow
|
||||
<FluentProgressRing />
|
||||
}else
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
<FluentDataGrid TGridItem="EmployeeEntity"
|
||||
Items="@_employees.AsQueryable()"
|
||||
GridTemplateColumns="1fr 180px">
|
||||
|
||||
<PropertyColumn Property="@(item => item.Name)"
|
||||
Title="Navn"
|
||||
Sortable="true" />
|
||||
|
||||
<TemplateColumn Title="Handling" Context="employee">
|
||||
<FluentButton Class="deactivate-button"
|
||||
Appearance="@ButtonAppearance.Outline"
|
||||
OnClick="@(() => ConfirmDeactivation(employee))">
|
||||
Deaktivér
|
||||
</FluentButton>
|
||||
</TemplateColumn>
|
||||
</FluentDataGrid>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,46 @@
|
||||
using Database.Models;
|
||||
using Microsoft.FluentUI.AspNetCore.Components;
|
||||
|
||||
namespace Pos.Web.Components.Pages.Settings
|
||||
{
|
||||
public partial class Employees
|
||||
{
|
||||
private List<EmployeeEntity> _employees = [];
|
||||
private bool _isLoading = true;
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_employees = await EmployeeService.GetEmployeesAsync();
|
||||
_isLoading = false;
|
||||
}
|
||||
|
||||
private void LoadEmployees()
|
||||
{
|
||||
_employees = EmployeeService.GetEmployees();
|
||||
}
|
||||
|
||||
private async Task ConfirmDeactivation(EmployeeEntity employee)
|
||||
{
|
||||
DialogResult result = await DialogService.ShowConfirmationAsync(
|
||||
$"Er du sikker på, at du vil deaktivere {employee.Name}?",
|
||||
"Bekræft deaktivering",
|
||||
"Annuller",
|
||||
"Deaktivér");
|
||||
|
||||
if (result.Cancelled)
|
||||
{
|
||||
DeactivateEmployee(employee);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeactivateEmployee(EmployeeEntity employee)
|
||||
{
|
||||
EmployeeService.ArchiveEmployee(employee.Id);
|
||||
LoadEmployees();
|
||||
}
|
||||
|
||||
private class EmployeeRow
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user