initial commit

This commit is contained in:
2026-07-21 14:08:10 +07:00
commit f7cf118326
533 changed files with 41762 additions and 0 deletions
@@ -0,0 +1,55 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Features.Organization.Branch.Cqrs;
using MediatR;
using Microsoft.AspNetCore.Authentication.JwtBearer;
namespace Indotalent.Features.Organization.Branch;
public static class BranchEndpoint
{
public static void MapBranchEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("/branch").WithTags("Branches")
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
.RequireAuthenticatedUser());
group.MapGet("/", async (IMediator mediator) =>
{
var result = await mediator.Send(new GetBranchListQuery());
return result.ToApiResponse("Data branch retrieved successfully");
})
.WithName("GetBranchList");
group.MapGet("/{id}", async (string id, IMediator mediator) =>
{
var result = await mediator.Send(new GetBranchByIdQuery(id));
return result.ToApiResponse(result is not null
? "Branch detail retrieved successfully"
: $"Branch with ID {id} not found");
})
.WithName("GetBranchById");
group.MapPost("/", async (CreateBranchRequest request, IMediator mediator) =>
{
var result = await mediator.Send(new CreateBranchCommand(request));
return result.ToApiResponse("Branch has been created successfully", StatusCodes.Status201Created);
})
.WithName("CreateBranch");
group.MapPost("/update", async (UpdateBranchRequest request, IMediator mediator) =>
{
var result = await mediator.Send(new UpdateBranchCommand(request));
if (!result.Success) return ((object?)null).ToApiResponse("Update failed.");
return result.ToApiResponse("Branch has been updated successfully");
})
.WithName("UpdateBranch");
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
{
var result = await mediator.Send(new DeleteBranchByIdCommand(new DeleteBranchByIdRequest(id)));
if (!result) return ((object?)null).ToApiResponse("Delete failed.");
return true.ToApiResponse("Branch has been deleted successfully");
})
.WithName("DeleteBranchById");
}
}
@@ -0,0 +1,54 @@
using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Organization.Branch.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;
namespace Indotalent.Features.Organization.Branch;
public class BranchService : BaseService
{
private readonly RestClient _client;
public BranchService(IHttpClientFactory clientFactory, NavigationManager nav, ISnackbar snackbar, ICurrentUserService currentUserService, TokenProvider tokenProvider)
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
{
_client = new RestClient(nav.BaseUri);
}
public async Task<ApiResponse<List<GetBranchListResponse>>?> GetBranchListAsync()
{
var request = new RestRequest("api/branch", Method.Get);
return await ExecuteWithResponseAsync<List<GetBranchListResponse>>(_client, request);
}
public async Task<ApiResponse<GetBranchByIdResponse>?> GetBranchByIdAsync(string id)
{
var request = new RestRequest($"api/branch/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetBranchByIdResponse>(_client, request);
}
public async Task<ApiResponse<CreateBranchResponse>?> CreateBranchAsync(CreateBranchRequest data)
{
var request = new RestRequest("api/branch", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreateBranchResponse>(_client, request);
}
public async Task<bool> DeleteBranchByIdAsync(string id)
{
var request = new RestRequest($"api/branch/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
public async Task<ApiResponse<UpdateBranchResponse>?> UpdateBranchAsync(UpdateBranchRequest data)
{
var request = new RestRequest("api/branch/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdateBranchResponse>(_client, request);
}
}
@@ -0,0 +1,52 @@
@page "/organization/branch"
@using Indotalent.Features.Organization.Branch
@using Indotalent.Features.Organization.Branch.Cqrs
@using MudBlazor
@if (_currentView == ViewMode.Create)
{
<_BranchCreateForm OnCancel="BackToTable"
OnSuccess="HandleSuccess" />
}
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
{
<_BranchUpdateForm Data="_selectedData!"
ReadOnly="@(_currentView == ViewMode.View)"
OnCancel="BackToTable"
OnSuccess="HandleSuccess" />
}
else
{
<_BranchDataTable OnAdd="() => ShowCreate()"
OnEdit="(item) => ShowUpdate(item, false)"
OnView="(item) => ShowUpdate(item, true)" />
}
@code {
private enum ViewMode { Table, Create, Update, View }
private ViewMode _currentView = ViewMode.Table;
private UpdateBranchRequest? _selectedData;
private void ShowCreate()
{
_currentView = ViewMode.Create;
}
private void ShowUpdate(UpdateBranchRequest data, bool isReadOnly)
{
_selectedData = data;
_currentView = isReadOnly ? ViewMode.View : ViewMode.Update;
}
private void BackToTable()
{
_currentView = ViewMode.Table;
_selectedData = null;
}
private void HandleSuccess()
{
_currentView = ViewMode.Table;
_selectedData = null;
}
}
@@ -0,0 +1,147 @@
@using Indotalent.Features.Organization.Branch
@using Indotalent.Features.Organization.Branch.Cqrs
@using Indotalent.Shared.Utils
@using MudBlazor
@inject BranchService BranchService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Add New Branch</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">Configure new office or warehouse location.</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
<MudForm @ref="_form" Model="_model">
<MudGrid Spacing="3">
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Branch Code</MudText>
<MudTextField @bind-Value="_model.Code"
For="@(() => _model.Code)"
Validation="@(_validator.ValidateValue())"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. HQ-JKT" />
</MudItem>
<MudItem xs="12" sm="8">
<MudText Typo="Typo.subtitle2" Class="mb-1">Branch Name</MudText>
<MudTextField @bind-Value="_model.Name"
For="@(() => _model.Name)"
Validation="@(_validator.ValidateValue())"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. Central Office" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">City</MudText>
<MudTextField @bind-Value="_model.City"
For="@(() => _model.City)"
Validation="@(_validator.ValidateValue())"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. Jakarta" />
</MudItem>
<MudItem xs="12" sm="8">
<MudText Typo="Typo.subtitle2" Class="mb-1">Street Address</MudText>
<MudTextField @bind-Value="_model.StreetAddress"
For="@(() => _model.StreetAddress)"
Validation="@(_validator.ValidateValue())"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">State/Province</MudText>
<MudTextField @bind-Value="_model.StateProvince" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">ZIP Code</MudText>
<MudTextField @bind-Value="_model.ZipCode" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Phone</MudText>
<MudTextField @bind-Value="_model.Phone" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Email</MudText>
<MudTextField @bind-Value="_model.Email"
For="@(() => _model.Email)"
Validation="@(_validator.ValidateValue())"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 1</MudText>
<MudTextField @bind-Value="_model.OtherInformation1" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 2</MudText>
<MudTextField @bind-Value="_model.OtherInformation2" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 3</MudText>
<MudTextField @bind-Value="_model.OtherInformation3" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-8">
<MudButton OnClick="() => OnCancel.InvokeAsync()"
Variant="Variant.Outlined"
Disabled="_processing"
Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">
Cancel
</MudButton>
<MudButton Color="Color.Primary"
Variant="Variant.Filled"
OnClick="Submit"
Disabled="_processing"
Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText>Create Branch</MudText>
}
</MudButton>
</div>
</MudForm>
</MudPaper>
@code {
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm _form = default!;
private CreateBranchValidator _validator = new();
private CreateBranchRequest _model = new();
private bool _processing = false;
private async Task Submit()
{
await _form.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var response = await BranchService.CreateBranchAsync(_model);
await Task.Delay(500);
if (response != null && response.IsSuccess)
{
Snackbar.Add("Branch created successfully", Severity.Success);
await OnSuccess.InvokeAsync();
}
}
catch (Exception ex)
{
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
}
finally
{
_processing = false;
}
}
}
@@ -0,0 +1,402 @@
@using Indotalent.ConfigBackEnd.Extensions
@using Indotalent.Features.Organization.Branch
@using Indotalent.Features.Organization.Branch.Cqrs
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using MudBlazor
@using Features.Root.Shared
@using ClosedXML.Excel
@using System.IO
@inject BranchService BranchService
@inject IDialogService DialogService
@inject ISnackbar Snackbar
@inject IJSRuntime JSRuntime
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
<div>
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Branch Management</MudText>
<MudText Typo="Typo.body2" Style="color: #9CA3AF; font-size: 0.75rem;">Manage physical office locations, regional branches, and site operational details.</MudText>
</div>
<div class="d-flex align-center gap-2">
<MudIcon Icon="@Icons.Material.Filled.Home" Size="Size.Small" Color="Color.Default" />
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Organization</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Branch</MudText>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
<div style="display: flex; align-items: center; gap: 8px;">
<MudTextField @bind-Value="_searchString"
Placeholder="Search..."
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search"
IconSize="Size.Small"
Class="mt-0"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Style="background-color: white; width: 280px; border-radius: 8px;"
OnKeyDown="@HandleSearchKeyDown" />
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
OnClick="OnSearchClick"
Size="Size.Small"
Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; box-shadow: none; background: #3B82F6; color: white;">
Search
</MudButton>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<MudButton Variant="Variant.Outlined"
Color="Color.Success"
OnClick="ExportToExcel"
Size="Size.Small"
Disabled="_isExporting"
StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)"
Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">
@if (_isExporting)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText>
}
</MudButton>
<MudButton Variant="Variant.Outlined"
Color="Color.Primary"
OnClick="LoadData"
Size="Size.Small"
StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)"
Disabled="_isRefreshing"
Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">
@if (_isRefreshing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText>
}
else
{
<MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText>
}
</MudButton>
@if (_selectedBranch != null)
{
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">View</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">Edit</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="background: white; border: 1px solid #FCA5A5; color: #EF4444; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px;">Remove</MudButton>
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedBranch = null" />
}
else
{
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; background: #3B82F6; color: white;">
Add New Branch
</MudButton>
}
</div>
</div>
<MudTable Items="@GetPagedData()" Hover="true" Elevation="0" CustomHeader="true" Dense="true" Striped="true" Class="mud-table-styled" T="GetBranchListResponse" OnRowClick="@((args) => _selectedBranch = args.Item)" Loading="@_isRefreshing">
<HeaderContent>
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetBranchListResponse, object>(x => x.Code)">Branch ID</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetBranchListResponse, object>(x => x.Name)">Branch Name</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetBranchListResponse, object>(x => x.City)">City / Region</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetBranchListResponse, object>(x => x.StreetAddress)">Full Address</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetBranchListResponse, object>(x => x.Phone)">Contact Number</MudTableSortLabel>
</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudCheckBox T="bool" Value="@(_selectedBranch?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudChip T="string" Size="Size.Small" Variant="Variant.Text" Style="background-color: #F9FAFB; color: #374151; font-weight: 600; border-radius: 4px;">
@context.Code
</MudChip>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<div class="d-flex align-center gap-2">
<MudAvatar Color="Color.Primary" Size="Size.Small" Style="width: 32px; height: 32px; font-weight: 700; font-size: 0.75rem;">@(!string.IsNullOrWhiteSpace(context.Name) ? context.Name.ToInitial() : "?")</MudAvatar>
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.Name</MudText>
</div>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #6B7280; font-size: 0.875rem;">@context.City</MudText>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudText Typo="Typo.body2" Style="color: #6B7280; font-size: 0.875rem;">@context.StreetAddress</MudText>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudText Typo="Typo.body2" Style="font-family: monospace; color: #6B7280; font-size: 0.875rem;">@context.Phone</MudText>
</MudTd>
</RowTemplate>
</MudTable>
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
<div style="display: flex; align-items: center; gap: 12px;">
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
<MudSelect T="int"
Value="@_top"
ValueChanged="OnPageSizeChanged"
Dense="true"
Margin="Margin.Dense"
Style="width: 80px; background-color: white; font-size: 12px; font-weight: 600;"
Variant="Variant.Outlined"
Class="mt-0 custom-select-dense">
<MudSelectItem Value="5" />
<MudSelectItem Value="10" />
<MudSelectItem Value="50" />
<MudSelectItem Value="500" />
<MudSelectItem Value="1000" />
</MudSelect>
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem; margin-left: 12px;">
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
</MudText>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" Class="rounded-0" />
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="@(_currentPage == 1 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #6B7280; border: 1px solid #D1D5DB; border-radius: 6px;")">Prev</MudButton>
@{
var totalPages = _totalPage == 0 ? 1 : _totalPage;
var maxVisible = 5;
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
}
@for (int i = startPage; i <= endPage; i++)
{
var pageNum = i;
var isActive = pageNum == _currentPage;
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
Variant="Variant.Text" Size="Size.Small"
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
}
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #6B7280; border: 1px solid #D1D5DB; border-radius: 6px;")">Next</MudButton>
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" Class="rounded-0" />
</div>
</div>
</MudPaper>
<script>
function downloadFile(fileName, contentType, base64String) {
const link = document.createElement('a');
link.download = fileName;
link.href = `data:${contentType};base64,${base64String}`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
</script>
<style>
.mud-input-outlined-border { border-radius: 0px !important; }
.custom-select-dense .mud-input-control { margin-top: 0 !important; }
.custom-select-dense .mud-input-slot { padding-top: 4px !important; padding-bottom: 4px !important; padding-left: 8px !important; font-size: 12px !important; }
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
</style>
@code {
[Parameter] public EventCallback OnAdd { get; set; }
[Parameter] public EventCallback<UpdateBranchRequest> OnEdit { get; set; }
[Parameter] public EventCallback<UpdateBranchRequest> OnView { get; set; }
private List<GetBranchListResponse> _branches = new();
private GetBranchListResponse? _selectedBranch;
private string _searchString = "";
private int _skip = 0;
private int _top = 5;
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
private bool _isRefreshing = false;
private bool _isExporting = false;
protected override async Task OnInitializedAsync() => await LoadData();
private async Task LoadData()
{
_isRefreshing = true; _selectedBranch = null;
StateHasChanged();
try
{
var response = await BranchService.GetBranchListAsync();
await Task.Delay(500);
if (response != null && response.IsSuccess)
{
_branches = response.Value ?? new();
}
}
finally
{
_isRefreshing = false;
StateHasChanged();
}
}
private IEnumerable<GetBranchListResponse> GetFilteredData()
{
if (string.IsNullOrWhiteSpace(_searchString)) return _branches;
return _branches.Where(x =>
(x.Name?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.Code?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.City?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.StreetAddress?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
);
}
private IEnumerable<GetBranchListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
private async Task ExportToExcel()
{
_isExporting = true;
StateHasChanged();
try
{
await Task.Delay(1000);
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.Worksheets.Add("Branches");
var currentRow = 1;
worksheet.Cell(currentRow, 1).Value = "Branch Code";
worksheet.Cell(currentRow, 2).Value = "Branch Name";
worksheet.Cell(currentRow, 3).Value = "City";
worksheet.Cell(currentRow, 4).Value = "Full Address";
worksheet.Cell(currentRow, 5).Value = "Phone";
var headerRange = worksheet.Range(1, 1, 1, 5);
headerRange.Style.Font.Bold = true;
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#0D47A1");
headerRange.Style.Font.FontColor = XLColor.White;
foreach (var item in GetFilteredData())
{
currentRow++;
worksheet.Cell(currentRow, 1).Value = item.Code;
worksheet.Cell(currentRow, 2).Value = item.Name;
worksheet.Cell(currentRow, 3).Value = item.City;
worksheet.Cell(currentRow, 4).Value = item.StreetAddress;
worksheet.Cell(currentRow, 5).Value = item.Phone;
}
worksheet.Columns().AdjustToContents();
using (var stream = new MemoryStream())
{
workbook.SaveAs(stream);
var content = Convert.ToBase64String(stream.ToArray());
await JSRuntime.InvokeVoidAsync("downloadFile", "Branch_Registry.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
Snackbar.Add("Excel exported successfully", Severity.Success);
}
}
}
catch (Exception ex)
{
Snackbar.Add($"Export failed: {ex.Message}", Severity.Error);
}
finally
{
_isExporting = false;
StateHasChanged();
}
}
private void OnSearchClick()
{
_skip = 0;
_selectedBranch = null;
StateHasChanged();
}
private void HandleSearchKeyDown(KeyboardEventArgs e)
{
if (e.Key == "Enter") OnSearchClick();
}
private void OnPageChanged(int page)
{
if (page >= 1 && page <= _totalPage)
{
_skip = (page - 1) * _top;
_selectedBranch = null;
StateHasChanged();
}
}
private void OnPageSizeChanged(int size)
{
_top = size;
_skip = 0;
_selectedBranch = null;
StateHasChanged();
}
private async Task InvokeEdit()
{
if (_selectedBranch == null) return;
var res = await BranchService.GetBranchByIdAsync(_selectedBranch.Id);
if (res?.Value != null) await OnEdit.InvokeAsync(MapToUpdate(res.Value));
}
private async Task InvokeView()
{
if (_selectedBranch == null) return;
var res = await BranchService.GetBranchByIdAsync(_selectedBranch.Id);
if (res?.Value != null) await OnView.InvokeAsync(MapToUpdate(res.Value));
}
private UpdateBranchRequest MapToUpdate(GetBranchByIdResponse d) => new UpdateBranchRequest
{
Id = d.Id,
Code = d.Code,
Name = d.Name,
Description = d.Description,
StreetAddress = d.StreetAddress,
City = d.City,
StateProvince = d.StateProvince,
ZipCode = d.ZipCode,
Phone = d.Phone,
Email = d.Email,
OtherInformation1 = d.OtherInformation1,
OtherInformation2 = d.OtherInformation2,
OtherInformation3 = d.OtherInformation3,
CreatedAt = d.CreatedAt,
CreatedBy = d.CreatedBy,
UpdatedAt = d.UpdatedAt,
UpdatedBy = d.UpdatedBy
};
private async Task OnDelete()
{
if (_selectedBranch == null) return;
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedBranch.Name } });
if (!(await dialog.Result).Canceled)
{
if (await BranchService.DeleteBranchByIdAsync(_selectedBranch.Id))
{
await LoadData(); Snackbar.Add("Branch deleted successfully", Severity.Success);
}
}
}
}
@@ -0,0 +1,198 @@
@using Indotalent.ConfigBackEnd.Extensions
@using Indotalent.Features.Organization.Branch
@using Indotalent.Features.Organization.Branch.Cqrs
@using Indotalent.Shared.Utils
@using MudBlazor
@inject BranchService BranchService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Branch Details" : "Edit Branch")</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing office location profile." : "Modify existing branch information.")</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
<MudForm @ref="_form" Model="_model">
<MudGrid Spacing="3">
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Branch Code</MudText>
<MudTextField @bind-Value="_model.Code"
For="@(() => _model.Code)"
Validation="@(_validator.ValidateValue())"
ReadOnly="ReadOnly"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="8">
<MudText Typo="Typo.subtitle2" Class="mb-1">Branch Name</MudText>
<MudTextField @bind-Value="_model.Name"
For="@(() => _model.Name)"
Validation="@(_validator.ValidateValue())"
ReadOnly="ReadOnly"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">City</MudText>
<MudTextField @bind-Value="_model.City"
For="@(() => _model.City)"
Validation="@(_validator.ValidateValue())"
ReadOnly="ReadOnly"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="8">
<MudText Typo="Typo.subtitle2" Class="mb-1">Street Address</MudText>
<MudTextField @bind-Value="_model.StreetAddress"
For="@(() => _model.StreetAddress)"
Validation="@(_validator.ValidateValue())"
ReadOnly="ReadOnly"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Phone</MudText>
<MudTextField @bind-Value="_model.Phone" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="8">
<MudText Typo="Typo.subtitle2" Class="mb-1">Email</MudText>
<MudTextField @bind-Value="_model.Email"
For="@(() => _model.Email)"
Validation="@(_validator.ValidateValue())"
ReadOnly="ReadOnly"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12">
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
<MudTextField @bind-Value="_model.Description" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 1</MudText>
<MudTextField @bind-Value="_model.OtherInformation1" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 2</MudText>
<MudTextField @bind-Value="_model.OtherInformation2" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 3</MudText>
<MudTextField @bind-Value="_model.OtherInformation3" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" Class="mt-4">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Audit History</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Created At</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.CreatedAt)</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Created By</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System")</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Last Updated At</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.UpdatedAt)</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Last Updated By</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System")</MudText>
</MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-10">
<MudButton OnClick="() => OnCancel.InvokeAsync()"
Variant="Variant.Outlined"
Disabled="_processing"
Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">
@(ReadOnly ? "Back to List" : "Cancel")
</MudButton>
@if (!ReadOnly)
{
<MudButton Color="Color.Primary"
Variant="Variant.Filled"
OnClick="Submit"
Disabled="_processing"
Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2">Updating...</MudText>
}
else
{
<MudText>Save Changes</MudText>
}
</MudButton>
}
</div>
</MudForm>
</MudPaper>
@code {
[Parameter] public UpdateBranchRequest Data { get; set; } = new();
[Parameter] public bool ReadOnly { get; set; } = false;
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm _form = default!;
private UpdateBranchValidator _validator = new();
private UpdateBranchRequest _model = new();
private bool _processing = false;
protected override void OnInitialized()
{
_model = new UpdateBranchRequest
{
Id = Data.Id,
Code = Data.Code,
Name = Data.Name,
Description = Data.Description,
StreetAddress = Data.StreetAddress,
City = Data.City,
StateProvince = Data.StateProvince,
ZipCode = Data.ZipCode,
Phone = Data.Phone,
Email = Data.Email,
OtherInformation1 = Data.OtherInformation1,
OtherInformation2 = Data.OtherInformation2,
OtherInformation3 = Data.OtherInformation3,
CreatedAt = Data.CreatedAt,
CreatedBy = Data.CreatedBy,
UpdatedAt = Data.UpdatedAt,
UpdatedBy = Data.UpdatedBy
};
}
private async Task Submit()
{
if (ReadOnly) return;
await _form.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var response = await BranchService.UpdateBranchAsync(_model);
await Task.Delay(500);
if (response != null && response.IsSuccess)
{
Snackbar.Add("Branch updated successfully", Severity.Success);
await OnSuccess.InvokeAsync();
}
}
catch (Exception ex)
{
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
}
finally
{
_processing = false;
}
}
}
@@ -0,0 +1,83 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Branch.Cqrs;
public class CreateBranchRequest
{
public string? Code { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string StreetAddress { get; set; } = string.Empty;
public string City { get; set; } = string.Empty;
public string StateProvince { get; set; } = string.Empty;
public string ZipCode { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string OtherInformation1 { get; set; } = string.Empty;
public string OtherInformation2 { get; set; } = string.Empty;
public string OtherInformation3 { get; set; } = string.Empty;
}
public class CreateBranchResponse
{
public string? Id { get; set; }
public string? Code { get; set; }
}
public record CreateBranchCommand(CreateBranchRequest Data) : IRequest<CreateBranchResponse>;
public class CreateBranchHandler : IRequestHandler<CreateBranchCommand, CreateBranchResponse>
{
private readonly AppDbContext _context;
public CreateBranchHandler(AppDbContext context) => _context = context;
public async Task<CreateBranchResponse> Handle(CreateBranchCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.Branch
.AnyAsync(x => x.Code == request.Data.Code, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Branch", request.Data.Code ?? string.Empty);
}
var entityName = nameof(Data.Entities.Branch);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.Branch
{
AutoNumber = autoNo,
Code = request.Data.Code,
Name = request.Data.Name,
Description = request.Data.Description,
StreetAddress = request.Data.StreetAddress,
City = request.Data.City,
StateProvince = request.Data.StateProvince,
ZipCode = request.Data.ZipCode,
Phone = request.Data.Phone,
Email = request.Data.Email,
OtherInformation1 = request.Data.OtherInformation1,
OtherInformation2 = request.Data.OtherInformation2,
OtherInformation3 = request.Data.OtherInformation3
};
_context.Branch.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateBranchResponse
{
Id = entity.Id,
Code = entity.Code
};
}
}
@@ -0,0 +1,27 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Branch.Cqrs;
public class CreateBranchValidator : AbstractValidator<CreateBranchRequest>
{
public CreateBranchValidator()
{
RuleFor(x => x.Code)
.NotEmpty().WithMessage("Branch Code is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Branch Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.City)
.NotEmpty().WithMessage("City is required");
RuleFor(x => x.StreetAddress)
.NotEmpty().WithMessage("Street Address is required");
RuleFor(x => x.Email)
.EmailAddress().When(x => !string.IsNullOrEmpty(x.Email));
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Branch.Cqrs;
public record DeleteBranchByIdRequest(string Id);
public record DeleteBranchByIdCommand(DeleteBranchByIdRequest Data) : IRequest<bool>;
public class DeleteBranchByIdHandler : IRequestHandler<DeleteBranchByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteBranchByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteBranchByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Branch
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.Branch.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,65 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Branch.Cqrs;
public class GetBranchByIdResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? Code { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? StreetAddress { get; set; }
public string? City { get; set; }
public string? StateProvince { get; set; }
public string? ZipCode { get; set; }
public string? Phone { get; set; }
public string? Email { get; set; }
public string? OtherInformation1 { get; set; }
public string? OtherInformation2 { get; set; }
public string? OtherInformation3 { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetBranchByIdQuery(string Id) : IRequest<GetBranchByIdResponse?>;
public class GetBranchByIdHandler : IRequestHandler<GetBranchByIdQuery, GetBranchByIdResponse?>
{
private readonly AppDbContext _context;
public GetBranchByIdHandler(AppDbContext context) => _context = context;
public async Task<GetBranchByIdResponse?> Handle(GetBranchByIdQuery request, CancellationToken cancellationToken)
{
return await _context.Branch
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetBranchByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Code = x.Code,
Name = x.Name,
Description = x.Description,
StreetAddress = x.StreetAddress,
City = x.City,
StateProvince = x.StateProvince,
ZipCode = x.ZipCode,
Phone = x.Phone,
Email = x.Email,
OtherInformation1 = x.OtherInformation1,
OtherInformation2 = x.OtherInformation2,
OtherInformation3 = x.OtherInformation3,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,49 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Branch.Cqrs;
public class GetBranchListResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? Code { get; set; }
public string? Name { get; set; }
public string? City { get; set; }
public string? Phone { get; set; }
public string? Email { get; set; }
public string? StreetAddress { get; set; }
public string? Description { get; set; }
}
public record GetBranchListQuery() : IRequest<List<GetBranchListResponse>>;
public class GetBranchListHandler : IRequestHandler<GetBranchListQuery, List<GetBranchListResponse>>
{
private readonly AppDbContext _context;
public GetBranchListHandler(AppDbContext context) => _context = context;
public async Task<List<GetBranchListResponse>> Handle(GetBranchListQuery request, CancellationToken cancellationToken)
{
return await _context.Branch
.AsNoTracking()
.NotDeletedOnly()
.OrderBy(x => x.Code)
.Select(x => new GetBranchListResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Code = x.Code,
Name = x.Name,
City = x.City,
Phone = x.Phone,
Email = x.Email,
StreetAddress = x.StreetAddress,
Description = x.Description,
})
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,70 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Branch.Cqrs;
public class UpdateBranchRequest : CreateBranchRequest
{
public string? Id { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdateBranchResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdateBranchCommand(UpdateBranchRequest Data) : IRequest<UpdateBranchResponse>;
public class UpdateBranchHandler : IRequestHandler<UpdateBranchCommand, UpdateBranchResponse>
{
private readonly AppDbContext _context;
public UpdateBranchHandler(AppDbContext context) => _context = context;
public async Task<UpdateBranchResponse> Handle(UpdateBranchCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.Branch
.AnyAsync(x => x.Code == request.Data.Code && x.Id != request.Data.Id, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Branch", request.Data.Code ?? string.Empty);
}
var entity = await _context.Branch
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
return new UpdateBranchResponse { Id = request.Data.Id, Success = false };
}
entity.Code = request.Data.Code;
entity.Name = request.Data.Name;
entity.Description = request.Data.Description;
entity.StreetAddress = request.Data.StreetAddress;
entity.City = request.Data.City;
entity.StateProvince = request.Data.StateProvince;
entity.ZipCode = request.Data.ZipCode;
entity.Phone = request.Data.Phone;
entity.Email = request.Data.Email;
entity.OtherInformation1 = request.Data.OtherInformation1;
entity.OtherInformation2 = request.Data.OtherInformation2;
entity.OtherInformation3 = request.Data.OtherInformation3;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateBranchResponse
{
Id = entity.Id,
Success = true
};
}
}
@@ -0,0 +1,30 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Branch.Cqrs;
public class UpdateBranchValidator : AbstractValidator<UpdateBranchRequest>
{
public UpdateBranchValidator()
{
RuleFor(x => x.Id)
.NotEmpty().WithMessage("ID is required for update");
RuleFor(x => x.Code)
.NotEmpty().WithMessage("Branch Code is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Branch Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.City)
.NotEmpty().WithMessage("City is required");
RuleFor(x => x.StreetAddress)
.NotEmpty().WithMessage("Street Address is required");
RuleFor(x => x.Email)
.EmailAddress().When(x => !string.IsNullOrEmpty(x.Email));
}
}
@@ -0,0 +1,23 @@
@page "/organization/department"
@using Indotalent.Features.Organization.Department
@using Indotalent.Features.Organization.Department.Cqrs
@using MudBlazor
@if (_view == View.Create)
{
<_DepartmentCreateForm OnCancel="() => _view = View.Table" OnSuccess="() => _view = View.Table" />
}
else if (_view == View.Update || _view == View.Detail)
{
<_DepartmentUpdateForm Data="_data!" ReadOnly="@(_view == View.Detail)" OnCancel="() => _view = View.Table" OnSuccess="() => _view = View.Table" />
}
else
{
<_DepartmentDataTable OnAdd="() => _view = View.Create" OnEdit="d => { _data = d; _view = View.Update; }" OnView="d => { _data = d; _view = View.Detail; }" />
}
@code {
private enum View { Table, Create, Update, Detail }
private View _view = View.Table;
private UpdateDepartmentRequest? _data;
}
@@ -0,0 +1,93 @@
@using Indotalent.Features.Organization.Department
@using Indotalent.Features.Organization.Department.Cqrs
@using Indotalent.Shared.Utils
@using MudBlazor
@inject DepartmentService DepartmentService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Add New Department</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">Create a new department and assign a cost center.</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
<MudForm @ref="_form" Model="_model">
<MudGrid Spacing="3">
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Cost Center</MudText>
<MudTextField @bind-Value="_model.CostCenter" For="@(() => _model.CostCenter)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. CC-IT-01" />
</MudItem>
<MudItem xs="12" sm="8">
<MudText Typo="Typo.subtitle2" Class="mb-1">Department Name</MudText>
<MudTextField @bind-Value="_model.Name" For="@(() => _model.Name)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. Information Technology" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Head of Department</MudText>
<MudTextField @bind-Value="_model.HeadOfDeptartment" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 1</MudText>
<MudTextField @bind-Value="_model.OtherInformation1" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 2</MudText>
<MudTextField @bind-Value="_model.OtherInformation2" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 3</MudText>
<MudTextField @bind-Value="_model.OtherInformation3" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-8">
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">Cancel</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText>Create Department</MudText>
}
</MudButton>
</div>
</MudForm>
</MudPaper>
@code {
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm _form = default!;
private CreateDepartmentValidator _validator = new();
private CreateDepartmentRequest _model = new();
private bool _processing = false;
private async Task Submit()
{
await _form.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var response = await DepartmentService.CreateDepartmentAsync(_model);
await Task.Delay(500);
if (response != null && response.IsSuccess)
{
Snackbar.Add("Department created successfully", Severity.Success);
await OnSuccess.InvokeAsync();
}
}
finally { _processing = false; }
}
}
@@ -0,0 +1,373 @@
@using Indotalent.ConfigBackEnd.Extensions
@using Indotalent.Features.Organization.Department
@using Indotalent.Features.Organization.Department.Cqrs
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using MudBlazor
@using Features.Root.Shared
@using ClosedXML.Excel
@using System.IO
@inject DepartmentService DepartmentService
@inject IDialogService DialogService
@inject ISnackbar Snackbar
@inject IJSRuntime JSRuntime
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
<div>
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Department Management</MudText>
<MudText Typo="Typo.body2" Style="color: #9CA3AF; font-size: 0.75rem;">Manage organizational departments and team structures.</MudText>
</div>
<div class="d-flex align-center gap-2">
<MudIcon Icon="@Icons.Material.Filled.Home" Size="Size.Small" Color="Color.Default" />
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Organization</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Department</MudText>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
<div style="display: flex; align-items: center; gap: 8px;">
<MudTextField @bind-Value="_searchString"
Placeholder="Search..."
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search"
IconSize="Size.Small"
Class="mt-0"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Style="background-color: white; width: 280px; border-radius: 8px;"
OnKeyDown="@HandleSearchKeyDown" />
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
OnClick="OnSearchClick"
Size="Size.Small"
Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; box-shadow: none; background: #3B82F6; color: white;">
Search
</MudButton>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<MudButton Variant="Variant.Outlined"
Color="Color.Success"
OnClick="ExportToExcel"
Size="Size.Small"
Disabled="_isExporting"
StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)"
Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">
@if (_isExporting)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText>
}
</MudButton>
<MudButton Variant="Variant.Outlined"
Color="Color.Primary"
OnClick="LoadData"
Size="Size.Small"
StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)"
Disabled="_isRefreshing"
Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">
@if (_isRefreshing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText>
}
else
{
<MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText>
}
</MudButton>
@if (_selectedDept != null)
{
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">View</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">Edit</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="background: white; border: 1px solid #FCA5A5; color: #EF4444; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px;">Remove</MudButton>
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedDept = null" />
}
else
{
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; background: #3B82F6; color: white;">
Add New Department
</MudButton>
}
</div>
</div>
<MudTable Items="@GetPagedData()" Hover="true" Elevation="0" CustomHeader="true" Dense="true" Striped="true" Class="mud-table-styled" T="GetDepartmentListResponse" OnRowClick="@((args) => _selectedDept = args.Item)" Loading="@_isRefreshing">
<HeaderContent>
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetDepartmentListResponse, object>(x => x.AutoNumber!)">Department ID</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetDepartmentListResponse, object>(x => x.Name)">Department Name</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetDepartmentListResponse, object>(x => x.CostCenter!)">Cost Center</MudTableSortLabel>
</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudCheckBox T="bool" Value="@(_selectedDept?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudChip T="string" Size="Size.Small" Variant="Variant.Text" Style="background-color: #F9FAFB; color: #374151; font-weight: 600; border-radius: 4px;">@context.AutoNumber</MudChip>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<div class="d-flex align-center gap-2">
<MudAvatar Color="Color.Primary" Size="Size.Small" Style="width: 32px; height: 32px; font-weight: 700; font-size: 0.75rem;">@(!string.IsNullOrWhiteSpace(context.Name) ? context.Name.ToInitial() : "?")</MudAvatar>
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.Name</MudText>
</div>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudText Typo="Typo.body2" Style="color: #6B7280; font-size: 0.875rem;">@context.CostCenter</MudText>
</MudTd>
</RowTemplate>
</MudTable>
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
<div style="display: flex; align-items: center; gap: 12px;">
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
<MudSelect T="int"
Value="@_top"
ValueChanged="OnPageSizeChanged"
Dense="true"
Margin="Margin.Dense"
Style="width: 80px; background-color: white; font-size: 12px; font-weight: 600;"
Variant="Variant.Outlined"
Class="mt-0 custom-select-dense">
<MudSelectItem Value="5" />
<MudSelectItem Value="10" />
<MudSelectItem Value="50" />
<MudSelectItem Value="500" />
<MudSelectItem Value="1000" />
</MudSelect>
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem; margin-left: 12px;">
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
</MudText>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" Class="rounded-0" />
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="@(_currentPage == 1 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #6B7280; border: 1px solid #D1D5DB; border-radius: 6px;")">Prev</MudButton>
@{
var totalPages = _totalPage == 0 ? 1 : _totalPage;
var maxVisible = 5;
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
}
@for (int i = startPage; i <= endPage; i++)
{
var pageNum = i;
var isActive = pageNum == _currentPage;
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
Variant="Variant.Text" Size="Size.Small"
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
}
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #6B7280; border: 1px solid #D1D5DB; border-radius: 6px;")">Next</MudButton>
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" Class="rounded-0" />
</div>
</div>
</MudPaper>
<script>
function downloadFile(fileName, contentType, base64String) {
const link = document.createElement('a');
link.download = fileName;
link.href = `data:${contentType};base64,${base64String}`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
</script>
<style>
.mud-input-outlined-border { border-radius: 0px !important; }
.custom-select-dense .mud-input-control { margin-top: 0 !important; }
.custom-select-dense .mud-input-slot { padding-top: 4px !important; padding-bottom: 4px !important; padding-left: 8px !important; font-size: 12px !important; }
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
</style>
@code {
[Parameter] public EventCallback OnAdd { get; set; }
[Parameter] public EventCallback<UpdateDepartmentRequest> OnEdit { get; set; }
[Parameter] public EventCallback<UpdateDepartmentRequest> OnView { get; set; }
private List<GetDepartmentListResponse> _departments = new();
private GetDepartmentListResponse? _selectedDept;
private string _searchString = "";
private int _skip = 0;
private int _top = 5;
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
private bool _isRefreshing = false;
private bool _isExporting = false;
protected override async Task OnInitializedAsync() => await LoadData();
private async Task LoadData()
{
_isRefreshing = true; _selectedDept = null;
StateHasChanged();
try
{
var response = await DepartmentService.GetDepartmentListAsync();
await Task.Delay(500);
if (response != null && response.IsSuccess)
{
_departments = response.Value ?? new();
}
}
finally
{
_isRefreshing = false;
StateHasChanged();
}
}
private IEnumerable<GetDepartmentListResponse> GetFilteredData()
{
if (string.IsNullOrWhiteSpace(_searchString)) return _departments;
return _departments.Where(x =>
(x.Name?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.CostCenter?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
);
}
private IEnumerable<GetDepartmentListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
private async Task ExportToExcel()
{
_isExporting = true;
StateHasChanged();
try
{
await Task.Delay(1000);
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.Worksheets.Add("Departments");
var currentRow = 1;
worksheet.Cell(currentRow, 1).Value = "Auto Number";
worksheet.Cell(currentRow, 2).Value = "Department Name";
worksheet.Cell(currentRow, 3).Value = "Cost Center";
var headerRange = worksheet.Range(1, 1, 1, 3);
headerRange.Style.Font.Bold = true;
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#0D47A1");
headerRange.Style.Font.FontColor = XLColor.White;
foreach (var item in GetFilteredData())
{
currentRow++;
worksheet.Cell(currentRow, 1).Value = item.AutoNumber;
worksheet.Cell(currentRow, 2).Value = item.Name;
worksheet.Cell(currentRow, 3).Value = item.CostCenter;
}
worksheet.Columns().AdjustToContents();
using (var stream = new MemoryStream())
{
workbook.SaveAs(stream);
var content = Convert.ToBase64String(stream.ToArray());
await JSRuntime.InvokeVoidAsync("downloadFile", "Department_Registry.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
Snackbar.Add("Excel exported successfully", Severity.Success);
}
}
}
catch (Exception ex)
{
Snackbar.Add($"Export failed: {ex.Message}", Severity.Error);
}
finally
{
_isExporting = false;
StateHasChanged();
}
}
private void OnSearchClick()
{
_skip = 0;
_selectedDept = null;
StateHasChanged();
}
private void HandleSearchKeyDown(KeyboardEventArgs e)
{
if (e.Key == "Enter") OnSearchClick();
}
private void OnPageChanged(int page)
{
if (page >= 1 && page <= _totalPage)
{
_skip = (page - 1) * _top;
_selectedDept = null;
StateHasChanged();
}
}
private void OnPageSizeChanged(int size)
{
_top = size;
_skip = 0;
_selectedDept = null;
StateHasChanged();
}
private async Task InvokeEdit()
{
if (_selectedDept == null) return;
var res = await DepartmentService.GetDepartmentByIdAsync(_selectedDept.Id);
if (res?.Value != null) await OnEdit.InvokeAsync(MapToUpdate(res.Value));
}
private async Task InvokeView()
{
if (_selectedDept == null) return;
var res = await DepartmentService.GetDepartmentByIdAsync(_selectedDept.Id);
if (res?.Value != null) await OnView.InvokeAsync(MapToUpdate(res.Value));
}
private UpdateDepartmentRequest MapToUpdate(GetDepartmentByIdResponse d) => new UpdateDepartmentRequest
{
CostCenter = d.CostCenter,
Name = d.Name,
Description = d.Description,
HeadOfDeptartment = d.HeadOfDeptartment ?? string.Empty,
OtherInformation1 = d.OtherInformation1 ?? string.Empty,
OtherInformation2 = d.OtherInformation2 ?? string.Empty,
OtherInformation3 = d.OtherInformation3 ?? string.Empty
};
private async Task OnDelete()
{
if (_selectedDept == null) return;
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedDept.Name } });
if (!(await dialog.Result).Canceled)
{
if (await DepartmentService.DeleteDepartmentByIdAsync(_selectedDept.Id))
{
await LoadData(); Snackbar.Add("Department deleted successfully", Severity.Success);
}
}
}
}
@@ -0,0 +1,132 @@
@using Indotalent.ConfigBackEnd.Extensions
@using Indotalent.Features.Organization.Department
@using Indotalent.Features.Organization.Department.Cqrs
@using Indotalent.Shared.Utils
@using MudBlazor
@inject DepartmentService DepartmentService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Department Details" : "Edit Department")</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing department profile." : "Modify department information.")</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
<MudForm @ref="_form" Model="_model">
<MudGrid Spacing="3">
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Cost Center</MudText>
<MudTextField @bind-Value="_model.CostCenter" For="@(() => _model.CostCenter)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="8">
<MudText Typo="Typo.subtitle2" Class="mb-1">Department Name</MudText>
<MudTextField @bind-Value="_model.Name" For="@(() => _model.Name)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Head of Department</MudText>
<MudTextField @bind-Value="_model.HeadOfDeptartment" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
<MudTextField @bind-Value="_model.Description" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 1</MudText>
<MudTextField @bind-Value="_model.OtherInformation1" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 2</MudText>
<MudTextField @bind-Value="_model.OtherInformation2" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 3</MudText>
<MudTextField @bind-Value="_model.OtherInformation3" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" Class="mt-4">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Audit History</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Created At</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.CreatedAt)</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Created By</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System")</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Last Updated At</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.UpdatedAt)</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Last Updated By</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System")</MudText>
</MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-10">
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">@(ReadOnly ? "Back to List" : "Cancel")</MudButton>
@if (!ReadOnly)
{
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2">Updating...</MudText>
}
else
{
<MudText>Save Changes</MudText>
}
</MudButton>
}
</div>
</MudForm>
</MudPaper>
@code {
[Parameter] public UpdateDepartmentRequest Data { get; set; } = new();
[Parameter] public bool ReadOnly { get; set; } = false;
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm _form = default!;
private UpdateDepartmentValidator _validator = new();
private UpdateDepartmentRequest _model = new();
private bool _processing = false;
protected override void OnInitialized() => _model = new UpdateDepartmentRequest
{
Id = Data.Id,
CostCenter = Data.CostCenter,
Name = Data.Name,
Description = Data.Description,
HeadOfDeptartment = Data.HeadOfDeptartment,
OtherInformation1 = Data.OtherInformation1,
OtherInformation2 = Data.OtherInformation2,
OtherInformation3 = Data.OtherInformation3,
CreatedAt = Data.CreatedAt,
CreatedBy = Data.CreatedBy,
UpdatedAt = Data.UpdatedAt,
UpdatedBy = Data.UpdatedBy
};
private async Task Submit()
{
await _form.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var response = await DepartmentService.UpdateDepartmentAsync(_model);
await Task.Delay(500);
if (response != null && response.IsSuccess) { Snackbar.Add("Updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); }
}
finally { _processing = false; }
}
}
@@ -0,0 +1,73 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Department.Cqrs;
public class CreateDepartmentRequest
{
public string? CostCenter { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string HeadOfDeptartment { get; set; } = string.Empty;
public string OtherInformation1 { get; set; } = string.Empty;
public string OtherInformation2 { get; set; } = string.Empty;
public string OtherInformation3 { get; set; } = string.Empty;
}
public class CreateDepartmentResponse
{
public string? Id { get; set; }
public string? CostCenter { get; set; }
}
public record CreateDepartmentCommand(CreateDepartmentRequest Data) : IRequest<CreateDepartmentResponse>;
public class CreateDepartmentHandler : IRequestHandler<CreateDepartmentCommand, CreateDepartmentResponse>
{
private readonly AppDbContext _context;
public CreateDepartmentHandler(AppDbContext context) => _context = context;
public async Task<CreateDepartmentResponse> Handle(CreateDepartmentCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.Department
.AnyAsync(x => x.CostCenter == request.Data.CostCenter, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Department", request.Data.CostCenter ?? string.Empty);
}
var entityName = nameof(Data.Entities.Department);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.Department
{
AutoNumber = autoNo,
CostCenter = request.Data.CostCenter,
Name = request.Data.Name,
Description = request.Data.Description,
HeadOfDeptartment = request.Data.HeadOfDeptartment,
OtherInformation1 = request.Data.OtherInformation1,
OtherInformation2 = request.Data.OtherInformation2,
OtherInformation3 = request.Data.OtherInformation3
};
_context.Department.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateDepartmentResponse
{
Id = entity.Id,
CostCenter = entity.CostCenter
};
}
}
@@ -0,0 +1,21 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Department.Cqrs;
public class CreateDepartmentValidator : AbstractValidator<CreateDepartmentRequest>
{
public CreateDepartmentValidator()
{
RuleFor(x => x.CostCenter)
.NotEmpty().WithMessage("Cost Center is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Department Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.HeadOfDeptartment)
.MaximumLength(GlobalConsts.StringLengthShort);
}
}
@@ -0,0 +1,26 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Department.Cqrs;
public record DeleteDepartmentByIdRequest(string Id);
public record DeleteDepartmentByIdCommand(DeleteDepartmentByIdRequest Data) : IRequest<bool>;
public class DeleteDepartmentByIdHandler : IRequestHandler<DeleteDepartmentByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteDepartmentByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteDepartmentByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Department
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.Department.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,55 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Department.Cqrs;
public class GetDepartmentByIdResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? CostCenter { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? HeadOfDeptartment { get; set; }
public string? OtherInformation1 { get; set; }
public string? OtherInformation2 { get; set; }
public string? OtherInformation3 { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetDepartmentByIdQuery(string Id) : IRequest<GetDepartmentByIdResponse?>;
public class GetDepartmentByIdHandler : IRequestHandler<GetDepartmentByIdQuery, GetDepartmentByIdResponse?>
{
private readonly AppDbContext _context;
public GetDepartmentByIdHandler(AppDbContext context) => _context = context;
public async Task<GetDepartmentByIdResponse?> Handle(GetDepartmentByIdQuery request, CancellationToken cancellationToken)
{
return await _context.Department
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetDepartmentByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
CostCenter = x.CostCenter,
Name = x.Name,
Description = x.Description,
HeadOfDeptartment = x.HeadOfDeptartment,
OtherInformation1 = x.OtherInformation1,
OtherInformation2 = x.OtherInformation2,
OtherInformation3 = x.OtherInformation3,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,43 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Department.Cqrs;
public class GetDepartmentListResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? CostCenter { get; set; }
public string? Name { get; set; }
public string? HeadOfDeptartment { get; set; }
public string? Description { get; set; }
}
public record GetDepartmentListQuery() : IRequest<List<GetDepartmentListResponse>>;
public class GetDepartmentListHandler : IRequestHandler<GetDepartmentListQuery, List<GetDepartmentListResponse>>
{
private readonly AppDbContext _context;
public GetDepartmentListHandler(AppDbContext context) => _context = context;
public async Task<List<GetDepartmentListResponse>> Handle(GetDepartmentListQuery request, CancellationToken cancellationToken)
{
return await _context.Department
.AsNoTracking()
.NotDeletedOnly()
.OrderBy(x => x.CostCenter)
.Select(x => new GetDepartmentListResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
CostCenter = x.CostCenter,
Name = x.Name,
HeadOfDeptartment = x.HeadOfDeptartment,
Description = x.Description,
})
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,61 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Department.Cqrs;
public class UpdateDepartmentRequest : CreateDepartmentRequest
{
public string? Id { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdateDepartmentResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdateDepartmentCommand(UpdateDepartmentRequest Data) : IRequest<UpdateDepartmentResponse>;
public class UpdateDepartmentHandler : IRequestHandler<UpdateDepartmentCommand, UpdateDepartmentResponse>
{
private readonly AppDbContext _context;
public UpdateDepartmentHandler(AppDbContext context) => _context = context;
public async Task<UpdateDepartmentResponse> Handle(UpdateDepartmentCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.Department
.AnyAsync(x => x.CostCenter == request.Data.CostCenter && x.Id != request.Data.Id, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Department", request.Data.CostCenter ?? string.Empty);
}
var entity = await _context.Department
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
return new UpdateDepartmentResponse { Id = request.Data.Id, Success = false };
}
entity.CostCenter = request.Data.CostCenter;
entity.Name = request.Data.Name;
entity.Description = request.Data.Description;
entity.HeadOfDeptartment = request.Data.HeadOfDeptartment;
entity.OtherInformation1 = request.Data.OtherInformation1;
entity.OtherInformation2 = request.Data.OtherInformation2;
entity.OtherInformation3 = request.Data.OtherInformation3;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateDepartmentResponse { Id = entity.Id, Success = true };
}
}
@@ -0,0 +1,14 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Department.Cqrs;
public class UpdateDepartmentValidator : AbstractValidator<UpdateDepartmentRequest>
{
public UpdateDepartmentValidator()
{
RuleFor(x => x.Id).NotEmpty().WithMessage("ID is required");
RuleFor(x => x.CostCenter).NotEmpty().MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Name).NotEmpty().MaximumLength(GlobalConsts.StringLengthShort);
}
}
@@ -0,0 +1,30 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Features.Organization.Department.Cqrs;
using MediatR;
using Microsoft.AspNetCore.Authentication.JwtBearer;
namespace Indotalent.Features.Organization.Department;
public static class DepartmentEndpoint
{
public static void MapDepartmentEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("/department").WithTags("Departments")
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme).RequireAuthenticatedUser());
group.MapGet("/", async (IMediator mediator) =>
(await mediator.Send(new GetDepartmentListQuery())).ToApiResponse("Data retrieved"));
group.MapGet("/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new GetDepartmentByIdQuery(id))).ToApiResponse("Detail retrieved"));
group.MapPost("/", async (CreateDepartmentRequest request, IMediator mediator) =>
(await mediator.Send(new CreateDepartmentCommand(request))).ToApiResponse("Created", StatusCodes.Status201Created));
group.MapPost("/update", async (UpdateDepartmentRequest request, IMediator mediator) =>
(await mediator.Send(new UpdateDepartmentCommand(request))).ToApiResponse("Updated"));
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new DeleteDepartmentByIdCommand(new DeleteDepartmentByIdRequest(id)))).ToApiResponse("Deleted"));
}
}
@@ -0,0 +1,54 @@
using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Organization.Department.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;
namespace Indotalent.Features.Organization.Department;
public class DepartmentService : BaseService
{
private readonly RestClient _client;
public DepartmentService(IHttpClientFactory clientFactory, NavigationManager nav, ISnackbar snackbar, ICurrentUserService currentUserService, TokenProvider tokenProvider)
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
{
_client = new RestClient(nav.BaseUri);
}
public async Task<ApiResponse<List<GetDepartmentListResponse>>?> GetDepartmentListAsync()
{
var request = new RestRequest("api/department", Method.Get);
return await ExecuteWithResponseAsync<List<GetDepartmentListResponse>>(_client, request);
}
public async Task<ApiResponse<GetDepartmentByIdResponse>?> GetDepartmentByIdAsync(string id)
{
var request = new RestRequest($"api/department/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetDepartmentByIdResponse>(_client, request);
}
public async Task<ApiResponse<CreateDepartmentResponse>?> CreateDepartmentAsync(CreateDepartmentRequest data)
{
var request = new RestRequest("api/department", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreateDepartmentResponse>(_client, request);
}
public async Task<ApiResponse<UpdateDepartmentResponse>?> UpdateDepartmentAsync(UpdateDepartmentRequest data)
{
var request = new RestRequest("api/department/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdateDepartmentResponse>(_client, request);
}
public async Task<bool> DeleteDepartmentByIdAsync(string id)
{
var request = new RestRequest($"api/department/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
}
@@ -0,0 +1,25 @@
@page "/organization/designation"
@using Indotalent.Features.Organization.Designation
@using Indotalent.Features.Organization.Designation.Cqrs
@using MudBlazor
@if (_view == View.Create)
{
<_DesignationCreateForm OnCancel="() => _view = View.Table" OnSuccess="() => _view = View.Table" />
}
else if (_view == View.Update || _view == View.Detail)
{
<_DesignationUpdateForm Data="_data!" ReadOnly="@(_view == View.Detail)" OnCancel="() => _view = View.Table" OnSuccess="() => _view = View.Table" />
}
else
{
<_DesignationDataTable OnAdd="() => _view = View.Create"
OnEdit="d => { _data = d; _view = View.Update; }"
OnView="d => { _data = d; _view = View.Detail; }" />
}
@code {
private enum View { Table, Create, Update, Detail }
private View _view = View.Table;
private UpdateDesignationRequest? _data;
}
@@ -0,0 +1,93 @@
@using Indotalent.Features.Organization.Designation
@using Indotalent.Features.Organization.Designation.Cqrs
@using Indotalent.Shared.Utils
@using MudBlazor
@inject DesignationService DesignationService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Add New Designation</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">Create a new job title and career level.</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
<MudForm @ref="_form" Model="_model">
<MudGrid Spacing="3">
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Designation Code</MudText>
<MudTextField @bind-Value="_model.Code" For="@(() => _model.Code)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. M-001" />
</MudItem>
<MudItem xs="12" sm="8">
<MudText Typo="Typo.subtitle2" Class="mb-1">Designation Name</MudText>
<MudTextField @bind-Value="_model.Name" For="@(() => _model.Name)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. Software Engineering Manager" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Career Level</MudText>
<MudTextField @bind-Value="_model.Level" For="@(() => _model.Level)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. Management" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 1</MudText>
<MudTextField @bind-Value="_model.OtherInformation1" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 2</MudText>
<MudTextField @bind-Value="_model.OtherInformation2" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 3</MudText>
<MudTextField @bind-Value="_model.OtherInformation3" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-8">
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">Cancel</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText>Create Designation</MudText>
}
</MudButton>
</div>
</MudForm>
</MudPaper>
@code {
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm _form = default!;
private CreateDesignationValidator _validator = new();
private CreateDesignationRequest _model = new();
private bool _processing = false;
private async Task Submit()
{
await _form.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var response = await DesignationService.CreateDesignationAsync(_model);
await Task.Delay(500);
if (response != null && response.IsSuccess)
{
Snackbar.Add("Designation created successfully", Severity.Success);
await OnSuccess.InvokeAsync();
}
}
finally { _processing = false; }
}
}
@@ -0,0 +1,389 @@
@using Indotalent.ConfigBackEnd.Extensions
@using Indotalent.Features.Organization.Designation
@using Indotalent.Features.Organization.Designation.Cqrs
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using MudBlazor
@using Features.Root.Shared
@using ClosedXML.Excel
@using System.IO
@inject DesignationService DesignationService
@inject IDialogService DialogService
@inject ISnackbar Snackbar
@inject IJSRuntime JSRuntime
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
<div>
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Designation Management</MudText>
<MudText Typo="Typo.body2" Style="color: #9CA3AF; font-size: 0.75rem;">Manage job titles, hierarchies, and official designations across the organization.</MudText>
</div>
<div class="d-flex align-center gap-2">
<MudIcon Icon="@Icons.Material.Filled.Home" Size="Size.Small" Color="Color.Default" />
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Organization</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Designation</MudText>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
<div style="display: flex; align-items: center; gap: 8px;">
<MudTextField @bind-Value="_searchString"
Placeholder="Search..."
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search"
IconSize="Size.Small"
Class="mt-0"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Style="background-color: white; width: 280px; border-radius: 8px;"
OnKeyDown="@HandleSearchKeyDown" />
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
OnClick="OnSearchClick"
Size="Size.Small"
Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; box-shadow: none; background: #3B82F6; color: white;">
Search
</MudButton>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<MudButton Variant="Variant.Outlined"
Color="Color.Success"
OnClick="ExportToExcel"
Size="Size.Small"
Disabled="_isExporting"
StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)"
Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">
@if (_isExporting)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText>
}
</MudButton>
<MudButton Variant="Variant.Outlined"
Color="Color.Primary"
OnClick="LoadData"
Size="Size.Small"
StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)"
Disabled="_isRefreshing"
Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">
@if (_isRefreshing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText>
}
else
{
<MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText>
}
</MudButton>
@if (_selectedDesig != null)
{
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">View</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">Edit</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="background: white; border: 1px solid #FCA5A5; color: #EF4444; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px;">Remove</MudButton>
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedDesig = null" />
}
else
{
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; background: #3B82F6; color: white;">
Add New Designation
</MudButton>
}
</div>
</div>
<MudTable Items="@GetPagedData()" Hover="true" Elevation="0" CustomHeader="true" Dense="true" Striped="true" Class="mud-table-styled" T="GetDesignationListResponse" OnRowClick="@((args) => _selectedDesig = args.Item)" Loading="@_isRefreshing">
<HeaderContent>
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetDesignationListResponse, object>(x => x.Code)">Code</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetDesignationListResponse, object>(x => x.Name)">Designation Name</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetDesignationListResponse, object>(x => x.Level)">Level</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetDesignationListResponse, object>(x => x.Description)">Job Description Brief</MudTableSortLabel>
</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudCheckBox T="bool" Value="@(_selectedDesig?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudChip T="string" Size="Size.Small" Variant="Variant.Text" Style="background-color: #F9FAFB; color: #374151; font-weight: 600; border-radius: 4px;">
@context.Code
</MudChip>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<div class="d-flex align-center gap-2">
<MudAvatar Color="Color.Info" Size="Size.Small" Style="width: 32px; height: 32px; font-weight: 700; font-size: 0.75rem;">@(!string.IsNullOrWhiteSpace(context.Name) ? context.Name.ToInitial() : "?")</MudAvatar>
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.Name</MudText>
</div>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #6B7280; font-size: 0.875rem;">@context.Level</MudText>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudText Typo="Typo.body2" Style="color: #6B7280; font-size: 0.875rem;">@context.Description</MudText>
</MudTd>
</RowTemplate>
</MudTable>
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
<div style="display: flex; align-items: center; gap: 12px;">
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
<MudSelect T="int"
Value="@_top"
ValueChanged="OnPageSizeChanged"
Dense="true"
Margin="Margin.Dense"
Style="width: 80px; background-color: white; font-size: 12px; font-weight: 600;"
Variant="Variant.Outlined"
Class="mt-0 custom-select-dense">
<MudSelectItem Value="5" />
<MudSelectItem Value="10" />
<MudSelectItem Value="50" />
<MudSelectItem Value="500" />
<MudSelectItem Value="1000" />
</MudSelect>
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem; margin-left: 12px;">
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
</MudText>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" Class="rounded-0" />
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="@(_currentPage == 1 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #6B7280; border: 1px solid #D1D5DB; border-radius: 6px;")">Prev</MudButton>
@{
var totalPages = _totalPage == 0 ? 1 : _totalPage;
var maxVisible = 5;
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
}
@for (int i = startPage; i <= endPage; i++)
{
var pageNum = i;
var isActive = pageNum == _currentPage;
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
Variant="Variant.Text" Size="Size.Small"
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
}
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #6B7280; border: 1px solid #D1D5DB; border-radius: 6px;")">Next</MudButton>
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" Class="rounded-0" />
</div>
</div>
</MudPaper>
<script>
function downloadFile(fileName, contentType, base64String) {
const link = document.createElement('a');
link.download = fileName;
link.href = `data:${contentType};base64,${base64String}`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
</script>
<style>
.mud-input-outlined-border { border-radius: 0px !important; }
.custom-select-dense .mud-input-control { margin-top: 0 !important; }
.custom-select-dense .mud-input-slot { padding-top: 4px !important; padding-bottom: 4px !important; padding-left: 8px !important; font-size: 12px !important; }
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
</style>
@code {
[Parameter] public EventCallback OnAdd { get; set; }
[Parameter] public EventCallback<UpdateDesignationRequest> OnEdit { get; set; }
[Parameter] public EventCallback<UpdateDesignationRequest> OnView { get; set; }
private List<GetDesignationListResponse> _designations = new();
private GetDesignationListResponse? _selectedDesig;
private string _searchString = "";
private int _skip = 0;
private int _top = 5;
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
private bool _isRefreshing = false;
private bool _isExporting = false;
protected override async Task OnInitializedAsync() => await LoadData();
private async Task LoadData()
{
_isRefreshing = true; _selectedDesig = null;
StateHasChanged();
try
{
var response = await DesignationService.GetDesignationListAsync();
await Task.Delay(500);
if (response != null && response.IsSuccess)
{
_designations = response.Value ?? new();
}
}
finally
{
_isRefreshing = false;
StateHasChanged();
}
}
private IEnumerable<GetDesignationListResponse> GetFilteredData()
{
if (string.IsNullOrWhiteSpace(_searchString)) return _designations;
return _designations.Where(x =>
(x.Name?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.Code?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.Level?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.Description?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
);
}
private IEnumerable<GetDesignationListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
private async Task ExportToExcel()
{
_isExporting = true;
StateHasChanged();
try
{
await Task.Delay(1000);
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.Worksheets.Add("Designations");
var currentRow = 1;
worksheet.Cell(currentRow, 1).Value = "Code";
worksheet.Cell(currentRow, 2).Value = "Designation Name";
worksheet.Cell(currentRow, 3).Value = "Level";
worksheet.Cell(currentRow, 4).Value = "Description";
var headerRange = worksheet.Range(1, 1, 1, 4);
headerRange.Style.Font.Bold = true;
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#0D47A1");
headerRange.Style.Font.FontColor = XLColor.White;
foreach (var item in GetFilteredData())
{
currentRow++;
worksheet.Cell(currentRow, 1).Value = item.Code;
worksheet.Cell(currentRow, 2).Value = item.Name;
worksheet.Cell(currentRow, 3).Value = item.Level;
worksheet.Cell(currentRow, 4).Value = item.Description;
}
worksheet.Columns().AdjustToContents();
using (var stream = new MemoryStream())
{
workbook.SaveAs(stream);
var content = Convert.ToBase64String(stream.ToArray());
await JSRuntime.InvokeVoidAsync("downloadFile", "Designation_Registry.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
Snackbar.Add("Excel exported successfully", Severity.Success);
}
}
}
catch (Exception ex)
{
Snackbar.Add($"Export failed: {ex.Message}", Severity.Error);
}
finally
{
_isExporting = false;
StateHasChanged();
}
}
private void OnSearchClick()
{
_skip = 0;
_selectedDesig = null;
StateHasChanged();
}
private void HandleSearchKeyDown(KeyboardEventArgs e)
{
if (e.Key == "Enter") OnSearchClick();
}
private void OnPageChanged(int page)
{
if (page >= 1 && page <= _totalPage)
{
_skip = (page - 1) * _top;
_selectedDesig = null;
StateHasChanged();
}
}
private void OnPageSizeChanged(int size)
{
_top = size;
_skip = 0;
_selectedDesig = null;
StateHasChanged();
}
private async Task InvokeEdit()
{
if (_selectedDesig == null) return;
var res = await DesignationService.GetDesignationByIdAsync(_selectedDesig.Id);
if (res?.Value != null) await OnEdit.InvokeAsync(Map(res.Value));
}
private async Task InvokeView()
{
if (_selectedDesig == null) return;
var res = await DesignationService.GetDesignationByIdAsync(_selectedDesig.Id);
if (res?.Value != null) await OnView.InvokeAsync(Map(res.Value));
}
private UpdateDesignationRequest Map(GetDesignationByIdResponse d) => new UpdateDesignationRequest
{
Id = d.Id,
Code = d.Code,
Name = d.Name,
Description = d.Description,
Level = d.Level,
OtherInformation1 = d.OtherInformation1 ?? string.Empty,
OtherInformation2 = d.OtherInformation2 ?? string.Empty,
OtherInformation3 = d.OtherInformation3 ?? string.Empty,
CreatedAt = d.CreatedAt,
CreatedBy = d.CreatedBy,
UpdatedAt = d.UpdatedAt,
UpdatedBy = d.UpdatedBy
};
private async Task OnDelete()
{
if (_selectedDesig == null) return;
var diag = await DialogService.ShowAsync<_DeleteConfirmation>("", new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedDesig.Name } });
if (!(await diag.Result).Canceled)
{
if (await DesignationService.DeleteDesignationByIdAsync(_selectedDesig.Id))
{
await LoadData(); Snackbar.Add("Designation deleted successfully", Severity.Success);
}
}
}
}
@@ -0,0 +1,132 @@
@using Indotalent.ConfigBackEnd.Extensions
@using Indotalent.Features.Organization.Designation
@using Indotalent.Features.Organization.Designation.Cqrs
@using Indotalent.Shared.Utils
@using MudBlazor
@inject DesignationService DesignationService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Designation Details" : "Edit Designation")</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing designation profile." : "Modify existing designation information.")</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
<MudForm @ref="_form" Model="_model">
<MudGrid Spacing="3">
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Designation Code</MudText>
<MudTextField @bind-Value="_model.Code" For="@(() => _model.Code)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="8">
<MudText Typo="Typo.subtitle2" Class="mb-1">Designation Name</MudText>
<MudTextField @bind-Value="_model.Name" For="@(() => _model.Name)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Career Level</MudText>
<MudTextField @bind-Value="_model.Level" For="@(() => _model.Level)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
<MudTextField @bind-Value="_model.Description" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 1</MudText>
<MudTextField @bind-Value="_model.OtherInformation1" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 2</MudText>
<MudTextField @bind-Value="_model.OtherInformation2" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudText Typo="Typo.subtitle2" Class="mb-1">Other Information 3</MudText>
<MudTextField @bind-Value="_model.OtherInformation3" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" Class="mt-4">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Audit History</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Created At</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.CreatedAt)</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Created By</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System")</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Last Updated At</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.UpdatedAt)</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Last Updated By</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System")</MudText>
</MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-10">
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">@(ReadOnly ? "Back to List" : "Cancel")</MudButton>
@if (!ReadOnly)
{
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2">Updating...</MudText>
}
else
{
<MudText>Save Changes</MudText>
}
</MudButton>
}
</div>
</MudForm>
</MudPaper>
@code {
[Parameter] public UpdateDesignationRequest Data { get; set; } = new();
[Parameter] public bool ReadOnly { get; set; } = false;
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm _form = default!;
private UpdateDesignationValidator _validator = new();
private UpdateDesignationRequest _model = new();
private bool _processing = false;
protected override void OnInitialized() => _model = new UpdateDesignationRequest
{
Id = Data.Id,
Code = Data.Code,
Name = Data.Name,
Description = Data.Description,
Level = Data.Level,
OtherInformation1 = Data.OtherInformation1,
OtherInformation2 = Data.OtherInformation2,
OtherInformation3 = Data.OtherInformation3,
CreatedAt = Data.CreatedAt,
CreatedBy = Data.CreatedBy,
UpdatedAt = Data.UpdatedAt,
UpdatedBy = Data.UpdatedBy
};
private async Task Submit()
{
await _form.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var response = await DesignationService.UpdateDesignationAsync(_model);
await Task.Delay(500);
if (response != null && response.IsSuccess) { Snackbar.Add("Updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); }
}
finally { _processing = false; }
}
}
@@ -0,0 +1,73 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Designation.Cqrs;
public class CreateDesignationRequest
{
public string? Code { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? Level { get; set; }
public string OtherInformation1 { get; set; } = string.Empty;
public string OtherInformation2 { get; set; } = string.Empty;
public string OtherInformation3 { get; set; } = string.Empty;
}
public class CreateDesignationResponse
{
public string? Id { get; set; }
public string? Code { get; set; }
}
public record CreateDesignationCommand(CreateDesignationRequest Data) : IRequest<CreateDesignationResponse>;
public class CreateDesignationHandler : IRequestHandler<CreateDesignationCommand, CreateDesignationResponse>
{
private readonly AppDbContext _context;
public CreateDesignationHandler(AppDbContext context) => _context = context;
public async Task<CreateDesignationResponse> Handle(CreateDesignationCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.Designation
.AnyAsync(x => x.Code == request.Data.Code, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Designation", request.Data.Code ?? string.Empty);
}
var entityName = nameof(Data.Entities.Designation);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.Designation
{
AutoNumber = autoNo,
Code = request.Data.Code,
Name = request.Data.Name,
Description = request.Data.Description,
Level = request.Data.Level,
OtherInformation1 = request.Data.OtherInformation1,
OtherInformation2 = request.Data.OtherInformation2,
OtherInformation3 = request.Data.OtherInformation3
};
_context.Designation.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateDesignationResponse
{
Id = entity.Id,
Code = entity.Code
};
}
}
@@ -0,0 +1,21 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Designation.Cqrs;
public class CreateDesignationValidator : AbstractValidator<CreateDesignationRequest>
{
public CreateDesignationValidator()
{
RuleFor(x => x.Code)
.NotEmpty().WithMessage("Designation Code is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Designation Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Level)
.NotEmpty().WithMessage("Level is required");
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Designation.Cqrs;
public record DeleteDesignationByIdRequest(string Id);
public record DeleteDesignationByIdCommand(DeleteDesignationByIdRequest Data) : IRequest<bool>;
public class DeleteDesignationByIdHandler : IRequestHandler<DeleteDesignationByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteDesignationByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteDesignationByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Designation
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.Designation.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,55 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Designation.Cqrs;
public class GetDesignationByIdResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? Code { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? Level { get; set; }
public string? OtherInformation1 { get; set; }
public string? OtherInformation2 { get; set; }
public string? OtherInformation3 { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetDesignationByIdQuery(string Id) : IRequest<GetDesignationByIdResponse?>;
public class GetDesignationByIdHandler : IRequestHandler<GetDesignationByIdQuery, GetDesignationByIdResponse?>
{
private readonly AppDbContext _context;
public GetDesignationByIdHandler(AppDbContext context) => _context = context;
public async Task<GetDesignationByIdResponse?> Handle(GetDesignationByIdQuery request, CancellationToken cancellationToken)
{
return await _context.Designation
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetDesignationByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Code = x.Code,
Name = x.Name,
Description = x.Description,
Level = x.Level,
OtherInformation1 = x.OtherInformation1,
OtherInformation2 = x.OtherInformation2,
OtherInformation3 = x.OtherInformation3,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,43 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Designation.Cqrs;
public class GetDesignationListResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? Code { get; set; }
public string? Name { get; set; }
public string? Level { get; set; }
public string? Description { get; set; }
}
public record GetDesignationListQuery() : IRequest<List<GetDesignationListResponse>>;
public class GetDesignationListHandler : IRequestHandler<GetDesignationListQuery, List<GetDesignationListResponse>>
{
private readonly AppDbContext _context;
public GetDesignationListHandler(AppDbContext context) => _context = context;
public async Task<List<GetDesignationListResponse>> Handle(GetDesignationListQuery request, CancellationToken cancellationToken)
{
return await _context.Designation
.AsNoTracking()
.NotDeletedOnly()
.OrderBy(x => x.Code)
.Select(x => new GetDesignationListResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Code = x.Code,
Name = x.Name,
Level = x.Level,
Description = x.Description,
})
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,62 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Designation.Cqrs;
public class UpdateDesignationRequest : CreateDesignationRequest
{
public string? Id { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdateDesignationResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdateDesignationCommand(UpdateDesignationRequest Data) : IRequest<UpdateDesignationResponse>;
public class UpdateDesignationHandler : IRequestHandler<UpdateDesignationCommand, UpdateDesignationResponse>
{
private readonly AppDbContext _context;
public UpdateDesignationHandler(AppDbContext context) => _context = context;
public async Task<UpdateDesignationResponse> Handle(UpdateDesignationCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Designation
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return new UpdateDesignationResponse { Id = request.Data.Id, Success = false };
var isExists = await _context.Designation
.AnyAsync(x => x.Code == request.Data.Code && x.Id != request.Data.Id, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Designation", request.Data.Code ?? string.Empty);
}
entity.Code = request.Data.Code;
entity.Name = request.Data.Name;
entity.Description = request.Data.Description;
entity.Level = request.Data.Level;
entity.OtherInformation1 = request.Data.OtherInformation1;
entity.OtherInformation2 = request.Data.OtherInformation2;
entity.OtherInformation3 = request.Data.OtherInformation3;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateDesignationResponse
{
Id = entity.Id,
Success = true
};
}
}
@@ -0,0 +1,24 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Designation.Cqrs;
public class UpdateDesignationValidator : AbstractValidator<UpdateDesignationRequest>
{
public UpdateDesignationValidator()
{
RuleFor(x => x.Id)
.NotEmpty().WithMessage("ID is required for update");
RuleFor(x => x.Code)
.NotEmpty().WithMessage("Designation Code is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Designation Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Level)
.NotEmpty().WithMessage("Level is required");
}
}
@@ -0,0 +1,30 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Features.Organization.Designation.Cqrs;
using MediatR;
using Microsoft.AspNetCore.Authentication.JwtBearer;
namespace Indotalent.Features.Organization.Designation;
public static class DesignationEndpoint
{
public static void MapDesignationEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("/designation").WithTags("Designations")
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme).RequireAuthenticatedUser());
group.MapGet("/", async (IMediator mediator) =>
(await mediator.Send(new GetDesignationListQuery())).ToApiResponse("Data retrieved"));
group.MapGet("/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new GetDesignationByIdQuery(id))).ToApiResponse("Detail retrieved"));
group.MapPost("/", async (CreateDesignationRequest request, IMediator mediator) =>
(await mediator.Send(new CreateDesignationCommand(request))).ToApiResponse("Created", StatusCodes.Status201Created));
group.MapPost("/update", async (UpdateDesignationRequest request, IMediator mediator) =>
(await mediator.Send(new UpdateDesignationCommand(request))).ToApiResponse("Updated"));
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new DeleteDesignationByIdCommand(new DeleteDesignationByIdRequest(id)))).ToApiResponse("Deleted"));
}
}
@@ -0,0 +1,54 @@
using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Organization.Designation.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;
namespace Indotalent.Features.Organization.Designation;
public class DesignationService : BaseService
{
private readonly RestClient _client;
public DesignationService(IHttpClientFactory clientFactory, NavigationManager nav, ISnackbar snackbar, ICurrentUserService currentUserService, TokenProvider tokenProvider)
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
{
_client = new RestClient(nav.BaseUri);
}
public async Task<ApiResponse<List<GetDesignationListResponse>>?> GetDesignationListAsync()
{
var request = new RestRequest("api/designation", Method.Get);
return await ExecuteWithResponseAsync<List<GetDesignationListResponse>>(_client, request);
}
public async Task<ApiResponse<GetDesignationByIdResponse>?> GetDesignationByIdAsync(string id)
{
var request = new RestRequest($"api/designation/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetDesignationByIdResponse>(_client, request);
}
public async Task<ApiResponse<CreateDesignationResponse>?> CreateDesignationAsync(CreateDesignationRequest data)
{
var request = new RestRequest("api/designation", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreateDesignationResponse>(_client, request);
}
public async Task<ApiResponse<UpdateDesignationResponse>?> UpdateDesignationAsync(UpdateDesignationRequest data)
{
var request = new RestRequest("api/designation/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdateDesignationResponse>(_client, request);
}
public async Task<bool> DeleteDesignationByIdAsync(string id)
{
var request = new RestRequest($"api/designation/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
}
@@ -0,0 +1,54 @@
@page "/organization/employee"
@using Indotalent.Features.Organization.Employee
@using Indotalent.Features.Organization.Employee.Cqrs
@using MudBlazor
@if (_view == View.Create)
{
<_EmployeeCreateForm OnCancel="() => _view = View.Table" OnSuccess="() => _view = View.Table" />
}
else if (_view == View.Update || _view == View.Detail)
{
<_EmployeeUpdateForm Data="_data!" ReadOnly="@(_view == View.Detail)" OnCancel="() => _view = View.Table" OnSuccess="() => _view = View.Table" />
}
else if (_view == View.Income)
{
<_EmployeeIncomeDataTable EmployeeId="@_selectedId" EmployeeName="@_selectedName" EmployeeCode="@_selectedCode" OnBack="() => _view = View.Table" />
}
else if (_view == View.Deduction)
{
<_EmployeeDeductionDataTable EmployeeId="@_selectedId" EmployeeName="@_selectedName" EmployeeCode="@_selectedCode" OnBack="() => _view = View.Table" />
}
else
{
<_EmployeeDataTable OnAdd="() => _view = View.Create"
OnEdit="d => { _data = d; _view = View.Update; }"
OnView="d => { _data = d; _view = View.Detail; }"
OnIncome="HandleIncome"
OnDeduction="HandleDeduction" />
}
@code {
private enum View { Table, Create, Update, Detail, Income, Deduction }
private View _view = View.Table;
private UpdateEmployeeRequest? _data;
private string _selectedId = string.Empty;
private string _selectedName = string.Empty;
private string _selectedCode = string.Empty;
private void HandleIncome((string Id, string Name, string Code) args)
{
_selectedId = args.Id;
_selectedName = args.Name;
_selectedCode = args.Code;
_view = View.Income;
}
private void HandleDeduction((string Id, string Name, string Code) args)
{
_selectedId = args.Id;
_selectedName = args.Name;
_selectedCode = args.Code;
_view = View.Deduction;
}
}
@@ -0,0 +1,303 @@
@using Indotalent.Features.Organization.Employee
@using Indotalent.Features.Organization.Employee.Cqrs
@using Indotalent.Shared.Utils
@using MudBlazor
@implements IDisposable
@inject EmployeeService EmployeeService
@inject ISnackbar Snackbar
<style>
.field-label { font-size: 13px; font-weight: 700; color: #424242; margin-bottom: 4px; display: block; }
.section-header { font-weight: 800; color: #0D47A1; letter-spacing: 0.5px; margin-bottom: 8px; }
</style>
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Add New Employee</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">Create a comprehensive employee profile and organizational placement.</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
@if (_isLoadingData)
{
<div class="d-flex flex-column align-center pa-10">
<MudProgressCircular Color="Color.Primary" Indeterminate="true" />
<MudText Class="mt-4">Synchronizing Records...</MudText>
</div>
}
else
{
<MudForm @ref="_form" Model="_model">
<MudStack Spacing="6">
<MudGrid Spacing="3">
<MudItem xs="12"><div class="section-header">BASIC IDENTITY</div><MudDivider /></MudItem>
<MudItem xs="6">
<label class="field-label">Employee Code</label>
<MudTextField @bind-Value="_model.Code" For="@(() => _model.Code)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="6">
<label class="field-label">Salary Grade</label>
<MudSelect @bind-Value="_model.GradeId"
For="@(() => _model.GradeId)"
Validation="@(_validator.ValidateValue())"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Dense="true"
Placeholder="Select Grade">
@foreach (var item in _lookupData.Grades)
{
<MudSelectItem Value="@item.Id">
<div class="d-flex justify-space-between w-100 gap-4">
<MudText Typo="Typo.body2"><b>@item.Name</b> (@item.Code)</MudText>
<MudText Typo="Typo.caption" Style="color: #64748b;">
Range: @item.SalaryFrom.ToString("N0") - @item.SalaryTo.ToString("N0")
</MudText>
</div>
</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="4">
<label class="field-label">First Name</label>
<MudTextField @bind-Value="_model.FirstName" For="@(() => _model.FirstName)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Middle Name</label>
<MudTextField @bind-Value="_model.MiddleName" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Last Name</label>
<MudTextField @bind-Value="_model.LastName" For="@(() => _model.LastName)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">PAYROLL & BANKING</div><MudDivider /></MudItem>
<MudItem xs="6">
<label class="field-label">Basic Salary (Monthly)</label>
<MudNumericField @bind-Value="_model.BasicSalary"
For="@(() => _model.BasicSalary)"
HideSpinButtons="false"
Step="1"
Min="0"
Format="N0"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Payments"
AdornmentColor="Color.Success"
Variant="Variant.Outlined"
Margin="Margin.Dense" />
@if (!string.IsNullOrEmpty(_model.GradeId))
{
var selectedGrade = _lookupData.Grades.FirstOrDefault(x => x.Id == _model.GradeId);
if (selectedGrade != null)
{
<MudText Typo="Typo.caption" Color="Color.Info" Class="mt-1">
Allowed range: <b>@selectedGrade.SalaryFrom.ToString("N0")</b> - <b>@selectedGrade.SalaryTo.ToString("N0")</b>
</MudText>
}
}
</MudItem>
<MudItem xs="6">
<label class="field-label">Salary Bank Name</label>
<MudTextField @bind-Value="_model.SalaryBankName" Variant="Variant.Outlined" Margin="Margin.Dense" Placeholder="e.g. BCA" />
</MudItem>
<MudItem xs="6">
<label class="field-label">Bank Account Name</label>
<MudTextField @bind-Value="_model.SalaryBankAccountName" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="6">
<label class="field-label">Bank Account Number</label>
<MudTextField @bind-Value="_model.SalaryBankAccountNumber" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">PERSONAL DETAILS</div><MudDivider /></MudItem>
<MudItem xs="6">
<label class="field-label">Place of Birth</label>
<MudTextField @bind-Value="_model.PlaceOfBirth" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="6">
<label class="field-label">Date of Birth</label>
<MudDatePicker @bind-Date="_model.DateOfBirth" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Gender</label>
<MudSelect @bind-Value="_model.Gender" For="@(() => _model.Gender)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true">
<MudSelectItem Value="@("Male")">Male</MudSelectItem>
<MudSelectItem Value="@("Female")">Female</MudSelectItem>
</MudSelect>
</MudItem>
<MudItem xs="4">
<label class="field-label">Marital Status</label>
<MudTextField @bind-Value="_model.MaritalStatus" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Religion</label>
<MudTextField @bind-Value="_model.Religion" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Identity Number (KTP)</label>
<MudTextField @bind-Value="_model.IdentityNumber" For="@(() => _model.IdentityNumber)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Tax Number (NPWP)</label>
<MudTextField @bind-Value="_model.TaxNumber" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Blood Type</label>
<MudTextField @bind-Value="_model.BloodType" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="12">
<label class="field-label">Last Education</label>
<MudTextField @bind-Value="_model.LastEducation" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">ORGANIZATIONAL</div><MudDivider /></MudItem>
<MudItem xs="4">
<label class="field-label">Branch</label>
<MudSelect @bind-Value="_model.BranchId" For="@(() => _model.BranchId)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true">
@foreach (var item in _lookupData.Branches) { <MudSelectItem Value="@item.Id">@item.Name</MudSelectItem> }
</MudSelect>
</MudItem>
<MudItem xs="4">
<label class="field-label">Department</label>
<MudSelect @bind-Value="_model.DepartmentId" For="@(() => _model.DepartmentId)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true">
@foreach (var item in _lookupData.Departments) { <MudSelectItem Value="@item.Id">@item.Name</MudSelectItem> }
</MudSelect>
</MudItem>
<MudItem xs="4">
<label class="field-label">Designation</label>
<MudSelect @bind-Value="_model.DesignationId" For="@(() => _model.DesignationId)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true">
@foreach (var item in _lookupData.Designations) { <MudSelectItem Value="@item.Id">@item.Name</MudSelectItem> }
</MudSelect>
</MudItem>
<MudItem xs="4">
<label class="field-label">Joined Date</label>
<MudDatePicker @bind-Date="_model.JoinedDate" For="@(() => _model.JoinedDate)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Resigned Date</label>
<MudDatePicker @bind-Date="_model.ResignedDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Employee Status</label>
<MudTextField @bind-Value="_model.EmployeeStatus" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="6">
<label class="field-label">Employment Type</label>
<MudTextField @bind-Value="_model.EmploymentType" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="12">
<label class="field-label">Job Description</label>
<MudTextField @bind-Value="_model.JobDescription" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" />
</MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">ADDRESS & CONTACT</div><MudDivider /></MudItem>
<MudItem xs="6">
<label class="field-label">Email</label>
<MudTextField @bind-Value="_model.Email" For="@(() => _model.Email)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="6">
<label class="field-label">Phone</label>
<MudTextField @bind-Value="_model.Phone" For="@(() => _model.Phone)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="12">
<label class="field-label">Street Address</label>
<MudTextField @bind-Value="_model.StreetAddress" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4"><label class="field-label">City</label><MudTextField @bind-Value="_model.City" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Province</label><MudTextField @bind-Value="_model.StateProvince" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Zip Code</label><MudTextField @bind-Value="_model.ZipCode" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">SOCIAL MEDIA</div><MudDivider /></MudItem>
<MudItem xs="4"><label class="field-label">LinkedIn</label><MudTextField @bind-Value="_model.SocialMediaLinkedIn" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Instagram</label><MudTextField @bind-Value="_model.SocialMediaInstagram" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">TikTok</label><MudTextField @bind-Value="_model.SocialMediaTikTok" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="6"><label class="field-label">Facebook</label><MudTextField @bind-Value="_model.SocialMediaFacebook" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="6"><label class="field-label">X (Twitter)</label><MudTextField @bind-Value="_model.SocialMediaX" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">OTHERS</div><MudDivider /></MudItem>
<MudItem xs="4"><label class="field-label">Other Info 1</label><MudTextField @bind-Value="_model.OtherInformation1" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Other Info 2</label><MudTextField @bind-Value="_model.OtherInformation2" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Other Info 3</label><MudTextField @bind-Value="_model.OtherInformation3" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-10">
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">Cancel</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2">Creating...</MudText>
}
else
{
<MudText>Create Employee</MudText>
}
</MudButton>
</div>
</MudStack>
</MudForm>
}
</MudPaper>
@code {
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm? _form;
private CreateEmployeeRequest _model = new();
private CreateEmployeeValidator _validator = new();
private LookupResponse _lookupData = new();
private bool _processing = false;
private bool _isLoadingData = true;
private bool _isDisposed = false;
public void Dispose() => _isDisposed = true;
protected override async Task OnInitializedAsync()
{
try {
_isLoadingData = true;
var response = await EmployeeService.GetLookupAsync();
if (response?.IsSuccess == true)
{
_lookupData = response.Value ?? new();
}
} finally {
if (!_isDisposed) { _isLoadingData = false; StateHasChanged(); }
}
}
private async Task Submit()
{
await _form!.Validate();
if (!_form.IsValid) return;
_processing = true;
try {
var res = await EmployeeService.CreateEmployeeAsync(_model);
await Task.Delay(500);
if (res?.IsSuccess == true)
{
Snackbar.Add("Employee Created Successfully", Severity.Success);
await OnSuccess.InvokeAsync();
}
} finally { _processing = false; }
}
}
@@ -0,0 +1,457 @@
@using Indotalent.ConfigBackEnd.Extensions
@using Indotalent.Features.Organization.Employee
@using Indotalent.Features.Organization.Employee.Cqrs
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using MudBlazor
@using Features.Root.Shared
@using ClosedXML.Excel
@using System.IO
@inject EmployeeService EmployeeService
@inject IDialogService DialogService
@inject ISnackbar Snackbar
@inject IJSRuntime JSRuntime
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
<div>
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Employee Directory</MudText>
<MudText Typo="Typo.body2" Style="color: #9CA3AF; font-size: 0.75rem;">Manage human resources and organizational structure.</MudText>
</div>
<div class="d-flex align-center gap-2">
<MudIcon Icon="@Icons.Material.Filled.Home" Size="Size.Small" Color="Color.Default" />
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Organization</MudText>
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Employee</MudText>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
<div style="display: flex; align-items: center; gap: 8px;">
<MudTextField @bind-Value="_searchString"
Placeholder="Search..."
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search"
IconSize="Size.Small"
Class="mt-0"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Style="background-color: white; width: 280px; border-radius: 8px;"
OnKeyDown="@HandleSearchKeyDown" />
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
OnClick="OnSearchClick"
Size="Size.Small"
Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; box-shadow: none; background: #3B82F6; color: white;">
Search
</MudButton>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<MudButton Variant="Variant.Outlined"
Color="Color.Success"
OnClick="ExportToExcel"
Size="Size.Small"
Disabled="_isExporting"
StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)"
Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">
@if (_isExporting)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText>
}
</MudButton>
<MudButton Variant="Variant.Outlined"
Color="Color.Primary"
OnClick="LoadData"
Size="Size.Small"
StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)"
Disabled="_isRefreshing"
Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">
@if (_isRefreshing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText>
}
else
{
<MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText>
}
</MudButton>
@if (_selectedEmp != null)
{
<MudButton Variant="Variant.Filled" Color="Color.Success" StartIcon="@Icons.Material.Filled.Payments" OnClick="InvokeIncome" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px;">Income</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Warning" StartIcon="@Icons.Material.Filled.PriceCheck" OnClick="InvokeDeduction" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px;">Deduction</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">View</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="border: 1px solid #D1D5DB; background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; color: #6B7280;">Edit</MudButton>
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" OnClick="OnDelete" Size="Size.Small" Variant="Variant.Filled" Style="border-radius: 6px;" />
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedEmp = null" />
}
else
{
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; background: #3B82F6; color: white;">
Add Employee
</MudButton>
}
</div>
</div>
<MudTable Items="@GetPagedData()" Hover="true" Elevation="0" CustomHeader="true" Dense="true" Striped="true" Class="mud-table-styled" T="GetEmployeeListResponse" OnRowClick="@((args) => _selectedEmp = args.Item)" Loading="@_isRefreshing">
<HeaderContent>
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetEmployeeListResponse, object>(x => x.Code)">Code</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetEmployeeListResponse, object>(x => x.FullName)">Full Name</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetEmployeeListResponse, object>(x => x.GradeName)">Grade</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetEmployeeListResponse, object>(x => x.BasicSalary)">Salary</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetEmployeeListResponse, object>(x => x.DesignationName)">Designation</MudTableSortLabel>
</MudTh>
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; letter-spacing: 0.05em; white-space: nowrap;">
<MudTableSortLabel SortBy="new Func<GetEmployeeListResponse, object>(x => x.DepartmentName)">Department</MudTableSortLabel>
</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudCheckBox T="bool" Value="@(_selectedEmp?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudChip T="string" Size="Size.Small" Variant="Variant.Text" Style="background-color: #F9FAFB; color: #374151; font-weight: 600; border-radius: 4px;">@context.Code</MudChip>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<div class="d-flex align-center gap-2">
<MudAvatar Color="Color.Primary" Size="Size.Small" Style="width: 32px; height: 32px; font-weight: 700; font-size: 0.75rem;">@(!string.IsNullOrWhiteSpace(context.FullName) ? context.FullName.Substring(0, 1) : "?")</MudAvatar>
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.FullName</MudText>
</div>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudText Typo="Typo.body2" Style="color: #6B7280; font-size: 0.875rem;">@context.GradeName</MudText>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #6B7280; font-size: 0.875rem;">@context.BasicSalary?.ToString("N0")</MudText>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #6B7280; font-size: 0.875rem;">@context.DesignationName</MudText>
</MudTd>
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudText Typo="Typo.body2" Style="color: #6B7280; font-size: 0.875rem;">@context.DepartmentName</MudText>
</MudTd>
</RowTemplate>
</MudTable>
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
<div style="display: flex; align-items: center; gap: 12px;">
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
<MudSelect T="int"
Value="@_top"
ValueChanged="OnPageSizeChanged"
Dense="true"
Margin="Margin.Dense"
Style="width: 80px; background-color: white; font-size: 12px; font-weight: 600;"
Variant="Variant.Outlined"
Class="mt-0 custom-select-dense">
<MudSelectItem Value="5" />
<MudSelectItem Value="10" />
<MudSelectItem Value="50" />
<MudSelectItem Value="500" />
<MudSelectItem Value="1000" />
</MudSelect>
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem; margin-left: 12px;">
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
</MudText>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" Class="rounded-0" />
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="@(_currentPage == 1 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #6B7280; border: 1px solid #D1D5DB; border-radius: 6px;")">Prev</MudButton>
@{
var totalPages = _totalPage == 0 ? 1 : _totalPage;
var maxVisible = 5;
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
}
@for (int i = startPage; i <= endPage; i++)
{
var pageNum = i;
var isActive = pageNum == _currentPage;
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
Variant="Variant.Text" Size="Size.Small"
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
}
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #6B7280; border: 1px solid #D1D5DB; border-radius: 6px;")">Next</MudButton>
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" Class="rounded-0" />
</div>
</div>
</MudPaper>
<script>
function downloadFile(fileName, contentType, base64String) {
const link = document.createElement('a');
link.download = fileName;
link.href = `data:${contentType};base64,${base64String}`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
</script>
<style>
.mud-input-outlined-border { border-radius: 0px !important; }
.custom-select-dense .mud-input-control { margin-top: 0 !important; }
.custom-select-dense .mud-input-slot { padding-top: 4px !important; padding-bottom: 4px !important; padding-left: 8px !important; font-size: 12px !important; }
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
</style>
@code {
[Parameter] public EventCallback OnAdd { get; set; }
[Parameter] public EventCallback<UpdateEmployeeRequest> OnEdit { get; set; }
[Parameter] public EventCallback<UpdateEmployeeRequest> OnView { get; set; }
[Parameter] public EventCallback<(string Id, string Name, string Code)> OnIncome { get; set; }
[Parameter] public EventCallback<(string Id, string Name, string Code)> OnDeduction { get; set; }
private List<GetEmployeeListResponse> _employees = new();
private GetEmployeeListResponse? _selectedEmp;
private string _searchString = "";
private int _skip = 0;
private int _top = 5;
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
private bool _isRefreshing = false;
private bool _isExporting = false;
protected override async Task OnInitializedAsync() => await LoadData();
private async Task LoadData()
{
_isRefreshing = true; _selectedEmp = null;
StateHasChanged();
try
{
var response = await EmployeeService.GetEmployeeListAsync();
await Task.Delay(800);
if (response?.IsSuccess == true)
{
_employees = response.Value ?? new();
}
}
finally
{
_isRefreshing = false;
StateHasChanged();
}
}
private IEnumerable<GetEmployeeListResponse> GetFilteredData()
{
if (string.IsNullOrWhiteSpace(_searchString)) return _employees;
return _employees.Where(x =>
(x.FullName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.Code?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.DesignationName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.DepartmentName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
(x.BranchName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
);
}
private IEnumerable<GetEmployeeListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
private async Task ExportToExcel()
{
_isExporting = true;
StateHasChanged();
try
{
await Task.Delay(1000);
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.Worksheets.Add("Employees");
var currentRow = 1;
worksheet.Cell(currentRow, 1).Value = "Code";
worksheet.Cell(currentRow, 2).Value = "Full Name";
worksheet.Cell(currentRow, 3).Value = "Grade";
worksheet.Cell(currentRow, 4).Value = "Basic Salary";
worksheet.Cell(currentRow, 5).Value = "Designation";
worksheet.Cell(currentRow, 6).Value = "Department";
worksheet.Cell(currentRow, 7).Value = "Branch";
var headerRange = worksheet.Range(1, 1, 1, 7);
headerRange.Style.Font.Bold = true;
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#0D47A1");
headerRange.Style.Font.FontColor = XLColor.White;
foreach (var item in GetFilteredData())
{
currentRow++;
worksheet.Cell(currentRow, 1).Value = item.Code;
worksheet.Cell(currentRow, 2).Value = item.FullName;
worksheet.Cell(currentRow, 3).Value = item.GradeName;
worksheet.Cell(currentRow, 4).Value = item.BasicSalary;
worksheet.Cell(currentRow, 5).Value = item.DesignationName;
worksheet.Cell(currentRow, 6).Value = item.DepartmentName;
worksheet.Cell(currentRow, 7).Value = item.BranchName;
worksheet.Cell(currentRow, 4).Style.NumberFormat.Format = "#,##0";
}
worksheet.Columns().AdjustToContents();
using (var stream = new MemoryStream())
{
workbook.SaveAs(stream);
var content = Convert.ToBase64String(stream.ToArray());
await JSRuntime.InvokeVoidAsync("downloadFile", "Employee_Registry.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
Snackbar.Add("Excel exported successfully", Severity.Success);
}
}
}
catch (Exception ex)
{
Snackbar.Add($"Export failed: {ex.Message}", Severity.Error);
}
finally
{
_isExporting = false;
StateHasChanged();
}
}
private void OnSearchClick()
{
_skip = 0;
_selectedEmp = null;
StateHasChanged();
}
private void HandleSearchKeyDown(KeyboardEventArgs e)
{
if (e.Key == "Enter") OnSearchClick();
}
private void OnPageChanged(int page)
{
if (page >= 1 && page <= _totalPage)
{
_skip = (page - 1) * _top;
_selectedEmp = null;
StateHasChanged();
}
}
private void OnPageSizeChanged(int size)
{
_top = size;
_skip = 0;
_selectedEmp = null;
StateHasChanged();
}
private async Task InvokeIncome()
{
if (_selectedEmp == null) return;
await OnIncome.InvokeAsync((_selectedEmp.Id!, _selectedEmp.FullName!, _selectedEmp.Code!));
}
private async Task InvokeDeduction()
{
if (_selectedEmp == null) return;
await OnDeduction.InvokeAsync((_selectedEmp.Id!, _selectedEmp.FullName!, _selectedEmp.Code!));
}
private async Task InvokeView()
{
if (_selectedEmp == null) return;
var res = await EmployeeService.GetEmployeeByIdAsync(_selectedEmp.Id);
if (res?.Value != null) await OnView.InvokeAsync(Map(res.Value));
}
private async Task InvokeEdit()
{
if (_selectedEmp == null) return;
var res = await EmployeeService.GetEmployeeByIdAsync(_selectedEmp.Id);
if (res?.Value != null) await OnEdit.InvokeAsync(Map(res.Value));
}
private UpdateEmployeeRequest Map(GetEmployeeByIdResponse d) => new UpdateEmployeeRequest
{
Id = d.Id,
Code = d.Code,
FirstName = d.FirstName,
MiddleName = d.MiddleName,
LastName = d.LastName,
JobDescription = d.JobDescription,
GradeId = d.GradeId,
BasicSalary = d.BasicSalary,
SalaryBankName = d.SalaryBankName,
SalaryBankAccountName = d.SalaryBankAccountName,
SalaryBankAccountNumber = d.SalaryBankAccountNumber,
PlaceOfBirth = d.PlaceOfBirth,
DateOfBirth = d.DateOfBirth,
Gender = d.Gender,
MaritalStatus = d.MaritalStatus,
Religion = d.Religion,
BloodType = d.BloodType,
IdentityNumber = d.IdentityNumber,
TaxNumber = d.TaxNumber,
LastEducation = d.LastEducation,
JoinedDate = d.JoinedDate,
ResignedDate = d.ResignedDate,
EmployeeStatus = d.EmployeeStatus,
EmploymentType = d.EmploymentType,
StreetAddress = d.StreetAddress,
City = d.City,
StateProvince = d.StateProvince,
ZipCode = d.ZipCode,
Phone = d.Phone,
Email = d.Email,
BranchId = d.BranchId,
DepartmentId = d.DepartmentId,
DesignationId = d.DesignationId,
SocialMediaLinkedIn = d.SocialMediaLinkedIn,
SocialMediaX = d.SocialMediaX,
SocialMediaFacebook = d.SocialMediaFacebook,
SocialMediaInstagram = d.SocialMediaInstagram,
SocialMediaTikTok = d.SocialMediaTikTok,
OtherInformation1 = d.OtherInformation1,
OtherInformation2 = d.OtherInformation2,
OtherInformation3 = d.OtherInformation3,
CreatedAt = d.CreatedAt,
CreatedBy = d.CreatedBy,
UpdatedAt = d.UpdatedAt,
UpdatedBy = d.UpdatedBy
};
private async Task OnDelete()
{
if (_selectedEmp == null) return;
var diag = await DialogService.ShowAsync<_DeleteConfirmation>("", new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedEmp.FullName } });
if (!(await diag.Result).Canceled)
{
if (await EmployeeService.DeleteEmployeeByIdAsync(_selectedEmp.Id))
{
await LoadData();
Snackbar.Add("Employee deleted successfully", Severity.Success);
}
}
}
}
@@ -0,0 +1,134 @@
@using Indotalent.Features.Organization.Employee
@using Indotalent.Features.Organization.Employee.Cqrs
@using MudBlazor
@inject EmployeeService EmployeeService
@inject ISnackbar Snackbar
<style>
.field-label { font-size: 13px; font-weight: 700; color: #424242; margin-bottom: 4px; display: block; }
.section-header { font-weight: 800; color: #E65100; letter-spacing: 0.5px; margin-bottom: 8px; }
</style>
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">
<MudIcon Icon="@Icons.Material.Filled.Add" Color="Color.Warning" Class="mr-3 mb-n1" />
Add Employee Deduction
</MudText>
</TitleContent>
<DialogContent>
<MudForm @ref="_form">
<MudStack Spacing="4">
<MudGrid Spacing="3">
<MudItem xs="12"><div class="section-header">DEDUCTION INFORMATION</div><MudDivider /></MudItem>
<MudItem xs="12">
<label class="field-label">Deduction Component</label>
<MudSelect T="string"
@bind-Value="_model.DeductionId"
Required="true"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Placeholder="Select component"
Dense="true"
AnchorOrigin="Origin.BottomCenter"
TransformOrigin="Origin.TopCenter">
@foreach (var item in _lookupData.Deductions)
{
<MudSelectItem Value="@item.Id">@item.Name (@item.Code)</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12">
<label class="field-label">Amount</label>
<MudNumericField @bind-Value="_model.Amount"
Required="true"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Format="N0"
HideSpinButtons="false"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.PriceCheck"
AdornmentColor="Color.Warning" />
</MudItem>
<MudItem xs="12">
<label class="field-label">Description</label>
<MudTextField @bind-Value="_model.Description"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Lines="2"
Placeholder="Optional notes..." />
</MudItem>
<MudItem xs="12">
<MudCheckBox @bind-Value="_model.IsActive"
Label="Set as Active Component"
Color="Color.Warning"
Dense="true" />
</MudItem>
</MudGrid>
</MudStack>
</MudForm>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel" Variant="Variant.Outlined" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">Cancel</MudButton>
<MudButton Color="Color.Warning"
Variant="Variant.Filled"
OnClick="Submit"
Disabled="_processing"
Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText>Save Deduction</MudText>
}
</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
[Parameter] public string EmployeeId { get; set; } = string.Empty;
private MudForm? _form;
private CreateEmployeeDeductionRequest _model = new() { IsActive = true };
private LookupResponse _lookupData = new();
private bool _processing = false;
protected override async Task OnInitializedAsync()
{
_model.EmployeeId = EmployeeId;
var response = await EmployeeService.GetLookupAsync();
if (response?.IsSuccess == true)
{
_lookupData = response.Value ?? new();
}
}
private async Task Submit()
{
await _form!.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var res = await EmployeeService.CreateEmployeeDeductionAsync(_model);
await Task.Delay(500);
if (res?.IsSuccess == true)
{
Snackbar.Add("Deduction added successfully", Severity.Success);
MudDialog.Close(DialogResult.Ok(true));
}
}
finally { _processing = false; }
}
private void Cancel() => MudDialog.Cancel();
}
@@ -0,0 +1,154 @@
@using Indotalent.Features.Organization.Employee
@using Indotalent.Features.Organization.Employee.Cqrs
@using Features.Root.Shared
@using MudBlazor
@inject EmployeeService EmployeeService
@inject IDialogService DialogService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnBack.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Employee Deduction Details</MudText>
<MudText Typo="Typo.body2" Style="color: #9CA3AF; font-size: 0.75rem;">
Manage deduction components for <b>@EmployeeName</b> @(!string.IsNullOrEmpty(_displayCode) ? $"({_displayCode})" : "")
</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
<MudText Typo="Typo.subtitle1" Style="font-weight: 700;">List of Deductions</MudText>
<MudButton Variant="Variant.Filled"
Color="Color.Warning"
StartIcon="@Icons.Material.Filled.Add"
OnClick="OnAdd"
Size="Size.Small"
Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px;">
Add Deduction
</MudButton>
</div>
@if (_isLoading)
{
<div class="d-flex justify-center pa-10">
<MudProgressCircular Color="Color.Primary" Indeterminate="true" />
</div>
}
else if (!_deductions.Any())
{
<div class="pa-10 text-center" style="border: 1px dashed #E5E7EB; margin: 24px;">
<MudText Typo="Typo.body2" Color="Color.Secondary">No deduction components assigned for this employee.</MudText>
</div>
}
else
{
<MudTable Items="@_deductions" Hover="true" Elevation="0" Dense="true" Striped="true" Class="mud-table-styled">
<HeaderContent>
<MudTh Style="font-weight: 600; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Deduction Component</MudTh>
<MudTh Style="font-weight: 600; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Category</MudTh>
<MudTh Style="font-weight: 600; text-align: right; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Amount</MudTh>
<MudTh Style="font-weight: 600; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Description</MudTh>
<MudTh Style="font-weight: 600; text-align: center; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Status</MudTh>
<MudTh Style="font-weight: 600; text-align: center; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Deduction" Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">@context.DeductionName</MudTd>
<MudTd DataLabel="Category" Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudChip T="string" Size="Size.Small" Variant="Variant.Text" Color="Color.Warning" Style="font-weight: 700;">
@context.DeductionCategory
</MudChip>
</MudTd>
<MudTd DataLabel="Amount" Style="text-align: right; font-weight: 700; color: #d32f2f; padding-top: 0.75rem; padding-bottom: 0.75rem;">(@context.Amount.ToString("N0"))</MudTd>
<MudTd DataLabel="Description" Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">@context.Description</MudTd>
<MudTd DataLabel="Status" Style="text-align: center; padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudIcon Icon="@(context.IsActive? Icons.Material.Filled.CheckCircle : Icons.Material.Filled.Cancel)"
Color="@(context.IsActive ? Color.Success : Color.Error)" Size="Size.Small" />
</MudTd>
<MudTd Style="text-align: center; padding-top: 0.75rem; padding-bottom: 0.75rem;">
<div class="d-flex justify-center gap-1">
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small" Color="Color.Primary" OnClick="@(() => OnEdit(context))" />
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error" OnClick="@(() => OnDelete(context))" />
</div>
</MudTd>
</RowTemplate>
</MudTable>
}
</MudPaper>
<style>
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
</style>
@code {
[Parameter] public string EmployeeId { get; set; } = string.Empty;
[Parameter] public string EmployeeName { get; set; } = string.Empty;
[Parameter] public string EmployeeCode { get; set; } = string.Empty;
[Parameter] public EventCallback OnBack { get; set; }
private List<GetEmployeeDeductionListResponse> _deductions = new();
private bool _isLoading = true;
private string _displayCode = string.Empty;
protected override async Task OnInitializedAsync()
{
_displayCode = EmployeeCode;
await LoadData();
}
private async Task LoadData()
{
_isLoading = true;
StateHasChanged();
var response = await EmployeeService.GetEmployeeDeductionListAsync(EmployeeId);
if (response?.IsSuccess == true)
{
_deductions = response.Value ?? new();
if (_deductions.Any() && string.IsNullOrEmpty(_displayCode))
{
_displayCode = _deductions.First().EmployeeCode ?? string.Empty;
}
}
_isLoading = false;
StateHasChanged();
}
private async Task OnAdd()
{
var parameters = new DialogParameters { ["EmployeeId"] = EmployeeId };
var options = new DialogOptions { CloseButton = true, BackdropClick = false };
var dialog = await DialogService.ShowAsync<_EmployeeDeductionCreateForm>("Add Employee Deduction", parameters, options);
var result = await dialog.Result;
if (result != null && !result.Canceled) await LoadData();
}
private async Task OnEdit(GetEmployeeDeductionListResponse context)
{
var parameters = new DialogParameters { ["Id"] = context.Id };
var options = new DialogOptions { CloseButton = true, BackdropClick = false };
var dialog = await DialogService.ShowAsync<_EmployeeDeductionUpdateForm>("Edit Employee Deduction", parameters, options);
var result = await dialog.Result;
if (result != null && !result.Canceled) await LoadData();
}
private async Task OnDelete(GetEmployeeDeductionListResponse context)
{
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, $"{context.DeductionName} from {EmployeeName}" } });
var result = await dialog.Result;
if (result != null && !result.Canceled)
{
var success = await EmployeeService.DeleteEmployeeDeductionByIdAsync(context.Id!);
if (success)
{
Snackbar.Add("Deduction component removed", Severity.Success);
await LoadData();
}
}
}
}
@@ -0,0 +1,145 @@
@using Indotalent.Features.Organization.Employee
@using Indotalent.Features.Organization.Employee.Cqrs
@using MudBlazor
@inject EmployeeService EmployeeService
@inject ISnackbar Snackbar
<style>
.field-label { font-size: 13px; font-weight: 700; color: #424242; margin-bottom: 4px; display: block; }
.section-header { font-weight: 800; color: #E65100; letter-spacing: 0.5px; margin-bottom: 8px; }
</style>
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">
<MudIcon Icon="@Icons.Material.Filled.Edit" Color="Color.Warning" Class="mr-3 mb-n1" />
Edit Employee Deduction
</MudText>
</TitleContent>
<DialogContent>
@if (_isLoading)
{
<div class="d-flex flex-column align-center pa-10">
<MudProgressCircular Color="Color.Warning" Indeterminate="true" />
<MudText Class="mt-4">Fetching Details...</MudText>
</div>
}
else
{
<MudForm @ref="_form">
<MudStack Spacing="4">
<MudGrid Spacing="3">
<MudItem xs="12"><div class="section-header">UPDATE DEDUCTION DETAILS</div><MudDivider /></MudItem>
<MudItem xs="12">
<label class="field-label">Deduction Component</label>
<MudTextField Value="@_deductionName"
Variant="Variant.Outlined"
Margin="Margin.Dense"
ReadOnly="true"
Disabled="true"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Lock" />
</MudItem>
<MudItem xs="12">
<label class="field-label">Amount</label>
<MudNumericField @bind-Value="_model.Amount"
Required="true"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Format="N0"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.PriceCheck"
AdornmentColor="Color.Warning" />
</MudItem>
<MudItem xs="12">
<label class="field-label">Description</label>
<MudTextField @bind-Value="_model.Description"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Lines="2" />
</MudItem>
<MudItem xs="12">
<MudCheckBox @bind-Value="_model.IsActive"
Label="Keep this component active"
Color="Color.Warning"
Dense="true" />
</MudItem>
</MudGrid>
</MudStack>
</MudForm>
}
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel" Variant="Variant.Outlined" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">Cancel</MudButton>
<MudButton Color="Color.Warning"
Variant="Variant.Filled"
OnClick="Submit"
Disabled="_processing || _isLoading"
Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2">Updating...</MudText>
}
else
{
<MudText>Update Changes</MudText>
}
</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
[Parameter] public string Id { get; set; } = string.Empty;
private MudForm? _form;
private UpdateEmployeeDeductionRequest _model = new();
private string _deductionName = string.Empty;
private bool _isLoading = true;
private bool _processing = false;
protected override async Task OnInitializedAsync() => await LoadData();
private async Task LoadData()
{
_isLoading = true;
var response = await EmployeeService.GetEmployeeDeductionByIdAsync(Id);
if (response?.IsSuccess == true && response.Value != null)
{
var data = response.Value;
_model.Id = data.Id;
_model.DeductionId = data.DeductionId;
_model.Amount = data.Amount;
_model.Description = data.Description;
_model.IsActive = data.IsActive;
_deductionName = data.DeductionName ?? string.Empty;
}
_isLoading = false;
}
private async Task Submit()
{
await _form!.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var res = await EmployeeService.UpdateEmployeeDeductionAsync(_model);
await Task.Delay(500);
if (res?.IsSuccess == true)
{
Snackbar.Add("Deduction updated successfully", Severity.Success);
MudDialog.Close(DialogResult.Ok(true));
}
}
finally { _processing = false; }
}
private void Cancel() => MudDialog.Cancel();
}
@@ -0,0 +1,137 @@
@using Indotalent.Features.Organization.Employee
@using Indotalent.Features.Organization.Employee.Cqrs
@using MudBlazor
@inject EmployeeService EmployeeService
@inject ISnackbar Snackbar
<style>
.field-label { font-size: 13px; font-weight: 700; color: #424242; margin-bottom: 4px; display: block; }
.section-header { font-weight: 800; color: #0D47A1; letter-spacing: 0.5px; margin-bottom: 8px; }
</style>
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-3 mb-n1" />
Add Employee Income
</MudText>
</TitleContent>
<DialogContent>
<MudForm @ref="_form">
<MudStack Spacing="4">
<MudGrid Spacing="3">
<MudItem xs="12"><div class="section-header">INCOME INFORMATION</div><MudDivider /></MudItem>
<MudItem xs="12">
<label class="field-label">Income Component</label>
<MudSelect T="string"
@bind-Value="_model.IncomeId"
Required="true"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Placeholder="Select component"
Dense="true"
AnchorOrigin="Origin.BottomCenter"
TransformOrigin="Origin.TopCenter">
@foreach (var item in _lookupData.Incomes)
{
<MudSelectItem Value="@item.Id">@item.Name (@item.Code)</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12">
<label class="field-label">Amount</label>
<MudNumericField @bind-Value="_model.Amount"
Required="true"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Format="N0"
HideSpinButtons="false"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Payments"
AdornmentColor="Color.Success" />
</MudItem>
<MudItem xs="12">
<label class="field-label">Description</label>
<MudTextField @bind-Value="_model.Description"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Lines="2"
Placeholder="Optional notes..." />
</MudItem>
<MudItem xs="12">
<MudCheckBox @bind-Value="_model.IsActive"
Label="Set as Active Component"
Color="Color.Primary"
Dense="true" />
</MudItem>
</MudGrid>
</MudStack>
</MudForm>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel" Variant="Variant.Outlined" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">Cancel</MudButton>
<MudButton Color="Color.Primary"
Variant="Variant.Filled"
OnClick="Submit"
Disabled="_processing"
Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText>Save Income</MudText>
}
</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
[Parameter] public string EmployeeId { get; set; } = string.Empty;
private MudForm? _form;
private CreateEmployeeIncomeRequest _model = new() { IsActive = true };
private LookupResponse _lookupData = new();
private bool _processing = false;
protected override async Task OnInitializedAsync()
{
_model.EmployeeId = EmployeeId;
var response = await EmployeeService.GetLookupAsync();
if (response?.IsSuccess == true)
{
_lookupData = response.Value ?? new();
}
}
private async Task Submit()
{
await _form!.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var res = await EmployeeService.CreateEmployeeIncomeAsync(_model);
await Task.Delay(500);
if (res?.IsSuccess == true)
{
Snackbar.Add("Income added successfully", Severity.Success);
MudDialog.Close(DialogResult.Ok(true));
}
}
finally
{
_processing = false;
}
}
private void Cancel() => MudDialog.Cancel();
}
@@ -0,0 +1,154 @@
@using Indotalent.Features.Organization.Employee
@using Indotalent.Features.Organization.Employee.Cqrs
@using Features.Root.Shared
@using MudBlazor
@inject EmployeeService EmployeeService
@inject IDialogService DialogService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnBack.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Employee Income Details</MudText>
<MudText Typo="Typo.body2" Style="color: #9CA3AF; font-size: 0.75rem;">
Manage income components for <b>@EmployeeName</b> @(!string.IsNullOrEmpty(_displayCode) ? $"({_displayCode})" : "")
</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
<MudText Typo="Typo.subtitle1" Style="font-weight: 700;">List of Incomes</MudText>
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
StartIcon="@Icons.Material.Filled.Add"
OnClick="OnAdd"
Size="Size.Small"
Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px;">
Add Income
</MudButton>
</div>
@if (_isLoading)
{
<div class="d-flex justify-center pa-10">
<MudProgressCircular Color="Color.Primary" Indeterminate="true" />
</div>
}
else if (!_incomes.Any())
{
<div class="pa-10 text-center" style="border: 1px dashed #E5E7EB; margin: 24px;">
<MudText Typo="Typo.body2" Color="Color.Secondary">No income components assigned for this employee.</MudText>
</div>
}
else
{
<MudTable Items="@_incomes" Hover="true" Elevation="0" Dense="true" Striped="true" Class="mud-table-styled">
<HeaderContent>
<MudTh Style="font-weight: 600; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Income Component</MudTh>
<MudTh Style="font-weight: 600; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Type</MudTh>
<MudTh Style="font-weight: 600; text-align: right; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Amount</MudTh>
<MudTh Style="font-weight: 600; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Description</MudTh>
<MudTh Style="font-weight: 600; text-align: center; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Status</MudTh>
<MudTh Style="font-weight: 600; text-align: center; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Income" Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">@context.IncomeName</MudTd>
<MudTd DataLabel="Type" Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudChip T="string" Size="Size.Small" Variant="Variant.Text" Color="@(context.IncomeType == "Fixed" ? Color.Info : Color.Warning)" Style="font-weight: 700;">
@context.IncomeType
</MudChip>
</MudTd>
<MudTd DataLabel="Amount" Style="text-align: right; font-weight: 700; padding-top: 0.75rem; padding-bottom: 0.75rem;">@context.Amount.ToString("N0")</MudTd>
<MudTd DataLabel="Description" Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">@context.Description</MudTd>
<MudTd DataLabel="Status" Style="text-align: center; padding-top: 0.75rem; padding-bottom: 0.75rem;">
<MudIcon Icon="@(context.IsActive? Icons.Material.Filled.CheckCircle : Icons.Material.Filled.Cancel)"
Color="@(context.IsActive ? Color.Success : Color.Error)" Size="Size.Small" />
</MudTd>
<MudTd Style="text-align: center; padding-top: 0.75rem; padding-bottom: 0.75rem;">
<div class="d-flex justify-center gap-1">
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small" Color="Color.Primary" OnClick="@(() => OnEdit(context))" />
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error" OnClick="@(() => OnDelete(context))" />
</div>
</MudTd>
</RowTemplate>
</MudTable>
}
</MudPaper>
<style>
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
</style>
@code {
[Parameter] public string EmployeeId { get; set; } = string.Empty;
[Parameter] public string EmployeeName { get; set; } = string.Empty;
[Parameter] public string EmployeeCode { get; set; } = string.Empty;
[Parameter] public EventCallback OnBack { get; set; }
private List<GetEmployeeIncomeListResponse> _incomes = new();
private bool _isLoading = true;
private string _displayCode = string.Empty;
protected override async Task OnInitializedAsync()
{
_displayCode = EmployeeCode;
await LoadData();
}
private async Task LoadData()
{
_isLoading = true;
StateHasChanged();
var response = await EmployeeService.GetEmployeeIncomeListAsync(EmployeeId);
if (response?.IsSuccess == true)
{
_incomes = response.Value ?? new();
if (_incomes.Any() && string.IsNullOrEmpty(_displayCode))
{
_displayCode = _incomes.First().EmployeeCode ?? string.Empty;
}
}
_isLoading = false;
StateHasChanged();
}
private async Task OnAdd()
{
var parameters = new DialogParameters { ["EmployeeId"] = EmployeeId };
var options = new DialogOptions { CloseButton = true, BackdropClick = false };
var dialog = await DialogService.ShowAsync<_EmployeeIncomeCreateForm>("Add Employee Income", parameters, options);
var result = await dialog.Result;
if (result != null && !result.Canceled) await LoadData();
}
private async Task OnEdit(GetEmployeeIncomeListResponse context)
{
var parameters = new DialogParameters { ["Id"] = context.Id };
var options = new DialogOptions { CloseButton = true, BackdropClick = false };
var dialog = await DialogService.ShowAsync<_EmployeeIncomeUpdateForm>("Edit Employee Income", parameters, options);
var result = await dialog.Result;
if (result != null && !result.Canceled) await LoadData();
}
private async Task OnDelete(GetEmployeeIncomeListResponse context)
{
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, $"{context.IncomeName} from {EmployeeName}" } });
var result = await dialog.Result;
if (result != null && !result.Canceled)
{
var success = await EmployeeService.DeleteEmployeeIncomeByIdAsync(context.Id!);
if (success)
{
Snackbar.Add("Income component removed", Severity.Success);
await LoadData();
}
}
}
}
@@ -0,0 +1,151 @@
@using Indotalent.Features.Organization.Employee
@using Indotalent.Features.Organization.Employee.Cqrs
@using MudBlazor
@inject EmployeeService EmployeeService
@inject ISnackbar Snackbar
<style>
.field-label { font-size: 13px; font-weight: 700; color: #424242; margin-bottom: 4px; display: block; }
.section-header { font-weight: 800; color: #0D47A1; letter-spacing: 0.5px; margin-bottom: 8px; }
</style>
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">
<MudIcon Icon="@Icons.Material.Filled.Edit" Class="mr-3 mb-n1" />
Edit Employee Income
</MudText>
</TitleContent>
<DialogContent>
@if (_isLoading)
{
<div class="d-flex flex-column align-center pa-10">
<MudProgressCircular Color="Color.Primary" Indeterminate="true" />
<MudText Class="mt-4">Fetching Details...</MudText>
</div>
}
else
{
<MudForm @ref="_form">
<MudStack Spacing="4">
<MudGrid Spacing="3">
<MudItem xs="12"><div class="section-header">UPDATE INCOME DETAILS</div><MudDivider /></MudItem>
<MudItem xs="12">
<label class="field-label">Income Component</label>
<MudTextField Value="@_incomeName"
Variant="Variant.Outlined"
Margin="Margin.Dense"
ReadOnly="true"
Disabled="true"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Lock" />
</MudItem>
<MudItem xs="12">
<label class="field-label">Amount</label>
<MudNumericField @bind-Value="_model.Amount"
Required="true"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Format="N0"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Payments"
AdornmentColor="Color.Success" />
</MudItem>
<MudItem xs="12">
<label class="field-label">Description</label>
<MudTextField @bind-Value="_model.Description"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Lines="2" />
</MudItem>
<MudItem xs="12">
<MudCheckBox @bind-Value="_model.IsActive"
Label="Keep this component active"
Color="Color.Primary"
Dense="true" />
</MudItem>
</MudGrid>
</MudStack>
</MudForm>
}
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel" Variant="Variant.Outlined" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">Cancel</MudButton>
<MudButton Color="Color.Primary"
Variant="Variant.Filled"
OnClick="Submit"
Disabled="_processing || _isLoading"
Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2">Updating...</MudText>
}
else
{
<MudText>Update Changes</MudText>
}
</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
[Parameter] public string Id { get; set; } = string.Empty;
private MudForm? _form;
private UpdateEmployeeIncomeRequest _model = new();
private string _incomeName = string.Empty;
private bool _isLoading = true;
private bool _processing = false;
protected override async Task OnInitializedAsync()
{
await LoadData();
}
private async Task LoadData()
{
_isLoading = true;
var response = await EmployeeService.GetEmployeeIncomeByIdAsync(Id);
if (response?.IsSuccess == true && response.Value != null)
{
var data = response.Value;
_model.Id = data.Id;
_model.IncomeId = data.IncomeId;
_model.Amount = data.Amount;
_model.Description = data.Description;
_model.IsActive = data.IsActive;
_incomeName = data.IncomeName;
}
_isLoading = false;
}
private async Task Submit()
{
await _form!.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var res = await EmployeeService.UpdateEmployeeIncomeAsync(_model);
await Task.Delay(500);
if (res?.IsSuccess == true)
{
Snackbar.Add("Income updated successfully", Severity.Success);
MudDialog.Close(DialogResult.Ok(true));
}
}
finally
{
_processing = false;
}
}
private void Cancel() => MudDialog.Cancel();
}
@@ -0,0 +1,285 @@
@using Indotalent.ConfigBackEnd.Extensions
@using Indotalent.Features.Organization.Employee
@using Indotalent.Features.Organization.Employee.Cqrs
@using Indotalent.Shared.Utils
@using MudBlazor
@implements IDisposable
@inject EmployeeService EmployeeService
@inject ISnackbar Snackbar
<style>
.field-label { font-size: 13px; font-weight: 700; color: #424242; margin-bottom: 4px; display: block; }
.section-header { font-weight: 800; color: #0D47A1; letter-spacing: 0.5px; margin-bottom: 8px; }
</style>
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Employee Profile" : "Edit Employee")</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">Managing records for @_model.FirstName @_model.LastName</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
@if (_isLoadingData)
{
<div class="d-flex flex-column align-center pa-10">
<MudProgressCircular Color="Color.Primary" Indeterminate="true" />
<MudText Class="mt-4">Synchronizing Records...</MudText>
</div>
}
else
{
<MudForm @ref="_form" Model="_model">
<MudStack Spacing="6">
<MudGrid Spacing="3">
<MudItem xs="12"><div class="section-header">BASIC IDENTITY</div><MudDivider /></MudItem>
<MudItem xs="6">
<label class="field-label">Employee Code</label>
<MudTextField @bind-Value="_model.Code" For="@(() => _model.Code)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="6">
<label class="field-label">Salary Grade</label>
<MudSelect @bind-Value="_model.GradeId"
For="@(() => _model.GradeId)"
Validation="@(_validator.ValidateValue())"
ReadOnly="ReadOnly"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Dense="true">
@foreach (var item in _lookupData.Grades)
{
<MudSelectItem Value="@item.Id">
<div class="d-flex justify-space-between w-100 gap-4">
<MudText Typo="Typo.body2"><b>@item.Name</b> (@item.Code)</MudText>
<MudText Typo="Typo.caption" Style="color: #64748b;">
Range: @item.SalaryFrom.ToString("N0") - @item.SalaryTo.ToString("N0")
</MudText>
</div>
</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="4">
<label class="field-label">First Name</label>
<MudTextField @bind-Value="_model.FirstName" For="@(() => _model.FirstName)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Middle Name</label>
<MudTextField @bind-Value="_model.MiddleName" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="4">
<label class="field-label">Last Name</label>
<MudTextField @bind-Value="_model.LastName" For="@(() => _model.LastName)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">PAYROLL & BANKING</div><MudDivider /></MudItem>
<MudItem xs="6">
<label class="field-label">Basic Salary (Monthly)</label>
<MudNumericField @bind-Value="_model.BasicSalary"
For="@(() => _model.BasicSalary)"
Validation="@(_validator.ValidateValue())"
ReadOnly="ReadOnly"
HideSpinButtons="false"
Step="1"
Min="0"
Format="N0"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Payments"
AdornmentColor="Color.Success"
Variant="Variant.Outlined"
Margin="Margin.Dense" />
@if (!string.IsNullOrEmpty(_model.GradeId))
{
var selectedGrade = _lookupData.Grades.FirstOrDefault(x => x.Id == _model.GradeId);
if (selectedGrade != null)
{
<MudText Typo="Typo.caption" Color="Color.Info" Class="mt-1">
Allowed range: <b>@selectedGrade.SalaryFrom.ToString("N0")</b> - <b>@selectedGrade.SalaryTo.ToString("N0")</b>
</MudText>
}
}
</MudItem>
<MudItem xs="6">
<label class="field-label">Salary Bank Name</label>
<MudTextField @bind-Value="_model.SalaryBankName" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="6">
<label class="field-label">Bank Account Name</label>
<MudTextField @bind-Value="_model.SalaryBankAccountName" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="6">
<label class="field-label">Bank Account Number</label>
<MudTextField @bind-Value="_model.SalaryBankAccountNumber" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">PERSONAL DETAILS</div><MudDivider /></MudItem>
<MudItem xs="6"><label class="field-label">Place of Birth</label><MudTextField @bind-Value="_model.PlaceOfBirth" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="6"><label class="field-label">Date of Birth</label><MudDatePicker @bind-Date="_model.DateOfBirth" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4">
<label class="field-label">Gender</label>
<MudSelect @bind-Value="_model.Gender" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true">
<MudSelectItem Value="@("Male")">Male</MudSelectItem>
<MudSelectItem Value="@("Female")">Female</MudSelectItem>
</MudSelect>
</MudItem>
<MudItem xs="4"><label class="field-label">Marital Status</label><MudTextField @bind-Value="_model.MaritalStatus" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Religion</label><MudTextField @bind-Value="_model.Religion" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Identity Number (KTP)</label><MudTextField @bind-Value="_model.IdentityNumber" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Tax Number (NPWP)</label><MudTextField @bind-Value="_model.TaxNumber" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Blood Type</label><MudTextField @bind-Value="_model.BloodType" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="12"><label class="field-label">Last Education</label><MudTextField @bind-Value="_model.LastEducation" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">ORGANIZATIONAL</div><MudDivider /></MudItem>
<MudItem xs="4">
<label class="field-label">Branch</label>
<MudSelect @bind-Value="_model.BranchId" For="@(() => _model.BranchId)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true">
@foreach (var item in _lookupData.Branches) { <MudSelectItem Value="@item.Id">@item.Name</MudSelectItem> }
</MudSelect>
</MudItem>
<MudItem xs="4">
<label class="field-label">Department</label>
<MudSelect @bind-Value="_model.DepartmentId" For="@(() => _model.DepartmentId)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true">
@foreach (var item in _lookupData.Departments) { <MudSelectItem Value="@item.Id">@item.Name</MudSelectItem> }
</MudSelect>
</MudItem>
<MudItem xs="4">
<label class="field-label">Designation</label>
<MudSelect @bind-Value="_model.DesignationId" For="@(() => _model.DesignationId)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true">
@foreach (var item in _lookupData.Designations) { <MudSelectItem Value="@item.Id">@item.Name</MudSelectItem> }
</MudSelect>
</MudItem>
<MudItem xs="4"><label class="field-label">Joined Date</label><MudDatePicker @bind-Date="_model.JoinedDate" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Resigned Date</label><MudDatePicker @bind-Date="_model.ResignedDate" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Employee Status</label><MudTextField @bind-Value="_model.EmployeeStatus" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="6"><label class="field-label">Employment Type</label><MudTextField @bind-Value="_model.EmploymentType" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="12"><label class="field-label">Job Description</label><MudTextField @bind-Value="_model.JobDescription" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" /></MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">ADDRESS & CONTACT</div><MudDivider /></MudItem>
<MudItem xs="6">
<label class="field-label">Email</label>
<MudTextField @bind-Value="_model.Email" For="@(() => _model.Email)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="6"><label class="field-label">Phone</label><MudTextField @bind-Value="_model.Phone" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="12"><label class="field-label">Street Address</label><MudTextField @bind-Value="_model.StreetAddress" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">City</label><MudTextField @bind-Value="_model.City" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Province</label><MudTextField @bind-Value="_model.StateProvince" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Zip Code</label><MudTextField @bind-Value="_model.ZipCode" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">SOCIAL MEDIA</div><MudDivider /></MudItem>
<MudItem xs="4"><label class="field-label">LinkedIn</label><MudTextField @bind-Value="_model.SocialMediaLinkedIn" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Instagram</label><MudTextField @bind-Value="_model.SocialMediaInstagram" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">TikTok</label><MudTextField @bind-Value="_model.SocialMediaTikTok" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="6"><label class="field-label">Facebook</label><MudTextField @bind-Value="_model.SocialMediaFacebook" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="6"><label class="field-label">X (Twitter)</label><MudTextField @bind-Value="_model.SocialMediaX" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-2"><div class="section-header">ADDITIONAL</div><MudDivider /></MudItem>
<MudItem xs="4"><label class="field-label">Other Info 1</label><MudTextField @bind-Value="_model.OtherInformation1" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Other Info 2</label><MudTextField @bind-Value="_model.OtherInformation2" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
<MudItem xs="4"><label class="field-label">Other Info 3</label><MudTextField @bind-Value="_model.OtherInformation3" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
</MudGrid>
<MudGrid Spacing="3">
<MudItem xs="12" Class="mt-4">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Audit History</MudText>
<MudDivider Class="mt-2 mb-4" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Created At</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.CreatedAt)</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Created By</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System")</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Last Updated At</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.UpdatedAt)</MudText>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2">Last Updated By</MudText>
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System")</MudText>
</MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-10">
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">@(ReadOnly ? "Back to List" : "Cancel")</MudButton>
@if (!ReadOnly)
{
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing) { <MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" /> <MudText Class="ms-2">Updating...</MudText> }
else { <MudText>Save Changes</MudText> }
</MudButton>
}
</div>
</MudStack>
</MudForm>
}
</MudPaper>
@code {
[Parameter] public UpdateEmployeeRequest Data { get; set; } = new();
[Parameter] public bool ReadOnly { get; set; } = false;
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm? _form;
private UpdateEmployeeRequest _model = new();
private UpdateEmployeeValidator _validator = new();
private LookupResponse _lookupData = new();
private bool _processing = false;
private bool _isLoadingData = true;
private bool _isDisposed = false;
public void Dispose() => _isDisposed = true;
protected override void OnInitialized() { _model = Data; }
protected override async Task OnInitializedAsync()
{
try {
_isLoadingData = true;
var response = await EmployeeService.GetLookupAsync();
if (response?.IsSuccess == true)
{
_lookupData = response.Value ?? new();
}
} finally {
if (!_isDisposed) { _isLoadingData = false; StateHasChanged(); }
}
}
private async Task Submit()
{
await _form!.Validate();
if (!_form.IsValid) return;
_processing = true;
try {
var res = await EmployeeService.UpdateEmployeeAsync(_model);
await Task.Delay(500);
if (res?.IsSuccess == true)
{
Snackbar.Add("Updated successfully", Severity.Success);
await OnSuccess.InvokeAsync();
}
} finally { _processing = false; }
}
}
@@ -0,0 +1,54 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class CreateEmployeeDeductionRequest
{
public string? EmployeeId { get; set; }
public string? DeductionId { get; set; }
public decimal Amount { get; set; }
public string? Description { get; set; }
public bool IsActive { get; set; } = true;
}
public class CreateEmployeeDeductionResponse
{
public string? Id { get; set; }
}
public record CreateEmployeeDeductionCommand(CreateEmployeeDeductionRequest Data) : IRequest<CreateEmployeeDeductionResponse>;
public class CreateEmployeeDeductionHandler : IRequestHandler<CreateEmployeeDeductionCommand, CreateEmployeeDeductionResponse>
{
private readonly AppDbContext _context;
public CreateEmployeeDeductionHandler(AppDbContext context) => _context = context;
public async Task<CreateEmployeeDeductionResponse> Handle(CreateEmployeeDeductionCommand request, CancellationToken cancellationToken)
{
var entityName = nameof(Data.Entities.EmployeeDeduction);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"EDED/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.EmployeeDeduction
{
AutoNumber = autoNo,
EmployeeId = request.Data.EmployeeId,
DeductionId = request.Data.DeductionId,
Amount = request.Data.Amount,
Description = request.Data.Description,
IsActive = request.Data.IsActive
};
_context.EmployeeDeduction.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateEmployeeDeductionResponse { Id = entity.Id };
}
}
@@ -0,0 +1,15 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class CreateEmployeeDeductionValidator : AbstractValidator<CreateEmployeeDeductionRequest>
{
public CreateEmployeeDeductionValidator()
{
RuleFor(x => x.EmployeeId).NotEmpty().WithMessage("Employee is required");
RuleFor(x => x.DeductionId).NotEmpty().WithMessage("Deduction component is required");
RuleFor(x => x.Amount).GreaterThanOrEqualTo(0).WithMessage("Amount must be 0 or greater");
RuleFor(x => x.Description).MaximumLength(GlobalConsts.StringLengthShort);
}
}
@@ -0,0 +1,128 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class CreateEmployeeRequest
{
public string Code { get; set; } = string.Empty;
public string FirstName { get; set; } = string.Empty;
public string MiddleName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string JobDescription { get; set; } = string.Empty;
public string GradeId { get; set; } = string.Empty;
public decimal BasicSalary { get; set; }
public string SalaryBankName { get; set; } = string.Empty;
public string SalaryBankAccountName { get; set; } = string.Empty;
public string SalaryBankAccountNumber { get; set; } = string.Empty;
public string PlaceOfBirth { get; set; } = string.Empty;
public DateTime? DateOfBirth { get; set; }
public string Gender { get; set; } = string.Empty;
public string MaritalStatus { get; set; } = string.Empty;
public string Religion { get; set; } = string.Empty;
public string BloodType { get; set; } = string.Empty;
public string IdentityNumber { get; set; } = string.Empty;
public string TaxNumber { get; set; } = string.Empty;
public string LastEducation { get; set; } = string.Empty;
public DateTime? JoinedDate { get; set; }
public DateTime? ResignedDate { get; set; }
public string EmployeeStatus { get; set; } = string.Empty;
public string EmploymentType { get; set; } = string.Empty;
public string StreetAddress { get; set; } = string.Empty;
public string City { get; set; } = string.Empty;
public string StateProvince { get; set; } = string.Empty;
public string ZipCode { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string BranchId { get; set; } = string.Empty;
public string DepartmentId { get; set; } = string.Empty;
public string DesignationId { get; set; } = string.Empty;
public string SocialMediaLinkedIn { get; set; } = string.Empty;
public string SocialMediaX { get; set; } = string.Empty;
public string SocialMediaFacebook { get; set; } = string.Empty;
public string SocialMediaInstagram { get; set; } = string.Empty;
public string SocialMediaTikTok { get; set; } = string.Empty;
public string OtherInformation1 { get; set; } = string.Empty;
public string OtherInformation2 { get; set; } = string.Empty;
public string OtherInformation3 { get; set; } = string.Empty;
}
public class CreateEmployeeResponse
{
public string? Id { get; set; }
public string? Code { get; set; }
}
public record CreateEmployeeCommand(CreateEmployeeRequest Data) : IRequest<CreateEmployeeResponse>;
public class CreateEmployeeHandler : IRequestHandler<CreateEmployeeCommand, CreateEmployeeResponse>
{
private readonly AppDbContext _context;
public CreateEmployeeHandler(AppDbContext context) => _context = context;
public async Task<CreateEmployeeResponse> Handle(CreateEmployeeCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.Employee.AnyAsync(x => x.Code == request.Data.Code, cancellationToken);
if (isExists) throw new AlreadyExistsException("Employee", request.Data.Code);
var entityName = nameof(Data.Entities.Employee);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"EMP/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.Employee
{
AutoNumber = autoNo,
Code = request.Data.Code,
FirstName = request.Data.FirstName,
MiddleName = request.Data.MiddleName,
LastName = request.Data.LastName,
JobDescription = request.Data.JobDescription,
GradeId = request.Data.GradeId,
BasicSalary = request.Data.BasicSalary,
SalaryBankName = request.Data.SalaryBankName,
SalaryBankAccountName = request.Data.SalaryBankAccountName,
SalaryBankAccountNumber = request.Data.SalaryBankAccountNumber,
PlaceOfBirth = request.Data.PlaceOfBirth,
DateOfBirth = request.Data.DateOfBirth,
Gender = request.Data.Gender,
MaritalStatus = request.Data.MaritalStatus,
Religion = request.Data.Religion,
BloodType = request.Data.BloodType,
IdentityNumber = request.Data.IdentityNumber,
TaxNumber = request.Data.TaxNumber,
LastEducation = request.Data.LastEducation,
JoinedDate = request.Data.JoinedDate,
ResignedDate = request.Data.ResignedDate,
EmployeeStatus = request.Data.EmployeeStatus,
EmploymentType = request.Data.EmploymentType,
StreetAddress = request.Data.StreetAddress,
City = request.Data.City,
StateProvince = request.Data.StateProvince,
ZipCode = request.Data.ZipCode,
Phone = request.Data.Phone,
Email = request.Data.Email,
BranchId = request.Data.BranchId,
DepartmentId = request.Data.DepartmentId,
DesignationId = request.Data.DesignationId,
SocialMediaLinkedIn = request.Data.SocialMediaLinkedIn,
SocialMediaX = request.Data.SocialMediaX,
SocialMediaFacebook = request.Data.SocialMediaFacebook,
SocialMediaInstagram = request.Data.SocialMediaInstagram,
SocialMediaTikTok = request.Data.SocialMediaTikTok,
OtherInformation1 = request.Data.OtherInformation1,
OtherInformation2 = request.Data.OtherInformation2,
OtherInformation3 = request.Data.OtherInformation3
};
_context.Employee.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateEmployeeResponse { Id = entity.Id, Code = entity.Code };
}
}
@@ -0,0 +1,54 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class CreateEmployeeIncomeRequest
{
public string? EmployeeId { get; set; }
public string? IncomeId { get; set; }
public decimal Amount { get; set; }
public string? Description { get; set; }
public bool IsActive { get; set; } = true;
}
public class CreateEmployeeIncomeResponse
{
public string? Id { get; set; }
}
public record CreateEmployeeIncomeCommand(CreateEmployeeIncomeRequest Data) : IRequest<CreateEmployeeIncomeResponse>;
public class CreateEmployeeIncomeHandler : IRequestHandler<CreateEmployeeIncomeCommand, CreateEmployeeIncomeResponse>
{
private readonly AppDbContext _context;
public CreateEmployeeIncomeHandler(AppDbContext context) => _context = context;
public async Task<CreateEmployeeIncomeResponse> Handle(CreateEmployeeIncomeCommand request, CancellationToken cancellationToken)
{
var entityName = nameof(Data.Entities.EmployeeIncome);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"EINC/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.EmployeeIncome
{
AutoNumber = autoNo,
EmployeeId = request.Data.EmployeeId,
IncomeId = request.Data.IncomeId,
Amount = request.Data.Amount,
Description = request.Data.Description,
IsActive = request.Data.IsActive
};
_context.EmployeeIncome.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateEmployeeIncomeResponse { Id = entity.Id };
}
}
@@ -0,0 +1,15 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class CreateEmployeeIncomeValidator : AbstractValidator<CreateEmployeeIncomeRequest>
{
public CreateEmployeeIncomeValidator()
{
RuleFor(x => x.EmployeeId).NotEmpty().WithMessage("Employee is required");
RuleFor(x => x.IncomeId).NotEmpty().WithMessage("Income component is required");
RuleFor(x => x.Amount).GreaterThanOrEqualTo(0).WithMessage("Amount must be 0 or greater");
RuleFor(x => x.Description).MaximumLength(GlobalConsts.StringLengthShort);
}
}
@@ -0,0 +1,58 @@
using FluentValidation;
using Indotalent.Infrastructure.Database;
using Indotalent.Shared.Consts;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class CreateEmployeeValidator : AbstractValidator<CreateEmployeeRequest>
{
public CreateEmployeeValidator()
{
RuleFor(x => x.Code)
.NotEmpty().WithMessage("Employee Code is required")
.MaximumLength(GlobalConsts.StringLengthShort).WithMessage($"Code cannot exceed {GlobalConsts.StringLengthShort} characters");
RuleFor(x => x.FirstName)
.NotEmpty().WithMessage("First Name is required")
.MaximumLength(GlobalConsts.StringLengthShort).WithMessage($"First Name cannot exceed {GlobalConsts.StringLengthShort} characters");
RuleFor(x => x.LastName)
.NotEmpty().WithMessage("Last Name is required")
.MaximumLength(GlobalConsts.StringLengthShort).WithMessage($"Last Name cannot exceed {GlobalConsts.StringLengthShort} characters");
RuleFor(x => x.Email)
.NotEmpty().WithMessage("Email is required")
.EmailAddress().WithMessage("Invalid email format");
RuleFor(x => x.IdentityNumber)
.NotEmpty().WithMessage("Identity Number is required");
RuleFor(x => x.JoinedDate)
.NotEmpty().WithMessage("Joined Date is required");
RuleFor(x => x.BranchId)
.NotEmpty().WithMessage("Please select a Branch");
RuleFor(x => x.DepartmentId)
.NotEmpty().WithMessage("Please select a Department");
RuleFor(x => x.DesignationId)
.NotEmpty().WithMessage("Please select a Designation");
RuleFor(x => x.GradeId)
.NotEmpty().WithMessage("Please select a Salary Grade");
RuleFor(x => x.Gender)
.NotEmpty().WithMessage("Gender is required");
RuleFor(x => x.Phone)
.NotEmpty().WithMessage("Phone number is required");
RuleFor(x => x.BasicSalary)
.GreaterThan(0).WithMessage("Basic Salary must be greater than 0.");
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public record DeleteEmployeeByIdRequest(string Id);
public record DeleteEmployeeByIdCommand(DeleteEmployeeByIdRequest Data) : IRequest<bool>;
public class DeleteEmployeeByIdHandler : IRequestHandler<DeleteEmployeeByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteEmployeeByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteEmployeeByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Employee
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.Employee.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public record DeleteEmployeeDeductionByIdRequest(string Id);
public record DeleteEmployeeDeductionByIdCommand(DeleteEmployeeDeductionByIdRequest Data) : IRequest<bool>;
public class DeleteEmployeeDeductionByIdHandler : IRequestHandler<DeleteEmployeeDeductionByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteEmployeeDeductionByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteEmployeeDeductionByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.EmployeeDeduction
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.EmployeeDeduction.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public record DeleteEmployeeIncomeByIdRequest(string Id);
public record DeleteEmployeeIncomeByIdCommand(DeleteEmployeeIncomeByIdRequest Data) : IRequest<bool>;
public class DeleteEmployeeIncomeByIdHandler : IRequestHandler<DeleteEmployeeIncomeByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteEmployeeIncomeByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteEmployeeIncomeByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.EmployeeIncome
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.EmployeeIncome.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,120 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class GetEmployeeByIdResponse
{
public string Id { get; set; } = string.Empty;
public string? AutoNumber { get; set; }
public string Code { get; set; } = string.Empty;
public string FirstName { get; set; } = string.Empty;
public string MiddleName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string JobDescription { get; set; } = string.Empty;
public string? GradeId { get; set; }
public decimal BasicSalary { get; set; }
public string SalaryBankName { get; set; } = string.Empty;
public string SalaryBankAccountName { get; set; } = string.Empty;
public string SalaryBankAccountNumber { get; set; } = string.Empty;
public string PlaceOfBirth { get; set; } = string.Empty;
public DateTime? DateOfBirth { get; set; }
public string Gender { get; set; } = string.Empty;
public string MaritalStatus { get; set; } = string.Empty;
public string Religion { get; set; } = string.Empty;
public string BloodType { get; set; } = string.Empty;
public string IdentityNumber { get; set; } = string.Empty;
public string TaxNumber { get; set; } = string.Empty;
public string LastEducation { get; set; } = string.Empty;
public DateTime? JoinedDate { get; set; }
public DateTime? ResignedDate { get; set; }
public string EmployeeStatus { get; set; } = string.Empty;
public string EmploymentType { get; set; } = string.Empty;
public string StreetAddress { get; set; } = string.Empty;
public string City { get; set; } = string.Empty;
public string StateProvince { get; set; } = string.Empty;
public string ZipCode { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string BranchId { get; set; } = string.Empty;
public string DepartmentId { get; set; } = string.Empty;
public string DesignationId { get; set; } = string.Empty;
public string SocialMediaLinkedIn { get; set; } = string.Empty;
public string SocialMediaX { get; set; } = string.Empty;
public string SocialMediaFacebook { get; set; } = string.Empty;
public string SocialMediaInstagram { get; set; } = string.Empty;
public string SocialMediaTikTok { get; set; } = string.Empty;
public string OtherInformation1 { get; set; } = string.Empty;
public string OtherInformation2 { get; set; } = string.Empty;
public string OtherInformation3 { get; set; } = string.Empty;
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetEmployeeByIdQuery(string Id) : IRequest<GetEmployeeByIdResponse?>;
public class GetEmployeeByIdHandler : IRequestHandler<GetEmployeeByIdQuery, GetEmployeeByIdResponse?>
{
private readonly AppDbContext _context;
public GetEmployeeByIdHandler(AppDbContext context) => _context = context;
public async Task<GetEmployeeByIdResponse?> Handle(GetEmployeeByIdQuery request, CancellationToken cancellationToken)
{
return await _context.Employee
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetEmployeeByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Code = x.Code,
FirstName = x.FirstName,
MiddleName = x.MiddleName,
LastName = x.LastName,
JobDescription = x.JobDescription,
GradeId = x.GradeId,
BasicSalary = x.BasicSalary,
SalaryBankName = x.SalaryBankName,
SalaryBankAccountName = x.SalaryBankAccountName,
SalaryBankAccountNumber = x.SalaryBankAccountNumber,
PlaceOfBirth = x.PlaceOfBirth,
DateOfBirth = x.DateOfBirth,
Gender = x.Gender,
MaritalStatus = x.MaritalStatus,
Religion = x.Religion,
BloodType = x.BloodType,
IdentityNumber = x.IdentityNumber,
TaxNumber = x.TaxNumber,
LastEducation = x.LastEducation,
JoinedDate = x.JoinedDate,
ResignedDate = x.ResignedDate,
EmployeeStatus = x.EmployeeStatus,
EmploymentType = x.EmploymentType,
StreetAddress = x.StreetAddress,
City = x.City,
StateProvince = x.StateProvince,
ZipCode = x.ZipCode,
Phone = x.Phone,
Email = x.Email,
BranchId = x.BranchId,
DepartmentId = x.DepartmentId,
DesignationId = x.DesignationId,
SocialMediaLinkedIn = x.SocialMediaLinkedIn,
SocialMediaX = x.SocialMediaX,
SocialMediaFacebook = x.SocialMediaFacebook,
SocialMediaInstagram = x.SocialMediaInstagram,
SocialMediaTikTok = x.SocialMediaTikTok,
OtherInformation1 = x.OtherInformation1,
OtherInformation2 = x.OtherInformation2,
OtherInformation3 = x.OtherInformation3,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,41 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class GetEmployeeDeductionByIdResponse
{
public string? Id { get; set; }
public string? DeductionId { get; set; }
public string? DeductionName { get; set; }
public decimal Amount { get; set; }
public string? Description { get; set; }
public bool IsActive { get; set; }
}
public record GetEmployeeDeductionByIdQuery(string Id) : IRequest<GetEmployeeDeductionByIdResponse>;
public class GetEmployeeDeductionByIdHandler : IRequestHandler<GetEmployeeDeductionByIdQuery, GetEmployeeDeductionByIdResponse>
{
private readonly AppDbContext _context;
public GetEmployeeDeductionByIdHandler(AppDbContext context) => _context = context;
public async Task<GetEmployeeDeductionByIdResponse> Handle(GetEmployeeDeductionByIdQuery request, CancellationToken cancellationToken)
{
var data = await _context.EmployeeDeduction
.Where(x => x.Id == request.Id)
.Select(x => new GetEmployeeDeductionByIdResponse
{
Id = x.Id,
DeductionId = x.DeductionId,
DeductionName = x.Deduction != null ? x.Deduction.Name : string.Empty,
Amount = x.Amount,
Description = x.Description,
IsActive = x.IsActive
})
.FirstOrDefaultAsync(cancellationToken);
return data!;
}
}
@@ -0,0 +1,46 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class GetEmployeeDeductionListResponse
{
public string? Id { get; set; }
public string? DeductionId { get; set; }
public string? EmployeeCode { get; set; }
public string? DeductionName { get; set; }
public string? DeductionCategory { get; set; }
public decimal Amount { get; set; }
public string? Description { get; set; }
public bool IsActive { get; set; }
}
public record GetEmployeeDeductionListByEmployeeIdQuery(string EmployeeId) : IRequest<List<GetEmployeeDeductionListResponse>>;
public class GetEmployeeDeductionListByEmployeeIdHandler : IRequestHandler<GetEmployeeDeductionListByEmployeeIdQuery, List<GetEmployeeDeductionListResponse>>
{
private readonly AppDbContext _context;
public GetEmployeeDeductionListByEmployeeIdHandler(AppDbContext context) => _context = context;
public async Task<List<GetEmployeeDeductionListResponse>> Handle(GetEmployeeDeductionListByEmployeeIdQuery request, CancellationToken cancellationToken)
{
var data = await _context.EmployeeDeduction
.Where(x => x.EmployeeId == request.EmployeeId)
.Select(x => new GetEmployeeDeductionListResponse
{
Id = x.Id,
DeductionId = x.DeductionId,
EmployeeCode = x.Employee != null ? x.Employee.Code : string.Empty,
DeductionName = x.Deduction != null ? x.Deduction.Name : string.Empty,
DeductionCategory = x.Deduction != null ? x.Deduction.Category : string.Empty,
Amount = x.Amount,
Description = x.Description,
IsActive = x.IsActive
})
.OrderBy(x => x.DeductionName)
.ToListAsync(cancellationToken);
return data;
}
}
@@ -0,0 +1,41 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class GetEmployeeIncomeByIdResponse
{
public string? Id { get; set; }
public string? IncomeId { get; set; }
public string? IncomeName { get; set; }
public decimal Amount { get; set; }
public string? Description { get; set; }
public bool IsActive { get; set; }
}
public record GetEmployeeIncomeByIdQuery(string Id) : IRequest<GetEmployeeIncomeByIdResponse>;
public class GetEmployeeIncomeByIdHandler : IRequestHandler<GetEmployeeIncomeByIdQuery, GetEmployeeIncomeByIdResponse>
{
private readonly AppDbContext _context;
public GetEmployeeIncomeByIdHandler(AppDbContext context) => _context = context;
public async Task<GetEmployeeIncomeByIdResponse> Handle(GetEmployeeIncomeByIdQuery request, CancellationToken cancellationToken)
{
var data = await _context.EmployeeIncome
.Where(x => x.Id == request.Id)
.Select(x => new GetEmployeeIncomeByIdResponse
{
Id = x.Id,
IncomeId = x.IncomeId,
IncomeName = x.Income != null ? x.Income.Name : string.Empty,
Amount = x.Amount,
Description = x.Description,
IsActive = x.IsActive
})
.FirstOrDefaultAsync(cancellationToken);
return data!;
}
}
@@ -0,0 +1,46 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class GetEmployeeIncomeListResponse
{
public string? Id { get; set; }
public string? IncomeId { get; set; }
public string? EmployeeCode { get; set; }
public string? IncomeName { get; set; }
public string? IncomeType { get; set; }
public decimal Amount { get; set; }
public string? Description { get; set; }
public bool IsActive { get; set; }
}
public record GetEmployeeIncomeListByEmployeeIdQuery(string EmployeeId) : IRequest<List<GetEmployeeIncomeListResponse>>;
public class GetEmployeeIncomeListByEmployeeIdHandler : IRequestHandler<GetEmployeeIncomeListByEmployeeIdQuery, List<GetEmployeeIncomeListResponse>>
{
private readonly AppDbContext _context;
public GetEmployeeIncomeListByEmployeeIdHandler(AppDbContext context) => _context = context;
public async Task<List<GetEmployeeIncomeListResponse>> Handle(GetEmployeeIncomeListByEmployeeIdQuery request, CancellationToken cancellationToken)
{
var data = await _context.EmployeeIncome
.Where(x => x.EmployeeId == request.EmployeeId)
.Select(x => new GetEmployeeIncomeListResponse
{
Id = x.Id,
IncomeId = x.IncomeId,
EmployeeCode = x.Employee != null ? x.Employee.Code : string.Empty,
IncomeName = x.Income != null ? x.Income.Name : string.Empty,
IncomeType = x.Income != null ? x.Income.Type : string.Empty,
Amount = x.Amount,
Description = x.Description,
IsActive = x.IsActive
})
.OrderBy(x => x.IncomeName)
.ToListAsync(cancellationToken);
return data;
}
}
@@ -0,0 +1,53 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class GetEmployeeListResponse
{
public string Id { get; set; } = string.Empty;
public string? AutoNumber { get; set; }
public string Code { get; set; } = string.Empty;
public string FullName { get; set; } = string.Empty;
public string DesignationName { get; set; } = string.Empty;
public string DepartmentName { get; set; } = string.Empty;
public string BranchName { get; set; } = string.Empty;
public string EmployeeStatus { get; set; } = string.Empty;
public string? GradeName { get; set; }
public decimal? BasicSalary { get; set; }
}
public record GetEmployeeListQuery() : IRequest<List<GetEmployeeListResponse>>;
public class GetEmployeeListHandler : IRequestHandler<GetEmployeeListQuery, List<GetEmployeeListResponse>>
{
private readonly AppDbContext _context;
public GetEmployeeListHandler(AppDbContext context) => _context = context;
public async Task<List<GetEmployeeListResponse>> Handle(GetEmployeeListQuery request, CancellationToken cancellationToken)
{
var data = await _context.Employee
.Include(x => x.Grade)
.Include(x => x.Branch)
.Include(x => x.Department)
.Include(x => x.Designation)
.AsNoTracking()
.Select(x => new GetEmployeeListResponse
{
Id = x.Id,
Code = x.Code,
FullName = $"{x.FirstName} {x.MiddleName} {x.LastName}".Replace(" ", " "),
DesignationName = x.Designation!.Name,
DepartmentName = x.Department!.Name,
BranchName = x.Branch!.Name,
GradeName = x.Grade != null ? x.Grade.Name : string.Empty,
BasicSalary = x.BasicSalary
})
.ToListAsync(cancellationToken);
return data;
}
}
@@ -0,0 +1,78 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class LookupResponse
{
public List<LookupItem> Branches { get; set; } = new();
public List<LookupItem> Departments { get; set; } = new();
public List<LookupItem> Designations { get; set; } = new();
public List<LookupItem> Grades { get; set; } = new();
public List<LookupItem> Incomes { get; set; } = new();
public List<LookupItem> Deductions { get; set; } = new();
}
public class LookupItem
{
public string? Id { get; set; }
public string? Name { get; set; }
public string? Code { get; set; }
public decimal SalaryFrom { get; set; }
public decimal SalaryTo { get; set; }
}
public record LookupQuery() : IRequest<LookupResponse>;
public class LookupHandler : IRequestHandler<LookupQuery, LookupResponse>
{
private readonly AppDbContext _context;
public LookupHandler(AppDbContext context) => _context = context;
public async Task<LookupResponse> Handle(LookupQuery request, CancellationToken cancellationToken)
{
var response = new LookupResponse();
response.Branches = await _context.Branch
.AsNoTracking()
.Select(x => new LookupItem { Id = x.Id, Name = x.Name, Code = x.Code })
.ToListAsync(cancellationToken);
response.Departments = await _context.Department
.AsNoTracking()
.Select(x => new LookupItem { Id = x.Id, Name = x.Name, Code = x.CostCenter })
.ToListAsync(cancellationToken);
response.Designations = await _context.Designation
.AsNoTracking()
.Select(x => new LookupItem { Id = x.Id, Name = x.Name, Code = x.Code })
.ToListAsync(cancellationToken);
response.Grades = await _context.Grade
.AsNoTracking()
.Select(x => new LookupItem
{
Id = x.Id,
Name = x.Name,
Code = x.Code,
SalaryFrom = x.SalaryFrom,
SalaryTo = x.SalaryTo
})
.ToListAsync(cancellationToken);
response.Incomes = await _context.Income
.AsNoTracking()
.Where(x => x.Status == "Active")
.Select(x => new LookupItem { Id = x.Id, Name = x.Name, Code = x.Code })
.ToListAsync(cancellationToken);
response.Deductions = await _context.Deduction
.AsNoTracking()
.Where(x => x.Status == "Active")
.Select(x => new LookupItem { Id = x.Id, Name = x.Name, Code = x.Code })
.ToListAsync(cancellationToken);
return response;
}
}
@@ -0,0 +1,45 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class UpdateEmployeeDeductionRequest
{
public string? Id { get; set; }
public string? DeductionId { get; set; }
public decimal Amount { get; set; }
public string? Description { get; set; }
public bool IsActive { get; set; }
}
public class UpdateEmployeeDeductionResponse
{
public string? Id { get; set; }
}
public record UpdateEmployeeDeductionCommand(UpdateEmployeeDeductionRequest Data) : IRequest<UpdateEmployeeDeductionResponse>;
public class UpdateEmployeeDeductionHandler : IRequestHandler<UpdateEmployeeDeductionCommand, UpdateEmployeeDeductionResponse>
{
private readonly AppDbContext _context;
public UpdateEmployeeDeductionHandler(AppDbContext context) => _context = context;
public async Task<UpdateEmployeeDeductionResponse> Handle(UpdateEmployeeDeductionCommand request, CancellationToken cancellationToken)
{
var entity = await _context.EmployeeDeduction
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) throw new NotFoundException("EmployeeDeduction", request.Data.Id ?? string.Empty);
entity.DeductionId = request.Data.DeductionId;
entity.Amount = request.Data.Amount;
entity.Description = request.Data.Description;
entity.IsActive = request.Data.IsActive;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateEmployeeDeductionResponse { Id = entity.Id };
}
}
@@ -0,0 +1,15 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class UpdateEmployeeDeductionValidator : AbstractValidator<UpdateEmployeeDeductionRequest>
{
public UpdateEmployeeDeductionValidator()
{
RuleFor(x => x.Id).NotEmpty().WithMessage("ID is required");
RuleFor(x => x.DeductionId).NotEmpty().WithMessage("Deduction component is required");
RuleFor(x => x.Amount).GreaterThanOrEqualTo(0).WithMessage("Amount must be 0 or greater");
RuleFor(x => x.Description).MaximumLength(GlobalConsts.StringLengthShort);
}
}
@@ -0,0 +1,82 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class UpdateEmployeeRequest : CreateEmployeeRequest
{
public string Id { get; set; } = string.Empty;
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdateEmployeeResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdateEmployeeCommand(UpdateEmployeeRequest Data) : IRequest<UpdateEmployeeResponse>;
public class UpdateEmployeeHandler : IRequestHandler<UpdateEmployeeCommand, UpdateEmployeeResponse>
{
private readonly AppDbContext _context;
public UpdateEmployeeHandler(AppDbContext context) => _context = context;
public async Task<UpdateEmployeeResponse> Handle(UpdateEmployeeCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Employee.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return new UpdateEmployeeResponse { Id = request.Data.Id, Success = false };
var isExists = await _context.Employee.AnyAsync(x => x.Code == request.Data.Code && x.Id != request.Data.Id, cancellationToken);
if (isExists) throw new AlreadyExistsException("Employee", request.Data.Code);
entity.Code = request.Data.Code;
entity.FirstName = request.Data.FirstName;
entity.MiddleName = request.Data.MiddleName;
entity.LastName = request.Data.LastName;
entity.JobDescription = request.Data.JobDescription;
entity.GradeId = request.Data.GradeId;
entity.BasicSalary = request.Data.BasicSalary;
entity.SalaryBankName = request.Data.SalaryBankName;
entity.SalaryBankAccountName = request.Data.SalaryBankAccountName;
entity.SalaryBankAccountNumber = request.Data.SalaryBankAccountNumber;
entity.PlaceOfBirth = request.Data.PlaceOfBirth;
entity.DateOfBirth = request.Data.DateOfBirth;
entity.Gender = request.Data.Gender;
entity.MaritalStatus = request.Data.MaritalStatus;
entity.Religion = request.Data.Religion;
entity.BloodType = request.Data.BloodType;
entity.IdentityNumber = request.Data.IdentityNumber;
entity.TaxNumber = request.Data.TaxNumber;
entity.LastEducation = request.Data.LastEducation;
entity.JoinedDate = request.Data.JoinedDate;
entity.ResignedDate = request.Data.ResignedDate;
entity.EmployeeStatus = request.Data.EmployeeStatus;
entity.EmploymentType = request.Data.EmploymentType;
entity.StreetAddress = request.Data.StreetAddress;
entity.City = request.Data.City;
entity.StateProvince = request.Data.StateProvince;
entity.ZipCode = request.Data.ZipCode;
entity.Phone = request.Data.Phone;
entity.Email = request.Data.Email;
entity.BranchId = request.Data.BranchId;
entity.DepartmentId = request.Data.DepartmentId;
entity.DesignationId = request.Data.DesignationId;
entity.SocialMediaLinkedIn = request.Data.SocialMediaLinkedIn;
entity.SocialMediaX = request.Data.SocialMediaX;
entity.SocialMediaFacebook = request.Data.SocialMediaFacebook;
entity.SocialMediaInstagram = request.Data.SocialMediaInstagram;
entity.SocialMediaTikTok = request.Data.SocialMediaTikTok;
entity.OtherInformation1 = request.Data.OtherInformation1;
entity.OtherInformation2 = request.Data.OtherInformation2;
entity.OtherInformation3 = request.Data.OtherInformation3;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateEmployeeResponse { Id = entity.Id, Success = true };
}
}
@@ -0,0 +1,45 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class UpdateEmployeeIncomeRequest
{
public string? Id { get; set; }
public string? IncomeId { get; set; }
public decimal Amount { get; set; }
public string? Description { get; set; }
public bool IsActive { get; set; }
}
public class UpdateEmployeeIncomeResponse
{
public string? Id { get; set; }
}
public record UpdateEmployeeIncomeCommand(UpdateEmployeeIncomeRequest Data) : IRequest<UpdateEmployeeIncomeResponse>;
public class UpdateEmployeeIncomeHandler : IRequestHandler<UpdateEmployeeIncomeCommand, UpdateEmployeeIncomeResponse>
{
private readonly AppDbContext _context;
public UpdateEmployeeIncomeHandler(AppDbContext context) => _context = context;
public async Task<UpdateEmployeeIncomeResponse> Handle(UpdateEmployeeIncomeCommand request, CancellationToken cancellationToken)
{
var entity = await _context.EmployeeIncome
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) throw new NotFoundException("EmployeeIncome", request.Data.Id ?? string.Empty);
entity.IncomeId = request.Data.IncomeId;
entity.Amount = request.Data.Amount;
entity.Description = request.Data.Description;
entity.IsActive = request.Data.IsActive;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateEmployeeIncomeResponse { Id = entity.Id };
}
}
@@ -0,0 +1,15 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class UpdateEmployeeIncomeValidator : AbstractValidator<UpdateEmployeeIncomeRequest>
{
public UpdateEmployeeIncomeValidator()
{
RuleFor(x => x.Id).NotEmpty().WithMessage("ID is required");
RuleFor(x => x.IncomeId).NotEmpty().WithMessage("Income component is required");
RuleFor(x => x.Amount).GreaterThanOrEqualTo(0).WithMessage("Amount must be 0 or greater");
RuleFor(x => x.Description).MaximumLength(GlobalConsts.StringLengthShort);
}
}
@@ -0,0 +1,44 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class UpdateEmployeeValidator : AbstractValidator<UpdateEmployeeRequest>
{
public UpdateEmployeeValidator()
{
RuleFor(x => x.Id)
.NotEmpty().WithMessage("Employee ID is required for update");
RuleFor(x => x.Code)
.NotEmpty().WithMessage("Employee Code is required")
.MaximumLength(GlobalConsts.StringLengthShort).WithMessage($"Code cannot exceed {GlobalConsts.StringLengthShort} characters");
RuleFor(x => x.FirstName)
.NotEmpty().WithMessage("First Name is required")
.MaximumLength(GlobalConsts.StringLengthShort).WithMessage($"First Name cannot exceed {GlobalConsts.StringLengthShort} characters");
RuleFor(x => x.LastName)
.NotEmpty().WithMessage("Last Name is required")
.MaximumLength(GlobalConsts.StringLengthShort).WithMessage($"Last Name cannot exceed {GlobalConsts.StringLengthShort} characters");
RuleFor(x => x.Email)
.NotEmpty().WithMessage("Email is required")
.EmailAddress().WithMessage("Invalid email format");
RuleFor(x => x.BranchId)
.NotEmpty().WithMessage("Please select a Branch");
RuleFor(x => x.DepartmentId)
.NotEmpty().WithMessage("Please select a Department");
RuleFor(x => x.DesignationId)
.NotEmpty().WithMessage("Please select a Designation");
RuleFor(x => x.GradeId)
.NotEmpty().WithMessage("Please select a Salary Grade");
RuleFor(x => x.BasicSalary)
.GreaterThan(0).WithMessage("Basic Salary must be greater than 0");
}
}
@@ -0,0 +1,66 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Features.Organization.Employee.Cqrs;
using MediatR;
using Microsoft.AspNetCore.Authentication.JwtBearer;
namespace Indotalent.Features.Organization.Employee;
public static class EmployeeEndpoint
{
public static void MapEmployeeEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("/employee")
.WithTags("Employees")
.RequireAuthorization(policy =>
policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
.RequireAuthenticatedUser());
group.MapGet("/", async (IMediator mediator) =>
(await mediator.Send(new GetEmployeeListQuery())).ToApiResponse("Employee list retrieved successfully"));
group.MapGet("/lookup", async (IMediator mediator) =>
(await mediator.Send(new LookupQuery())).ToApiResponse("Lookups retrieved successfully"));
group.MapGet("/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new GetEmployeeByIdQuery(id))).ToApiResponse("Employee detail retrieved successfully"));
group.MapPost("/", async (CreateEmployeeRequest request, IMediator mediator) =>
(await mediator.Send(new CreateEmployeeCommand(request))).ToApiResponse("Employee created successfully", StatusCodes.Status201Created));
group.MapPost("/update", async (UpdateEmployeeRequest request, IMediator mediator) =>
(await mediator.Send(new UpdateEmployeeCommand(request))).ToApiResponse("Employee updated successfully"));
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new DeleteEmployeeByIdCommand(new DeleteEmployeeByIdRequest(id)))).ToApiResponse("Employee deleted successfully"));
group.MapGet("/income/list/{employeeId}", async (string employeeId, IMediator mediator) =>
(await mediator.Send(new GetEmployeeIncomeListByEmployeeIdQuery(employeeId))).ToApiResponse("Employee income list retrieved"));
group.MapGet("/income/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new GetEmployeeIncomeByIdQuery(id))).ToApiResponse("Employee income detail retrieved"));
group.MapPost("/income", async (CreateEmployeeIncomeRequest request, IMediator mediator) =>
(await mediator.Send(new CreateEmployeeIncomeCommand(request))).ToApiResponse("Employee income created", StatusCodes.Status201Created));
group.MapPost("/income/update", async (UpdateEmployeeIncomeRequest request, IMediator mediator) =>
(await mediator.Send(new UpdateEmployeeIncomeCommand(request))).ToApiResponse("Employee income updated"));
group.MapPost("/income/delete/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new DeleteEmployeeIncomeByIdCommand(new DeleteEmployeeIncomeByIdRequest(id)))).ToApiResponse("Employee income deleted successfully"));
group.MapGet("/deduction/list/{employeeId}", async (string employeeId, IMediator mediator) =>
(await mediator.Send(new GetEmployeeDeductionListByEmployeeIdQuery(employeeId))).ToApiResponse("Employee deduction list retrieved"));
group.MapGet("/deduction/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new GetEmployeeDeductionByIdQuery(id))).ToApiResponse("Employee deduction detail retrieved"));
group.MapPost("/deduction", async (CreateEmployeeDeductionRequest request, IMediator mediator) =>
(await mediator.Send(new CreateEmployeeDeductionCommand(request))).ToApiResponse("Employee deduction created", StatusCodes.Status201Created));
group.MapPost("/deduction/update", async (UpdateEmployeeDeductionRequest request, IMediator mediator) =>
(await mediator.Send(new UpdateEmployeeDeductionCommand(request))).ToApiResponse("Employee deduction updated"));
group.MapPost("/deduction/delete/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new DeleteEmployeeDeductionByIdCommand(new DeleteEmployeeDeductionByIdRequest(id)))).ToApiResponse("Employee deduction deleted successfully"));
}
}
@@ -0,0 +1,130 @@
using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Organization.Employee.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;
namespace Indotalent.Features.Organization.Employee;
public class EmployeeService : BaseService
{
private readonly RestClient _client;
public EmployeeService(IHttpClientFactory clientFactory, NavigationManager nav, ISnackbar snackbar, ICurrentUserService currentUserService, TokenProvider tokenProvider)
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
{
_client = new RestClient(nav.BaseUri);
}
// --- Employee Core ---
public async Task<ApiResponse<List<GetEmployeeListResponse>>?> GetEmployeeListAsync()
{
var request = new RestRequest("api/employee", Method.Get);
return await ExecuteWithResponseAsync<List<GetEmployeeListResponse>>(_client, request);
}
public async Task<ApiResponse<LookupResponse>?> GetLookupAsync()
{
var request = new RestRequest("api/employee/lookup", Method.Get);
return await ExecuteWithResponseAsync<LookupResponse>(_client, request);
}
public async Task<ApiResponse<GetEmployeeByIdResponse>?> GetEmployeeByIdAsync(string id)
{
var request = new RestRequest($"api/employee/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetEmployeeByIdResponse>(_client, request);
}
public async Task<ApiResponse<CreateEmployeeResponse>?> CreateEmployeeAsync(CreateEmployeeRequest data)
{
var request = new RestRequest("api/employee", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreateEmployeeResponse>(_client, request);
}
public async Task<ApiResponse<UpdateEmployeeResponse>?> UpdateEmployeeAsync(UpdateEmployeeRequest data)
{
var request = new RestRequest("api/employee/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdateEmployeeResponse>(_client, request);
}
public async Task<bool> DeleteEmployeeByIdAsync(string id)
{
var request = new RestRequest($"api/employee/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
// --- Employee Income ---
public async Task<ApiResponse<List<GetEmployeeIncomeListResponse>>?> GetEmployeeIncomeListAsync(string employeeId)
{
var request = new RestRequest($"api/employee/income/list/{employeeId}", Method.Get);
return await ExecuteWithResponseAsync<List<GetEmployeeIncomeListResponse>>(_client, request);
}
public async Task<ApiResponse<CreateEmployeeIncomeResponse>?> CreateEmployeeIncomeAsync(CreateEmployeeIncomeRequest data)
{
var request = new RestRequest("api/employee/income", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreateEmployeeIncomeResponse>(_client, request);
}
public async Task<ApiResponse<UpdateEmployeeIncomeResponse>?> UpdateEmployeeIncomeAsync(UpdateEmployeeIncomeRequest data)
{
var request = new RestRequest("api/employee/income/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdateEmployeeIncomeResponse>(_client, request);
}
public async Task<bool> DeleteEmployeeIncomeByIdAsync(string id)
{
var request = new RestRequest($"api/employee/income/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
public async Task<ApiResponse<GetEmployeeIncomeByIdResponse>?> GetEmployeeIncomeByIdAsync(string id)
{
var request = new RestRequest($"api/employee/income/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetEmployeeIncomeByIdResponse>(_client, request);
}
// --- Employee Deduction ---
public async Task<ApiResponse<List<GetEmployeeDeductionListResponse>>?> GetEmployeeDeductionListAsync(string employeeId)
{
var request = new RestRequest($"api/employee/deduction/list/{employeeId}", Method.Get);
return await ExecuteWithResponseAsync<List<GetEmployeeDeductionListResponse>>(_client, request);
}
public async Task<ApiResponse<CreateEmployeeDeductionResponse>?> CreateEmployeeDeductionAsync(CreateEmployeeDeductionRequest data)
{
var request = new RestRequest("api/employee/deduction", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<CreateEmployeeDeductionResponse>(_client, request);
}
public async Task<ApiResponse<UpdateEmployeeDeductionResponse>?> UpdateEmployeeDeductionAsync(UpdateEmployeeDeductionRequest data)
{
var request = new RestRequest("api/employee/deduction/update", Method.Post);
request.AddJsonBody(data);
return await ExecuteWithResponseAsync<UpdateEmployeeDeductionResponse>(_client, request);
}
public async Task<bool> DeleteEmployeeDeductionByIdAsync(string id)
{
var request = new RestRequest($"api/employee/deduction/delete/{id}", Method.Post);
var response = await ExecuteWithResponseAsync<object>(_client, request);
return response?.IsSuccess ?? false;
}
public async Task<ApiResponse<GetEmployeeDeductionByIdResponse>?> GetEmployeeDeductionByIdAsync(string id)
{
var request = new RestRequest($"api/employee/deduction/{id}", Method.Get);
return await ExecuteWithResponseAsync<GetEmployeeDeductionByIdResponse>(_client, request);
}
}
@@ -0,0 +1,104 @@
@page "/organization"
@using Indotalent.Features.Organization.Employee.Components
@using Microsoft.AspNetCore.Authorization
@using Indotalent.Infrastructure.Authorization.Identity
@attribute [Authorize(Roles = $"{ApplicationRoles.Admin},{ApplicationRoles.Member}")]
@using Indotalent.Features.Organization.Branch
@using Indotalent.Features.Organization.Branch.Components
@using Indotalent.Features.Organization.Department
@using Indotalent.Features.Organization.Department.Components
@using Indotalent.Features.Organization.Designation
@using Indotalent.Features.Organization.Designation.Components
@using MudBlazor
@inject NavigationManager NavigationManager
<style>
.clean-white-tabs .mud-tabs-toolbar {
background-color: white !important;
border-bottom: 2px solid #DCEBFA;
border-radius: 0px !important;
}
.clean-white-tabs .mud-tab {
color: #94a3b8 !important;
text-transform: none;
font-weight: 500;
min-width: 160px;
border-radius: 0px !important;
}
.clean-white-tabs .mud-tab-active {
color: var(--mud-palette-primary) !important;
font-weight: 800;
}
.clean-white-tabs .mud-tabs-slider {
background-color: var(--mud-palette-primary) !important;
height: 3px !important;
bottom: 0;
}
</style>
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="mt-2 mb-8">
<div class="clean-white-tabs">
<MudTabs Elevation="0"
ActivePanelIndex="@_activeTabIndex"
ActivePanelIndexChanged="OnTabChanged"
ApplyEffectsToContainer="true"
TabPanelsClass="pt-4">
<MudTabPanel Text="Branches" Icon="@Icons.Material.Outlined.LocationOn">
<BranchPage />
</MudTabPanel>
<MudTabPanel Text="Departments" Icon="@Icons.Material.Outlined.AccountTree">
<DepartmentPage />
</MudTabPanel>
<MudTabPanel Text="Designations" Icon="@Icons.Material.Outlined.Badge">
<DesignationPage />
</MudTabPanel>
<MudTabPanel Text="Employees" Icon="@Icons.Material.Outlined.Groups">
<EmployeePage />
</MudTabPanel>
</MudTabs>
</div>
</MudContainer>
@code {
private int _activeTabIndex = 0;
protected override void OnInitialized()
{
var uri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
if (Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query).TryGetValue("tab", out var tabValue))
{
_activeTabIndex = tabValue.ToString().ToLower() switch
{
"branch" => 0,
"department" => 1,
"designation" => 2,
"employee" => 3,
_ => 0
};
}
}
private void OnTabChanged(int index)
{
_activeTabIndex = index;
string tabName = index switch
{
0 => "branch",
1 => "department",
2 => "designation",
3 => "employee",
_ => "branch"
};
NavigationManager.NavigateTo($"/organization?tab={tabName}", replace: false);
}
}