Addet Employye get logic
This commit is contained in:
@@ -50,5 +50,10 @@ namespace Pos.Service
|
||||
if (employeeId <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(employeeId));
|
||||
}
|
||||
|
||||
public async Task<List<EmployeeEntity>> GetEmployeesAsync()
|
||||
{
|
||||
return await _employeeRepository.GetAllAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Database.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Database.Repository
|
||||
{
|
||||
@@ -58,5 +59,16 @@ namespace Database.Repository
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<EmployeeEntity>> GetAllAsync()
|
||||
{
|
||||
await using PosDbContext context = new PosDbContext();
|
||||
|
||||
return await context.Employee
|
||||
.AsNoTracking()
|
||||
.Where(employee => !employee.IsArchived)
|
||||
.OrderBy(employee => employee.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pos.Models\Pos.Models.csproj" />
|
||||
<ProjectReference Include="..\Pos.ServiceDefaults\Pos.ServiceDefaults.csproj" />
|
||||
<ProjectReference Include="..\Pos.Service\Pos.Service.csproj" />
|
||||
<ProjectReference Include="..\Pos.Ui\Database\Database.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.FluentUI.AspNetCore.Components;
|
||||
using Pos.Web.Components;
|
||||
using Pos.Service;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -9,6 +10,7 @@ builder.AddServiceDefaults();
|
||||
builder.Services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents();
|
||||
builder.Services.AddFluentUIComponents();
|
||||
builder.Services.AddScoped<EmployeeService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"SqlServer": "Server=localhost;Database=PointOfSale;Trusted_Connection=True;TrustServerCertificate=True;",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
Reference in New Issue
Block a user