initial commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Utilities.BookingGroup.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingGroup;
|
||||
|
||||
public static class BookingGroupEndpoint
|
||||
{
|
||||
public static void MapBookingGroupEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/booking-group").WithTags("BookingGroups")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetBookingGroupListQuery());
|
||||
|
||||
return result.ToApiResponse("Booking group list retrieved successfully");
|
||||
})
|
||||
.WithName("GetBookingGroupList")
|
||||
.WithTags("BookingGroups");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetBookingGroupByIdQuery(id));
|
||||
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Booking group detail retrieved successfully"
|
||||
: $"Booking group with ID {id} not found");
|
||||
})
|
||||
.WithName("GetBookingGroupById")
|
||||
.WithTags("BookingGroups");
|
||||
|
||||
group.MapPost("/", async (CreateBookingGroupRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateBookingGroupCommand(request));
|
||||
|
||||
return result.ToApiResponse("Booking group has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateBookingGroup")
|
||||
.WithTags("BookingGroups");
|
||||
|
||||
group.MapPost("/update", async (UpdateBookingGroupRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateBookingGroupCommand(request));
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The booking group data could not be found.");
|
||||
}
|
||||
|
||||
return result.ToApiResponse("Booking group has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateBookingGroup")
|
||||
.WithTags("BookingGroups");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteBookingGroupByIdCommand(new DeleteBookingGroupByIdRequest(id)));
|
||||
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The booking group data could not be found.");
|
||||
}
|
||||
|
||||
return true.ToApiResponse("Booking group has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteBookingGroupById")
|
||||
.WithTags("BookingGroups");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Utilities.BookingGroup.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingGroup;
|
||||
|
||||
public class BookingGroupService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public BookingGroupService(
|
||||
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<GetBookingGroupListResponse>>?> GetBookingGroupListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/booking-group", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetBookingGroupListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetBookingGroupByIdResponse>?> GetBookingGroupByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/booking-group/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetBookingGroupByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateBookingGroupResponse>?> CreateBookingGroupAsync(CreateBookingGroupRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/booking-group", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateBookingGroupResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteBookingGroupByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/booking-group/delete/{id}", Method.Post);
|
||||
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateBookingGroupResponse>?> UpdateBookingGroupAsync(UpdateBookingGroupRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/booking-group/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateBookingGroupResponse>(_client, request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
@page "/utilities/booking-group"
|
||||
@using Indotalent.Features.Utilities.BookingGroup
|
||||
@using Indotalent.Features.Utilities.BookingGroup.Cqrs
|
||||
@using Indotalent.Features.Utilities.BookingGroup.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_BookingGroupCreateForm OnCancel="BackToTable"
|
||||
OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_BookingGroupUpdateForm Data="_selectedData!"
|
||||
ReadOnly="@(_currentView == ViewMode.View)"
|
||||
OnCancel="BackToTable"
|
||||
OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_BookingGroupDataTable 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 UpdateBookingGroupRequest? _selectedData;
|
||||
|
||||
private void ShowCreate()
|
||||
{
|
||||
_currentView = ViewMode.Create;
|
||||
}
|
||||
|
||||
private void ShowUpdate(UpdateBookingGroupRequest 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,97 @@
|
||||
@using Indotalent.Features.Utilities.BookingGroup
|
||||
@using Indotalent.Features.Utilities.BookingGroup.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject BookingGroupService BookingGroupService
|
||||
@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 Booking Group</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Enter details for the new booking group classification.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Group Name</MudText>
|
||||
<MudTextField @bind-Value="_model.Name"
|
||||
For="@(() => _model.Name)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. Regular Group" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description"
|
||||
For="@(() => _model.Description)"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" 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-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">
|
||||
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 Booking Group</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
|
||||
private MudForm _form = default!;
|
||||
private CreateBookingGroupValidator _validator = new();
|
||||
private CreateBookingGroupRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await BookingGroupService.CreateBookingGroupAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Booking group created successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.BookingGroup
|
||||
@using Indotalent.Features.Utilities.BookingGroup.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject BookingGroupService BookingGroupService
|
||||
@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: 600; color: #111827;">Booking Group Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Manage booking group categories and classifications.</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;">Utilities</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Booking Group</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;">
|
||||
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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; 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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; 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 (_selectedBookingGroup != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedBookingGroup = 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;">
|
||||
Add New Booking Group
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Items="@GetPagedData()" Striped="true" Class="mud-table-styled" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetBookingGroupListResponse" OnRowClick="@((args) => _selectedBookingGroup = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #ffffff; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetBookingGroupListResponse, object>(x => x.Name!)">Group Name</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Description</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>
|
||||
<MudCheckBox T="bool" Value="@(_selectedBookingGroup?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudAvatar Color="Color.Info" Variant="Variant.Filled" Size="Size.Small" Style="border-radius: 50%; font-size: 10px; font-weight: 800;">
|
||||
@(!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; color: #374151; font-size: 0.875rem;">@context.Description</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="color: #9CA3AF; margin-left: 12px; font-size: 0.75rem; font-weight: 500;">
|
||||
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;")" />
|
||||
<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: #374151; border: 1px solid #D1D5DB; border-radius: 6px; background: white;")">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: #374151; border: 1px solid #D1D5DB; border-radius: 6px; background: white;")">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;" : "background-color: white; border: 1px solid #D1D5DB; color: #6B7280;")" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<style>
|
||||
.mud-input-outlined-border { border-radius: 8px !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<UpdateBookingGroupRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateBookingGroupRequest> OnView { get; set; }
|
||||
|
||||
private List<GetBookingGroupListResponse> _bookingGroups = new();
|
||||
private GetBookingGroupListResponse? _selectedBookingGroup;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
|
||||
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;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedBookingGroup = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var response = await BookingGroupService.GetBookingGroupListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_bookingGroups = response.Value ?? new List<GetBookingGroupListResponse>();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRefreshing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GetBookingGroupListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _bookingGroups;
|
||||
return _bookingGroups.Where(x =>
|
||||
(x.Name?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.Description?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
private IEnumerable<GetBookingGroupListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private void OnSearchClick()
|
||||
{
|
||||
_skip = 0;
|
||||
_selectedBookingGroup = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Enter") OnSearchClick();
|
||||
}
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("BookingGroups");
|
||||
var currentRow = 1;
|
||||
|
||||
worksheet.Cell(currentRow, 1).Value = "Group Name";
|
||||
worksheet.Cell(currentRow, 2).Value = "Description";
|
||||
|
||||
var headerRange = worksheet.Range(1, 1, 1, 2);
|
||||
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.Name;
|
||||
worksheet.Cell(currentRow, 2).Value = item.Description;
|
||||
}
|
||||
|
||||
worksheet.Columns().AdjustToContents();
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "BookingGroups_List.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 OnPageChanged(int page)
|
||||
{
|
||||
if (page >= 1 && page <= _totalPage)
|
||||
{
|
||||
_skip = (page - 1) * _top;
|
||||
_selectedBookingGroup = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageSizeChanged(int size)
|
||||
{
|
||||
_top = size;
|
||||
_skip = 0;
|
||||
_selectedBookingGroup = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task InvokeEdit()
|
||||
{
|
||||
if (_selectedBookingGroup == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedBookingGroup.Id!);
|
||||
if (request != null) await OnEdit.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task InvokeView()
|
||||
{
|
||||
if (_selectedBookingGroup == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedBookingGroup.Id!);
|
||||
if (request != null) await OnView.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task<UpdateBookingGroupRequest?> MapToUpdateRequest(string id)
|
||||
{
|
||||
var response = await BookingGroupService.GetBookingGroupByIdAsync(id);
|
||||
if (response != null && response.IsSuccess && response.Value != null)
|
||||
{
|
||||
var detail = response.Value;
|
||||
return new UpdateBookingGroupRequest
|
||||
{
|
||||
Id = detail.Id,
|
||||
Name = detail.Name,
|
||||
Description = detail.Description,
|
||||
CreatedAt = detail.CreatedAt,
|
||||
CreatedBy = detail.CreatedBy,
|
||||
UpdatedAt = detail.UpdatedAt,
|
||||
UpdatedBy = detail.UpdatedBy
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedBookingGroup == null) return;
|
||||
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedBookingGroup.Name } };
|
||||
var options = new DialogOptions { CloseButton = false, MaxWidth = MaxWidth.ExtraSmall, FullWidth = true };
|
||||
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, options);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
var isSuccess = await BookingGroupService.DeleteBookingGroupByIdAsync(_selectedBookingGroup.Id!);
|
||||
if (isSuccess)
|
||||
{
|
||||
_selectedBookingGroup = null;
|
||||
await LoadData();
|
||||
Snackbar.Add("Booking group deleted successfully", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Delete failed. This record might be protected.", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.BookingGroup
|
||||
@using Indotalent.Features.Utilities.BookingGroup.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject BookingGroupService BookingGroupService
|
||||
@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 ? "Booking Group Details" : "Edit Booking Group")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing booking group specification." : "Modify existing booking group information.")</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Group 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">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description"
|
||||
For="@(() => _model.Description)"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" 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-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">
|
||||
@(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 UpdateBookingGroupRequest 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 UpdateBookingGroupValidator _validator = new();
|
||||
private UpdateBookingGroupRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_model = new UpdateBookingGroupRequest
|
||||
{
|
||||
Id = Data.Id,
|
||||
Name = Data.Name,
|
||||
Description = Data.Description,
|
||||
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 BookingGroupService.UpdateBookingGroupAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Booking group updated successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingGroup.Cqrs;
|
||||
|
||||
public class CreateBookingGroupRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public class CreateBookingGroupResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record CreateBookingGroupCommand(CreateBookingGroupRequest Data) : IRequest<CreateBookingGroupResponse>;
|
||||
|
||||
public class CreateBookingGroupHandler : IRequestHandler<CreateBookingGroupCommand, CreateBookingGroupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateBookingGroupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateBookingGroupResponse> Handle(CreateBookingGroupCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var isExists = await _context.BookingGroup
|
||||
.AnyAsync(x => x.Name == request.Data.Name, cancellationToken);
|
||||
|
||||
if (isExists)
|
||||
{
|
||||
throw new AlreadyExistsException("Booking Group", request.Data.Name ?? string.Empty);
|
||||
}
|
||||
|
||||
var entity = new Data.Entities.BookingGroup
|
||||
{
|
||||
Name = request.Data.Name,
|
||||
Description = request.Data.Description
|
||||
};
|
||||
|
||||
_context.BookingGroup.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateBookingGroupResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingGroup.Cqrs;
|
||||
|
||||
public class CreateBookingGroupValidator : AbstractValidator<CreateBookingGroupRequest>
|
||||
{
|
||||
public CreateBookingGroupValidator()
|
||||
{
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingGroup.Cqrs;
|
||||
|
||||
public class DeleteBookingGroupByIdRequest
|
||||
{
|
||||
public DeleteBookingGroupByIdRequest(string id) => Id = id;
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public record DeleteBookingGroupByIdCommand(DeleteBookingGroupByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteBookingGroupByIdHandler : IRequestHandler<DeleteBookingGroupByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteBookingGroupByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteBookingGroupByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.BookingGroup
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_context.BookingGroup.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingGroup.Cqrs;
|
||||
|
||||
public class GetBookingGroupByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetBookingGroupByIdQuery(string Id) : IRequest<GetBookingGroupByIdResponse?>;
|
||||
|
||||
public class GetBookingGroupByIdHandler : IRequestHandler<GetBookingGroupByIdQuery, GetBookingGroupByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetBookingGroupByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetBookingGroupByIdResponse?> Handle(GetBookingGroupByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.BookingGroup
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetBookingGroupByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
Description = x.Description,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingGroup.Cqrs;
|
||||
|
||||
public class GetBookingGroupListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetBookingGroupListQuery() : IRequest<List<GetBookingGroupListResponse>>;
|
||||
|
||||
public class GetBookingGroupListHandler : IRequestHandler<GetBookingGroupListQuery, List<GetBookingGroupListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetBookingGroupListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetBookingGroupListResponse>> Handle(GetBookingGroupListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.BookingGroup
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new GetBookingGroupListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
Description = x.Description,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingGroup.Cqrs;
|
||||
|
||||
public class UpdateBookingGroupRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateBookingGroupResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateBookingGroupCommand(UpdateBookingGroupRequest Data) : IRequest<UpdateBookingGroupResponse>;
|
||||
|
||||
public class UpdateBookingGroupHandler : IRequestHandler<UpdateBookingGroupCommand, UpdateBookingGroupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateBookingGroupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateBookingGroupResponse> Handle(UpdateBookingGroupCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var isExists = await _context.BookingGroup
|
||||
.AnyAsync(x => x.Name == request.Data.Name && x.Id != request.Data.Id, cancellationToken);
|
||||
|
||||
if (isExists)
|
||||
{
|
||||
throw new AlreadyExistsException("Booking Group", request.Data.Name ?? string.Empty);
|
||||
}
|
||||
|
||||
var entity = await _context.BookingGroup
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateBookingGroupResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Name = request.Data.Name;
|
||||
entity.Description = request.Data.Description;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateBookingGroupResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingGroup.Cqrs;
|
||||
|
||||
public class UpdateBookingGroupValidator : AbstractValidator<UpdateBookingGroupRequest>
|
||||
{
|
||||
public UpdateBookingGroupValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required");
|
||||
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Utilities.BookingManager.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingManager;
|
||||
|
||||
public static class BookingManagerEndpoint
|
||||
{
|
||||
public static void MapBookingManagerEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/booking-manager").WithTags("BookingManager")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetBookingListQuery());
|
||||
return result.ToApiResponse("Booking list retrieved successfully");
|
||||
})
|
||||
.WithName("GetBookingList")
|
||||
.WithTags("BookingManager");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetBookingByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Booking detail retrieved successfully"
|
||||
: $"Booking with ID {id} not found");
|
||||
})
|
||||
.WithName("GetBookingById")
|
||||
.WithTags("BookingManager");
|
||||
|
||||
group.MapGet("/lookup-data", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new LookupBookingDataQuery());
|
||||
return result.ToApiResponse("Booking lookup data retrieved successfully");
|
||||
})
|
||||
.WithName("GetBookingLookupData")
|
||||
.WithTags("BookingManager");
|
||||
|
||||
group.MapPost("/", async (CreateBookingRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateBookingCommand(request));
|
||||
return result.ToApiResponse("Booking has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateBooking")
|
||||
.WithTags("BookingManager");
|
||||
|
||||
group.MapPost("/update", async (UpdateBookingRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateBookingCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The booking data could not be found.");
|
||||
}
|
||||
return result.ToApiResponse("Booking has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateBooking")
|
||||
.WithTags("BookingManager");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteBookingByIdCommand(new DeleteBookingByIdRequest(id)));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The booking data could not be found.");
|
||||
}
|
||||
return true.ToApiResponse("Booking has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteBookingById")
|
||||
.WithTags("BookingManager");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Utilities.BookingManager.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingManager;
|
||||
|
||||
public class BookingManagerService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public BookingManagerService(
|
||||
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<GetBookingListResponse>>?> GetBookingListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/booking-manager", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetBookingListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetBookingByIdResponse>?> GetBookingByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/booking-manager/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetBookingByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<LookupBookingDataResponse>?> GetLookupDataAsync()
|
||||
{
|
||||
var request = new RestRequest("api/booking-manager/lookup-data", Method.Get);
|
||||
return await ExecuteWithResponseAsync<LookupBookingDataResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateBookingResponse>?> CreateBookingAsync(CreateBookingRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/booking-manager", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateBookingResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteBookingByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/booking-manager/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateBookingResponse>?> UpdateBookingAsync(UpdateBookingRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/booking-manager/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateBookingResponse>(_client, request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
@page "/utilities/booking"
|
||||
@using Indotalent.Features.Utilities.BookingManager
|
||||
@using Indotalent.Features.Utilities.BookingManager.Cqrs
|
||||
@using Indotalent.Features.Utilities.BookingManager.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_BookingCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_BookingUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_BookingDataTable 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 UpdateBookingRequest? _selectedData;
|
||||
|
||||
private void ShowCreate()
|
||||
{
|
||||
_currentView = ViewMode.Create;
|
||||
}
|
||||
|
||||
private void ShowUpdate(UpdateBookingRequest 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,172 @@
|
||||
@using Indotalent.Features.Utilities.BookingManager
|
||||
@using Indotalent.Features.Utilities.BookingManager.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject BookingManagerService BookingManagerService
|
||||
@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 Booking</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Schedule a new resource booking.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Subject</MudText>
|
||||
<MudTextField @bind-Value="_model.Subject"
|
||||
For="@(() => _model.Subject)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Date</MudText>
|
||||
<MudDatePicker @bind-Date="_startDate"
|
||||
Validation="@(async (object value) => await _validator.ValidateValue()(_model, "StartTime"))"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Time</MudText>
|
||||
<MudTimePicker @bind-Time="_startTime"
|
||||
Validation="@(async (object value) => await _validator.ValidateValue()(_model, "StartTime"))"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Date</MudText>
|
||||
<MudDatePicker @bind-Date="_endDate"
|
||||
Validation="@(async (object value) => await _validator.ValidateValue()(_model, "EndTime"))"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Time</MudText>
|
||||
<MudTimePicker @bind-Time="_endTime"
|
||||
Validation="@(async (object value) => await _validator.ValidateValue()(_model, "EndTime"))"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Booking Resource</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.BookingResourceId"
|
||||
For="@(() => _model.BookingResourceId)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
|
||||
@foreach (var item in _lookupData.Resources)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.BookingStatus" @bind-Value="_model.Status"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
|
||||
@foreach (var item in _lookupData.Statuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.BookingStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" 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-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">
|
||||
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 Booking</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
|
||||
private MudForm _form = default!;
|
||||
private CreateBookingValidator _validator = new();
|
||||
private CreateBookingRequest _model = new() { Status = Indotalent.Data.Enums.BookingStatus.Draft };
|
||||
private LookupBookingDataResponse _lookupData = new();
|
||||
private bool _processing = false;
|
||||
|
||||
private DateTime? _startDate = DateTime.Today;
|
||||
private TimeSpan? _startTime = DateTime.Now.TimeOfDay;
|
||||
private DateTime? _endDate = DateTime.Today;
|
||||
private TimeSpan? _endTime = DateTime.Now.TimeOfDay.Add(TimeSpan.FromHours(1));
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var response = await BookingManagerService.GetLookupDataAsync();
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_lookupData = response.Value!;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (_startDate.HasValue && _startTime.HasValue)
|
||||
{
|
||||
_model.StartTime = _startDate.Value.Date.Add(_startTime.Value);
|
||||
}
|
||||
|
||||
if (_endDate.HasValue && _endTime.HasValue)
|
||||
{
|
||||
_model.EndTime = _endDate.Value.Date.Add(_endTime.Value);
|
||||
}
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await BookingManagerService.CreateBookingAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Booking created successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.BookingManager
|
||||
@using Indotalent.Features.Utilities.BookingManager.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject BookingManagerService BookingManagerService
|
||||
@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: 600; color: #111827;">Booking Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Manage schedules, resources, and booking status.</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;">Utilities</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Booking</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;">
|
||||
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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; 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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; 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 (_selectedBooking != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedBooking = 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;">
|
||||
Add New Booking
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Items="@GetPagedData()" Striped="true" Class="mud-table-styled" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetBookingListResponse" OnRowClick="@((args) => _selectedBooking = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #ffffff; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetBookingListResponse, object>(x => x.AutoNumber!)">No</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetBookingListResponse, object>(x => x.Subject!)">Subject</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Start Time</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Resource</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Status</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>
|
||||
<MudCheckBox T="bool" Value="@(_selectedBooking?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">@context.AutoNumber</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">
|
||||
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.Subject</MudText>
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">@DateTimeExtensions.ToString(context.StartTime)</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">@context.ResourceName</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Info" Variant="Variant.Text" Style="border-radius:4px; font-weight:700;">@context.Status</MudChip>
|
||||
</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" />
|
||||
</MudSelect>
|
||||
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF; margin-left: 12px; font-size: 0.75rem; font-weight: 500;">
|
||||
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;")" />
|
||||
<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: #374151; border: 1px solid #D1D5DB; border-radius: 6px; background: white;")">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: #374151; border: 1px solid #D1D5DB; border-radius: 6px; background: white;")">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;" : "background-color: white; border: 1px solid #D1D5DB; color: #6B7280;")" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
<style>
|
||||
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
||||
.mud-input-outlined-border { border-radius: 8px !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; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnAdd { get; set; }
|
||||
[Parameter] public EventCallback<UpdateBookingRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateBookingRequest> OnView { get; set; }
|
||||
|
||||
private List<GetBookingListResponse> _bookings = new();
|
||||
private GetBookingListResponse? _selectedBooking;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
|
||||
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;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedBooking = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var response = await BookingManagerService.GetBookingListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_bookings = response.Value ?? new List<GetBookingListResponse>();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRefreshing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GetBookingListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _bookings;
|
||||
return _bookings.Where(x =>
|
||||
(x.Subject?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.ResourceName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.Status?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
private IEnumerable<GetBookingListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private void OnSearchClick()
|
||||
{
|
||||
_skip = 0;
|
||||
_selectedBooking = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Enter") OnSearchClick();
|
||||
}
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("Bookings");
|
||||
var currentRow = 1;
|
||||
|
||||
worksheet.Cell(currentRow, 1).Value = "Auto Number";
|
||||
worksheet.Cell(currentRow, 2).Value = "Subject";
|
||||
worksheet.Cell(currentRow, 3).Value = "Start Time";
|
||||
worksheet.Cell(currentRow, 4).Value = "Resource";
|
||||
worksheet.Cell(currentRow, 5).Value = "Status";
|
||||
|
||||
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.AutoNumber;
|
||||
worksheet.Cell(currentRow, 2).Value = item.Subject;
|
||||
worksheet.Cell(currentRow, 3).Value = item.StartTime?.ToString("yyyy-MM-dd HH:mm");
|
||||
worksheet.Cell(currentRow, 4).Value = item.ResourceName;
|
||||
worksheet.Cell(currentRow, 5).Value = item.Status;
|
||||
}
|
||||
|
||||
worksheet.Columns().AdjustToContents();
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "Booking_List.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 OnPageChanged(int page)
|
||||
{
|
||||
if (page >= 1 && page <= _totalPage)
|
||||
{
|
||||
_skip = (page - 1) * _top;
|
||||
_selectedBooking = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageSizeChanged(int size)
|
||||
{
|
||||
_top = size;
|
||||
_skip = 0;
|
||||
_selectedBooking = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task InvokeEdit()
|
||||
{
|
||||
if (_selectedBooking == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedBooking.Id!);
|
||||
if (request != null) await OnEdit.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task InvokeView()
|
||||
{
|
||||
if (_selectedBooking == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedBooking.Id!);
|
||||
if (request != null) await OnView.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task<UpdateBookingRequest?> MapToUpdateRequest(string id)
|
||||
{
|
||||
var response = await BookingManagerService.GetBookingByIdAsync(id);
|
||||
if (response != null && response.IsSuccess && response.Value != null)
|
||||
{
|
||||
var detail = response.Value;
|
||||
return new UpdateBookingRequest
|
||||
{
|
||||
Id = detail.Id,
|
||||
Subject = detail.Subject,
|
||||
StartTime = detail.StartTime,
|
||||
EndTime = detail.EndTime,
|
||||
StartTimezone = detail.StartTimezone,
|
||||
EndTimezone = detail.EndTimezone,
|
||||
Location = detail.Location,
|
||||
Description = detail.Description,
|
||||
IsAllDay = detail.IsAllDay,
|
||||
IsReadOnly = detail.IsReadOnly,
|
||||
IsBlock = detail.IsBlock,
|
||||
RecurrenceRule = detail.RecurrenceRule,
|
||||
Status = detail.Status,
|
||||
BookingResourceId = detail.BookingResourceId,
|
||||
CreatedAt = detail.CreatedAt,
|
||||
CreatedBy = detail.CreatedBy,
|
||||
UpdatedAt = detail.UpdatedAt,
|
||||
UpdatedBy = detail.UpdatedBy
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedBooking == null) return;
|
||||
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedBooking.Subject } };
|
||||
var options = new DialogOptions { CloseButton = false, MaxWidth = MaxWidth.ExtraSmall, FullWidth = true };
|
||||
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, options);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
var isSuccess = await BookingManagerService.DeleteBookingByIdAsync(_selectedBooking.Id!);
|
||||
if (isSuccess)
|
||||
{
|
||||
_selectedBooking = null;
|
||||
await LoadData();
|
||||
Snackbar.Add("Booking deleted successfully", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Delete failed.", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.BookingManager
|
||||
@using Indotalent.Features.Utilities.BookingManager.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject BookingManagerService BookingManagerService
|
||||
@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 ? "Booking Details" : "Edit Booking")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing booking specification." : "Modify existing booking information.")</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
@if (_isDataLoading)
|
||||
{
|
||||
<div class="d-flex justify-center pa-10"><MudProgressCircular Color="Color.Primary" Indeterminate="true" /></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Subject</MudText>
|
||||
<MudTextField @bind-Value="_model.Subject"
|
||||
For="@(() => _model.Subject)"
|
||||
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">Start Date</MudText>
|
||||
<MudDatePicker @bind-Date="_startDate"
|
||||
ReadOnly="ReadOnly"
|
||||
Validation="@(async (object value) => await _validator.ValidateValue()(_model, "StartTime"))"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Time</MudText>
|
||||
<MudTimePicker @bind-Time="_startTime"
|
||||
ReadOnly="ReadOnly"
|
||||
Validation="@(async (object value) => await _validator.ValidateValue()(_model, "StartTime"))"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Date</MudText>
|
||||
<MudDatePicker @bind-Date="_endDate"
|
||||
ReadOnly="ReadOnly"
|
||||
Validation="@(async (object value) => await _validator.ValidateValue()(_model, "EndTime"))"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Time</MudText>
|
||||
<MudTimePicker @bind-Time="_endTime"
|
||||
ReadOnly="ReadOnly"
|
||||
Validation="@(async (object value) => await _validator.ValidateValue()(_model, "EndTime"))"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Booking Resource</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.BookingResourceId"
|
||||
For="@(() => _model.BookingResourceId)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
|
||||
@foreach (var item in _lookupData.Resources)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.BookingStatus" @bind-Value="_model.Status"
|
||||
For="@(() => _model.Status)"
|
||||
ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
|
||||
@foreach (var item in _lookupData.Statuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.BookingStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</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" Lines="3" 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-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">@(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 UpdateBookingRequest 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 UpdateBookingValidator _validator = new();
|
||||
private UpdateBookingRequest _model = new();
|
||||
private LookupBookingDataResponse _lookupData = new();
|
||||
private bool _processing = false;
|
||||
private bool _isDataLoading = true;
|
||||
|
||||
private DateTime? _startDate;
|
||||
private TimeSpan? _startTime;
|
||||
private DateTime? _endDate;
|
||||
private TimeSpan? _endTime;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_isDataLoading = true;
|
||||
try
|
||||
{
|
||||
var response = await BookingManagerService.GetLookupDataAsync();
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_lookupData = response.Value!;
|
||||
}
|
||||
|
||||
_model = new UpdateBookingRequest
|
||||
{
|
||||
Id = Data.Id,
|
||||
Subject = Data.Subject,
|
||||
StartTime = Data.StartTime,
|
||||
EndTime = Data.EndTime,
|
||||
StartTimezone = Data.StartTimezone,
|
||||
EndTimezone = Data.EndTimezone,
|
||||
Location = Data.Location,
|
||||
Description = Data.Description,
|
||||
IsAllDay = Data.IsAllDay,
|
||||
IsReadOnly = Data.IsReadOnly,
|
||||
IsBlock = Data.IsBlock,
|
||||
RecurrenceRule = Data.RecurrenceRule,
|
||||
Status = Data.Status,
|
||||
BookingResourceId = Data.BookingResourceId,
|
||||
CreatedAt = Data.CreatedAt,
|
||||
CreatedBy = Data.CreatedBy,
|
||||
UpdatedAt = Data.UpdatedAt,
|
||||
UpdatedBy = Data.UpdatedBy
|
||||
};
|
||||
|
||||
if (_model.StartTime.HasValue)
|
||||
{
|
||||
_startDate = _model.StartTime.Value.Date;
|
||||
_startTime = _model.StartTime.Value.TimeOfDay;
|
||||
}
|
||||
|
||||
if (_model.EndTime.HasValue)
|
||||
{
|
||||
_endDate = _model.EndTime.Value.Date;
|
||||
_endTime = _model.EndTime.Value.TimeOfDay;
|
||||
}
|
||||
}
|
||||
finally { _isDataLoading = false; }
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (ReadOnly) return;
|
||||
|
||||
if (_startDate.HasValue && _startTime.HasValue)
|
||||
{
|
||||
_model.StartTime = _startDate.Value.Date.Add(_startTime.Value);
|
||||
}
|
||||
|
||||
if (_endDate.HasValue && _endTime.HasValue)
|
||||
{
|
||||
_model.EndTime = _endDate.Value.Date.Add(_endTime.Value);
|
||||
}
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await BookingManagerService.UpdateBookingAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Booking updated successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingManager.Cqrs;
|
||||
|
||||
public class CreateBookingRequest
|
||||
{
|
||||
public string? Subject { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public string? StartTimezone { get; set; }
|
||||
public string? EndTimezone { get; set; }
|
||||
public string? Location { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public bool? IsAllDay { get; set; }
|
||||
public bool? IsReadOnly { get; set; }
|
||||
public bool? IsBlock { get; set; }
|
||||
public string? RecurrenceRule { get; set; }
|
||||
public BookingStatus Status { get; set; }
|
||||
public string? BookingResourceId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateBookingResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
}
|
||||
|
||||
public record CreateBookingCommand(CreateBookingRequest Data) : IRequest<CreateBookingResponse>;
|
||||
|
||||
public class CreateBookingHandler : IRequestHandler<CreateBookingCommand, CreateBookingResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateBookingHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateBookingResponse> Handle(CreateBookingCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.Booking);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.Booking
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
Subject = request.Data.Subject,
|
||||
StartTime = request.Data.StartTime,
|
||||
EndTime = request.Data.EndTime,
|
||||
StartTimezone = request.Data.StartTimezone,
|
||||
EndTimezone = request.Data.EndTimezone,
|
||||
Location = request.Data.Location,
|
||||
Description = request.Data.Description,
|
||||
IsAllDay = request.Data.IsAllDay,
|
||||
IsReadOnly = request.Data.IsReadOnly,
|
||||
IsBlock = request.Data.IsBlock,
|
||||
RecurrenceRule = request.Data.RecurrenceRule,
|
||||
Status = request.Data.Status,
|
||||
BookingResourceId = request.Data.BookingResourceId
|
||||
};
|
||||
|
||||
_context.Booking.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateBookingResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
AutoNumber = entity.AutoNumber
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingManager.Cqrs;
|
||||
|
||||
public class CreateBookingValidator : AbstractValidator<CreateBookingRequest>
|
||||
{
|
||||
public CreateBookingValidator()
|
||||
{
|
||||
RuleFor(x => x.Subject)
|
||||
.NotEmpty().WithMessage("Subject is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.StartTime)
|
||||
.NotEmpty().WithMessage("Start Time is required");
|
||||
|
||||
RuleFor(x => x.EndTime)
|
||||
.NotEmpty().WithMessage("End Time is required");
|
||||
|
||||
RuleFor(x => x.BookingResourceId)
|
||||
.NotEmpty().WithMessage("Resource is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingManager.Cqrs;
|
||||
|
||||
public class DeleteBookingByIdRequest
|
||||
{
|
||||
public DeleteBookingByIdRequest(string id) => Id = id;
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public record DeleteBookingByIdCommand(DeleteBookingByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteBookingByIdHandler : IRequestHandler<DeleteBookingByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteBookingByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteBookingByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Booking
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Booking.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingManager.Cqrs;
|
||||
|
||||
public class GetBookingByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Subject { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public string? StartTimezone { get; set; }
|
||||
public string? EndTimezone { get; set; }
|
||||
public string? Location { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public bool? IsAllDay { get; set; }
|
||||
public bool? IsReadOnly { get; set; }
|
||||
public bool? IsBlock { get; set; }
|
||||
public string? RecurrenceRule { get; set; }
|
||||
public string? RecurrenceID { get; set; }
|
||||
public string? FollowingID { get; set; }
|
||||
public string? RecurrenceException { get; set; }
|
||||
public BookingStatus Status { get; set; }
|
||||
public string? BookingResourceId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetBookingByIdQuery(string Id) : IRequest<GetBookingByIdResponse?>;
|
||||
|
||||
public class GetBookingByIdHandler : IRequestHandler<GetBookingByIdQuery, GetBookingByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetBookingByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetBookingByIdResponse?> Handle(GetBookingByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Booking
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetBookingByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Subject = x.Subject,
|
||||
StartTime = x.StartTime,
|
||||
EndTime = x.EndTime,
|
||||
StartTimezone = x.StartTimezone,
|
||||
EndTimezone = x.EndTimezone,
|
||||
Location = x.Location,
|
||||
Description = x.Description,
|
||||
IsAllDay = x.IsAllDay,
|
||||
IsReadOnly = x.IsReadOnly,
|
||||
IsBlock = x.IsBlock,
|
||||
RecurrenceRule = x.RecurrenceRule,
|
||||
RecurrenceID = x.RecurrenceID,
|
||||
FollowingID = x.FollowingID,
|
||||
RecurrenceException = x.RecurrenceException,
|
||||
Status = x.Status,
|
||||
BookingResourceId = x.BookingResourceId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingManager.Cqrs;
|
||||
|
||||
public class GetBookingListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Subject { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public string? ResourceName { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetBookingListQuery() : IRequest<List<GetBookingListResponse>>;
|
||||
|
||||
public class GetBookingListHandler : IRequestHandler<GetBookingListQuery, List<GetBookingListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetBookingListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetBookingListResponse>> Handle(GetBookingListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Booking
|
||||
.AsNoTracking()
|
||||
.Include(x => x.BookingResource)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetBookingListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Subject = x.Subject,
|
||||
StartTime = x.StartTime,
|
||||
EndTime = x.EndTime,
|
||||
Status = x.Status.GetDescription(),
|
||||
ResourceName = x.BookingResource != null ? x.BookingResource.Name : string.Empty,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingManager.Cqrs;
|
||||
|
||||
public class LookupBookingDataResponse
|
||||
{
|
||||
public List<LookupResourceItem> Resources { get; set; } = new();
|
||||
public List<LookupStatusItem> Statuses { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupResourceItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public class LookupStatusItem
|
||||
{
|
||||
public int Value { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record LookupBookingDataQuery() : IRequest<LookupBookingDataResponse>;
|
||||
|
||||
public class LookupBookingDataHandler : IRequestHandler<LookupBookingDataQuery, LookupBookingDataResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public LookupBookingDataHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LookupBookingDataResponse> Handle(LookupBookingDataQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var resources = await _context.BookingResource
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupResourceItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var statuses = Enum.GetValues(typeof(BookingStatus))
|
||||
.Cast<BookingStatus>()
|
||||
.Select(x => new LookupStatusItem
|
||||
{
|
||||
Value = (int)x,
|
||||
Name = x.GetDescription()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return new LookupBookingDataResponse
|
||||
{
|
||||
Resources = resources,
|
||||
Statuses = statuses
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingManager.Cqrs;
|
||||
|
||||
public class UpdateBookingRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Subject { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public string? StartTimezone { get; set; }
|
||||
public string? EndTimezone { get; set; }
|
||||
public string? Location { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public bool? IsAllDay { get; set; }
|
||||
public bool? IsReadOnly { get; set; }
|
||||
public bool? IsBlock { get; set; }
|
||||
public string? RecurrenceRule { get; set; }
|
||||
public BookingStatus Status { get; set; }
|
||||
public string? BookingResourceId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateBookingResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateBookingCommand(UpdateBookingRequest Data) : IRequest<UpdateBookingResponse>;
|
||||
|
||||
public class UpdateBookingHandler : IRequestHandler<UpdateBookingCommand, UpdateBookingResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateBookingHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateBookingResponse> Handle(UpdateBookingCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Booking
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateBookingResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Subject = request.Data.Subject;
|
||||
entity.StartTime = request.Data.StartTime;
|
||||
entity.EndTime = request.Data.EndTime;
|
||||
entity.StartTimezone = request.Data.StartTimezone;
|
||||
entity.EndTimezone = request.Data.EndTimezone;
|
||||
entity.Location = request.Data.Location;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.IsAllDay = request.Data.IsAllDay;
|
||||
entity.IsReadOnly = request.Data.IsReadOnly;
|
||||
entity.IsBlock = request.Data.IsBlock;
|
||||
entity.RecurrenceRule = request.Data.RecurrenceRule;
|
||||
entity.Status = request.Data.Status;
|
||||
entity.BookingResourceId = request.Data.BookingResourceId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateBookingResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingManager.Cqrs;
|
||||
|
||||
public class UpdateBookingValidator : AbstractValidator<UpdateBookingRequest>
|
||||
{
|
||||
public UpdateBookingValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
|
||||
RuleFor(x => x.Subject)
|
||||
.NotEmpty().WithMessage("Subject is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.StartTime)
|
||||
.NotEmpty().WithMessage("Start Time is required");
|
||||
|
||||
RuleFor(x => x.EndTime)
|
||||
.NotEmpty().WithMessage("End Time is required");
|
||||
|
||||
RuleFor(x => x.BookingResourceId)
|
||||
.NotEmpty().WithMessage("Resource is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource;
|
||||
|
||||
public class BookingResourceService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public BookingResourceService(
|
||||
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<GetBookingResourceListResponse>>?> GetBookingResourceListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/booking-resource", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetBookingResourceListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetBookingResourceByIdResponse>?> GetBookingResourceByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/booking-resource/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetBookingResourceByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<LookupBookingGroupResponse>?> GetBookingGroupLookupAsync()
|
||||
{
|
||||
var request = new RestRequest("api/booking-resource/lookup-booking-group", Method.Get);
|
||||
return await ExecuteWithResponseAsync<LookupBookingGroupResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateBookingResourceResponse>?> CreateBookingResourceAsync(CreateBookingResourceRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/booking-resource", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateBookingResourceResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteBookingResourceByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/booking-resource/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateBookingResourceResponse>?> UpdateBookingResourceAsync(UpdateBookingResourceRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/booking-resource/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateBookingResourceResponse>(_client, request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource;
|
||||
|
||||
public static class BookingResourceEndpoint
|
||||
{
|
||||
public static void MapBookingResourceEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/booking-resource").WithTags("BookingResources")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetBookingResourceListQuery());
|
||||
return result.ToApiResponse("Booking resource list retrieved successfully");
|
||||
})
|
||||
.WithName("GetBookingResourceList")
|
||||
.WithTags("BookingResources");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetBookingResourceByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Booking resource detail retrieved successfully"
|
||||
: $"Booking resource with ID {id} not found");
|
||||
})
|
||||
.WithName("GetBookingResourceById")
|
||||
.WithTags("BookingResources");
|
||||
|
||||
group.MapGet("/lookup-booking-group", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new LookupBookingGroupQuery());
|
||||
return result.ToApiResponse("Booking group lookup retrieved successfully");
|
||||
})
|
||||
.WithName("GetBookingGroupLookupForResource")
|
||||
.WithTags("BookingResources");
|
||||
|
||||
group.MapPost("/", async (CreateBookingResourceRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateBookingResourceCommand(request));
|
||||
return result.ToApiResponse("Booking resource has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateBookingResource")
|
||||
.WithTags("BookingResources");
|
||||
|
||||
group.MapPost("/update", async (UpdateBookingResourceRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateBookingResourceCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The booking resource data could not be found.");
|
||||
}
|
||||
return result.ToApiResponse("Booking resource has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateBookingResource")
|
||||
.WithTags("BookingResources");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteBookingResourceByIdCommand(new DeleteBookingResourceByIdRequest(id)));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The booking resource data could not be found.");
|
||||
}
|
||||
return true.ToApiResponse("Booking resource has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteBookingResourceById")
|
||||
.WithTags("BookingResources");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
@page "/utilities/booking-resource"
|
||||
@using Indotalent.Features.Utilities.BookingResource
|
||||
@using Indotalent.Features.Utilities.BookingResource.Cqrs
|
||||
@using Indotalent.Features.Utilities.BookingResource.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_BookingResourceCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_BookingResourceUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_BookingResourceDataTable 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 UpdateBookingResourceRequest? _selectedData;
|
||||
|
||||
private void ShowCreate()
|
||||
{
|
||||
_currentView = ViewMode.Create;
|
||||
}
|
||||
|
||||
private void ShowUpdate(UpdateBookingResourceRequest 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,108 @@
|
||||
@using Indotalent.Features.Utilities.BookingResource
|
||||
@using Indotalent.Features.Utilities.BookingResource.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject BookingResourceService BookingResourceService
|
||||
@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 Booking Resource</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Define a new bookable asset and its category.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Resource Name</MudText>
|
||||
<MudTextField @bind-Value="_model.Name"
|
||||
For="@(() => _model.Name)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. Meeting Room A" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Booking Group</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.BookingGroupId"
|
||||
For="@(() => _model.BookingGroupId)"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
|
||||
@foreach (var item in _lookupData.BookingGroups)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description"
|
||||
For="@(() => _model.Description)"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" 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-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">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 Resource</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
|
||||
private MudForm _form = default!;
|
||||
private CreateBookingResourceValidator _validator = new();
|
||||
private CreateBookingResourceRequest _model = new();
|
||||
private LookupBookingGroupResponse _lookupData = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var response = await BookingResourceService.GetBookingGroupLookupAsync();
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_lookupData = response.Value!;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await BookingResourceService.CreateBookingResourceAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Booking resource created successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.BookingResource
|
||||
@using Indotalent.Features.Utilities.BookingResource.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject BookingResourceService BookingResourceService
|
||||
@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: 600; color: #111827;">Booking Resource Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Manage rooms, equipment, or other bookable assets.</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;">Utilities</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Booking Resource</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;">
|
||||
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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; 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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; 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 (_selectedResource != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedResource = 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;">
|
||||
Add New Resource
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Items="@GetPagedData()" Striped="true" Class="mud-table-styled" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetBookingResourceListResponse" OnRowClick="@((args) => _selectedResource = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #ffffff; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetBookingResourceListResponse, object>(x => x.Name!)">Resource Name</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetBookingResourceListResponse, object>(x => x.BookingGroupName!)">Booking Group</MudTableSortLabel>
|
||||
</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>
|
||||
<MudCheckBox T="bool" Value="@(_selectedResource?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudAvatar Color="Color.Info" Variant="Variant.Filled" Size="Size.Small" Style="border-radius: 50%; font-size: 10px; font-weight: 800;">
|
||||
@(!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; color: #374151; font-size: 0.875rem;"><MudChip T="string" Size="Size.Small" Color="Color.Info" Variant="Variant.Text" Style="border-radius:4px; font-weight:700;">@context.BookingGroupName</MudChip></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" />
|
||||
</MudSelect>
|
||||
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF; margin-left: 12px; font-size: 0.75rem; font-weight: 500;">
|
||||
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;")" />
|
||||
<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: #374151; border: 1px solid #D1D5DB; border-radius: 6px; background: white;")">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: #374151; border: 1px solid #D1D5DB; border-radius: 6px; background: white;")">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;" : "background-color: white; border: 1px solid #D1D5DB; color: #6B7280;")" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
<style>
|
||||
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
||||
.mud-input-outlined-border { border-radius: 8px !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; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnAdd { get; set; }
|
||||
[Parameter] public EventCallback<UpdateBookingResourceRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateBookingResourceRequest> OnView { get; set; }
|
||||
|
||||
private List<GetBookingResourceListResponse> _resources = new();
|
||||
private GetBookingResourceListResponse? _selectedResource;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
|
||||
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;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedResource = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var response = await BookingResourceService.GetBookingResourceListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_resources = response.Value ?? new List<GetBookingResourceListResponse>();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRefreshing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GetBookingResourceListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _resources;
|
||||
return _resources.Where(x =>
|
||||
(x.Name?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.BookingGroupName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
private IEnumerable<GetBookingResourceListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private void OnSearchClick()
|
||||
{
|
||||
_skip = 0;
|
||||
_selectedResource = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Enter") OnSearchClick();
|
||||
}
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("BookingResources");
|
||||
var currentRow = 1;
|
||||
|
||||
worksheet.Cell(currentRow, 1).Value = "Resource Name";
|
||||
worksheet.Cell(currentRow, 2).Value = "Booking Group";
|
||||
|
||||
var headerRange = worksheet.Range(1, 1, 1, 2);
|
||||
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.Name;
|
||||
worksheet.Cell(currentRow, 2).Value = item.BookingGroupName;
|
||||
}
|
||||
|
||||
worksheet.Columns().AdjustToContents();
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "BookingResource_List.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 OnPageChanged(int page)
|
||||
{
|
||||
if (page >= 1 && page <= _totalPage)
|
||||
{
|
||||
_skip = (page - 1) * _top;
|
||||
_selectedResource = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageSizeChanged(int size)
|
||||
{
|
||||
_top = size;
|
||||
_skip = 0;
|
||||
_selectedResource = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task InvokeEdit()
|
||||
{
|
||||
if (_selectedResource == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedResource.Id!);
|
||||
if (request != null) await OnEdit.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task InvokeView()
|
||||
{
|
||||
if (_selectedResource == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedResource.Id!);
|
||||
if (request != null) await OnView.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task<UpdateBookingResourceRequest?> MapToUpdateRequest(string id)
|
||||
{
|
||||
var response = await BookingResourceService.GetBookingResourceByIdAsync(id);
|
||||
if (response != null && response.IsSuccess && response.Value != null)
|
||||
{
|
||||
var detail = response.Value;
|
||||
return new UpdateBookingResourceRequest
|
||||
{
|
||||
Id = detail.Id,
|
||||
Name = detail.Name,
|
||||
Description = detail.Description,
|
||||
BookingGroupId = detail.BookingGroupId,
|
||||
CreatedAt = detail.CreatedAt,
|
||||
CreatedBy = detail.CreatedBy,
|
||||
UpdatedAt = detail.UpdatedAt,
|
||||
UpdatedBy = detail.UpdatedBy
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedResource == null) return;
|
||||
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedResource.Name } };
|
||||
var options = new DialogOptions { CloseButton = false, MaxWidth = MaxWidth.ExtraSmall, FullWidth = true };
|
||||
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, options);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
var isSuccess = await BookingResourceService.DeleteBookingResourceByIdAsync(_selectedResource.Id!);
|
||||
if (isSuccess)
|
||||
{
|
||||
_selectedResource = null;
|
||||
await LoadData();
|
||||
Snackbar.Add("Booking resource deleted successfully", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Delete failed.", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.BookingResource
|
||||
@using Indotalent.Features.Utilities.BookingResource.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject BookingResourceService BookingResourceService
|
||||
@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 ? "Booking Resource Details" : "Edit Booking Resource")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing booking resource specification." : "Modify existing resource information.")</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
@if (_isDataLoading)
|
||||
{
|
||||
<div class="d-flex justify-center pa-10">
|
||||
<MudProgressCircular Color="Color.Primary" Indeterminate="true" />
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Resource 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">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Booking Group</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.BookingGroupId" For="@(() => _model.BookingGroupId)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Dense="true">
|
||||
@foreach (var item in _lookupData.BookingGroups)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" For="@(() => _model.Description)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" 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-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">@(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 UpdateBookingResourceRequest 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 UpdateBookingResourceValidator _validator = new();
|
||||
private UpdateBookingResourceRequest _model = new();
|
||||
private LookupBookingGroupResponse _lookupData = new();
|
||||
private bool _processing = false;
|
||||
private bool _isDataLoading = true;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_isDataLoading = true;
|
||||
try
|
||||
{
|
||||
var response = await BookingResourceService.GetBookingGroupLookupAsync();
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_lookupData = response.Value!;
|
||||
}
|
||||
|
||||
_model = new UpdateBookingResourceRequest
|
||||
{
|
||||
Id = Data.Id,
|
||||
Name = Data.Name,
|
||||
Description = Data.Description,
|
||||
BookingGroupId = Data.BookingGroupId,
|
||||
CreatedAt = Data.CreatedAt,
|
||||
CreatedBy = Data.CreatedBy,
|
||||
UpdatedAt = Data.UpdatedAt,
|
||||
UpdatedBy = Data.UpdatedBy
|
||||
};
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isDataLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (ReadOnly) return;
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await BookingResourceService.UpdateBookingResourceAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Booking resource updated successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
|
||||
public class CreateBookingResourceRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? BookingGroupId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateBookingResourceResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record CreateBookingResourceCommand(CreateBookingResourceRequest Data) : IRequest<CreateBookingResourceResponse>;
|
||||
|
||||
public class CreateBookingResourceHandler : IRequestHandler<CreateBookingResourceCommand, CreateBookingResourceResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateBookingResourceHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateBookingResourceResponse> Handle(CreateBookingResourceCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var isExists = await _context.BookingResource
|
||||
.AnyAsync(x => x.Name == request.Data.Name, cancellationToken);
|
||||
|
||||
if (isExists)
|
||||
{
|
||||
throw new AlreadyExistsException("Booking Resource", request.Data.Name ?? string.Empty);
|
||||
}
|
||||
|
||||
var entity = new Data.Entities.BookingResource
|
||||
{
|
||||
Name = request.Data.Name,
|
||||
Description = request.Data.Description,
|
||||
BookingGroupId = request.Data.BookingGroupId
|
||||
};
|
||||
|
||||
_context.BookingResource.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateBookingResourceResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
|
||||
public class CreateBookingResourceValidator : AbstractValidator<CreateBookingResourceRequest>
|
||||
{
|
||||
public CreateBookingResourceValidator()
|
||||
{
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.BookingGroupId)
|
||||
.NotEmpty().WithMessage("Booking Group is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
|
||||
public class DeleteBookingResourceByIdRequest
|
||||
{
|
||||
public DeleteBookingResourceByIdRequest(string id) => Id = id;
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public record DeleteBookingResourceByIdCommand(DeleteBookingResourceByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteBookingResourceByIdHandler : IRequestHandler<DeleteBookingResourceByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteBookingResourceByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteBookingResourceByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.BookingResource
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_context.BookingResource.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
|
||||
public class GetBookingResourceByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? BookingGroupId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetBookingResourceByIdQuery(string Id) : IRequest<GetBookingResourceByIdResponse?>;
|
||||
|
||||
public class GetBookingResourceByIdHandler : IRequestHandler<GetBookingResourceByIdQuery, GetBookingResourceByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetBookingResourceByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetBookingResourceByIdResponse?> Handle(GetBookingResourceByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.BookingResource
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetBookingResourceByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
Description = x.Description,
|
||||
BookingGroupId = x.BookingGroupId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
|
||||
public class GetBookingResourceListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? BookingGroupName { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetBookingResourceListQuery() : IRequest<List<GetBookingResourceListResponse>>;
|
||||
|
||||
public class GetBookingResourceListHandler : IRequestHandler<GetBookingResourceListQuery, List<GetBookingResourceListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetBookingResourceListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetBookingResourceListResponse>> Handle(GetBookingResourceListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.BookingResource
|
||||
.AsNoTracking()
|
||||
.Include(x => x.BookingGroup)
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new GetBookingResourceListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
BookingGroupName = x.BookingGroup != null ? x.BookingGroup.Name : string.Empty,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
|
||||
public class LookupBookingGroupResponse
|
||||
{
|
||||
public List<LookupBookingGroupItem> BookingGroups { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupBookingGroupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record LookupBookingGroupQuery() : IRequest<LookupBookingGroupResponse>;
|
||||
|
||||
public class LookupBookingGroupHandler : IRequestHandler<LookupBookingGroupQuery, LookupBookingGroupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public LookupBookingGroupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LookupBookingGroupResponse> Handle(LookupBookingGroupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var items = await _context.BookingGroup
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupBookingGroupItem
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return new LookupBookingGroupResponse { BookingGroups = items };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
|
||||
public class UpdateBookingResourceRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? BookingGroupId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateBookingResourceResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateBookingResourceCommand(UpdateBookingResourceRequest Data) : IRequest<UpdateBookingResourceResponse>;
|
||||
|
||||
public class UpdateBookingResourceHandler : IRequestHandler<UpdateBookingResourceCommand, UpdateBookingResourceResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateBookingResourceHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateBookingResourceResponse> Handle(UpdateBookingResourceCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var isExists = await _context.BookingResource
|
||||
.AnyAsync(x => x.Name == request.Data.Name && x.Id != request.Data.Id, cancellationToken);
|
||||
|
||||
if (isExists)
|
||||
{
|
||||
throw new AlreadyExistsException("Booking Resource", request.Data.Name ?? string.Empty);
|
||||
}
|
||||
|
||||
var entity = await _context.BookingResource
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateBookingResourceResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Name = request.Data.Name;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.BookingGroupId = request.Data.BookingGroupId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateBookingResourceResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
|
||||
public class UpdateBookingResourceValidator : AbstractValidator<UpdateBookingResourceRequest>
|
||||
{
|
||||
public UpdateBookingResourceValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required");
|
||||
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.BookingGroupId)
|
||||
.NotEmpty().WithMessage("Booking Group is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Utilities.BookingScheduler.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingScheduler;
|
||||
|
||||
public static class BookingSchedulerEndpoint
|
||||
{
|
||||
public static void MapBookingSchedulerEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/booking-scheduler").WithTags("BookingScheduler")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetBookingSchedulerListQuery());
|
||||
return result.ToApiResponse("Scheduler data retrieved successfully");
|
||||
})
|
||||
.WithName("GetBookingSchedulerList")
|
||||
.WithTags("BookingScheduler");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Utilities.BookingScheduler.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingScheduler;
|
||||
|
||||
public class BookingSchedulerService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public BookingSchedulerService(
|
||||
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<GetBookingSchedulerListResponse>>?> GetBookingSchedulerListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/booking-scheduler", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetBookingSchedulerListResponse>>(_client, request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
@page "/utilities/booking-scheduler"
|
||||
@using Indotalent.Features.Utilities.BookingScheduler
|
||||
@using Indotalent.Features.Utilities.BookingScheduler.Cqrs
|
||||
@using MudBlazor
|
||||
@inject BookingSchedulerService SchedulerService
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Booking Scheduler</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Visual schedule of resource allocations and time slots.</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: #94a3b8;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #94a3b8;">Utilities</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #94a3b8;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #1a1a1a;">Scheduler</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12" lg="4">
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-0 rounded-0" Style="border-color: #DCEBFA; background-color: #ffffff; overflow: hidden;">
|
||||
<div class="pa-4 d-flex align-center justify-space-between" style="background-color: #F8FAFC; border-bottom: 1px solid #DCEBFA;">
|
||||
<MudText Typo="Typo.subtitle2" Style="font-weight: 900; color: #1e293b; text-transform: uppercase;">Date Navigation</MudText>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Refresh" Size="Size.Small" OnClick="LoadData" Disabled="_loading" Color="Color.Primary" />
|
||||
</div>
|
||||
<div class="pa-2">
|
||||
<MudDatePicker PickerVariant="PickerVariant.Static"
|
||||
@bind-Date="_selectedDate"
|
||||
Color="Color.Primary"
|
||||
Rounded="false"
|
||||
Elevation="0" />
|
||||
</div>
|
||||
<MudDivider />
|
||||
<div class="pa-4">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-4" Style="font-weight: 900; color: #1e293b; text-transform: uppercase;">Summary for @(_selectedDate?.ToString("dd MMM yyyy") ?? "Today")</MudText>
|
||||
<div class="d-flex flex-column gap-3">
|
||||
<div class="d-flex justify-space-between align-center">
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Total Bookings</MudText>
|
||||
<MudText Typo="Typo.body2" Style="font-weight: 800; color: #0D47A1;">@GetFilteredData().Count()</MudText>
|
||||
</div>
|
||||
<div class="d-flex justify-space-between align-center">
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Active Resources</MudText>
|
||||
<MudText Typo="Typo.body2" Style="font-weight: 800; color: #0D47A1;">@GetFilteredData().Select(x => x.ResourceName).Distinct().Count()</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" lg="8">
|
||||
@if (_loading)
|
||||
{
|
||||
<div class="d-flex justify-center pa-20">
|
||||
<MudProgressCircular Color="Color.Primary" Indeterminate="true" Size="Size.Large" />
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-6 rounded-0" Style="border-color: #DCEBFA; background-color: #ffffff; min-height: 600px;">
|
||||
<div class="d-flex align-center gap-2 mb-8">
|
||||
<MudIcon Icon="@Icons.Material.Filled.CalendarToday" Color="Color.Primary" />
|
||||
<MudText Typo="Typo.h6" Style="font-weight: 900; color: #1a1a1a;">Timeline Details</MudText>
|
||||
</div>
|
||||
|
||||
@if (!GetFilteredData().Any())
|
||||
{
|
||||
<div class="d-flex flex-column align-center justify-center pa-10" style="border: 2px dashed #E2E8F0;">
|
||||
<MudIcon Icon="@Icons.Material.Filled.EventBusy" Size="Size.Large" Style="color: #cbd5e1;" />
|
||||
<MudText Typo="Typo.body1" Class="mt-2" Style="color: #94a3b8; font-weight: 600;">No bookings scheduled for this date.</MudText>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTimeline TimelinePosition="TimelinePosition.Start" Dense="true">
|
||||
@foreach (var item in GetFilteredData())
|
||||
{
|
||||
<MudTimelineItem Color="@GetStatusColor(item.Status)" Size="Size.Small" Elevation="0">
|
||||
<ItemOpposite>
|
||||
<div style="text-align: right; padding-right: 16px;">
|
||||
<MudText Typo="Typo.body2" Style="font-weight: 900; color: #1e293b; line-height: 1;">@item.StartTime?.ToString("HH:mm")</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #94a3b8; font-weight: 700;">@item.EndTime?.ToString("HH:mm")</MudText>
|
||||
</div>
|
||||
</ItemOpposite>
|
||||
<ItemContent>
|
||||
<MudPaper Elevation="0" Class="pa-4 mb-4 rounded-0" Style="@GetCardStyle(item.Status)">
|
||||
<div class="d-flex justify-space-between align-start">
|
||||
<div style="flex: 1;">
|
||||
<div class="d-flex align-center gap-2 mb-1">
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 900; color: #94a3b8; text-transform: uppercase;">@item.ResourceGroupName</MudText>
|
||||
</div>
|
||||
<MudText Typo="Typo.subtitle1" Style="font-weight: 900; color: #0D47A1; line-height: 1.2;">@item.Subject</MudText>
|
||||
<div class="d-flex align-center gap-2 mt-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Label" Size="Size.Small" Style="color: #64748b;" />
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 800; color: #475569;">@item.ResourceName</MudText>
|
||||
</div>
|
||||
</div>
|
||||
<div style="text-align: right;">
|
||||
<MudText Typo="Typo.caption" Style="@GetStatusTextStyle(item.Status)">@item.Status?.ToUpper()</MudText>
|
||||
<div class="mt-1">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Circle" Size="Size.Small" Color="@GetStatusColor(item.Status)" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(item.Description))
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="mt-3 pa-2" Style="color: #64748b; background-color: #F8FAFC; border-radius: 4px; font-style: italic;">@item.Description</MudText>
|
||||
}
|
||||
|
||||
<div class="d-flex align-center gap-4 mt-4 pt-3" style="border-top: 1px solid #F1F5F9;">
|
||||
<div class="d-flex align-center gap-1">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Timer" Size="Size.Small" Style="color: #94a3b8;" />
|
||||
<MudText Typo="Typo.caption" Style="color: #64748b; font-weight: 700;">@GetDuration(item.StartTime, item.EndTime)</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
</ItemContent>
|
||||
</MudTimelineItem>
|
||||
}
|
||||
</MudTimeline>
|
||||
}
|
||||
</MudPaper>
|
||||
}
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<style>
|
||||
.mud-timeline-item-opposite {
|
||||
flex: 0 0 100px !important;
|
||||
max-width: 100px !important;
|
||||
}
|
||||
.mud-picker-static {
|
||||
width: 100% !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
@code {
|
||||
private List<GetBookingSchedulerListResponse> _data = new();
|
||||
private bool _loading = true;
|
||||
private DateTime? _selectedDate = DateTime.Today;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_loading = true;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var response = await SchedulerService.GetBookingSchedulerListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_data = response.Value ?? new();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_loading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GetBookingSchedulerListResponse> GetFilteredData()
|
||||
{
|
||||
if (!_selectedDate.HasValue) return _data;
|
||||
return _data.Where(x => x.StartTime.HasValue && x.StartTime.Value.Date == _selectedDate.Value.Date);
|
||||
}
|
||||
|
||||
private Color GetStatusColor(string? status) => status switch
|
||||
{
|
||||
"Confirmed" => Color.Success,
|
||||
"Done" => Color.Primary,
|
||||
"OnProgress" => Color.Info,
|
||||
"Cancelled" => Color.Error,
|
||||
_ => Color.Default
|
||||
};
|
||||
|
||||
private string GetStatusHex(string? status) => status switch
|
||||
{
|
||||
"Confirmed" => "#2E7D32",
|
||||
"Done" => "#1565C0",
|
||||
"OnProgress" => "#0288D1",
|
||||
"Cancelled" => "#C62828",
|
||||
_ => "#64748B"
|
||||
};
|
||||
|
||||
private string GetStatusTextStyle(string? status)
|
||||
{
|
||||
var hex = GetStatusHex(status);
|
||||
return $"font-weight: 900; color: {hex};";
|
||||
}
|
||||
|
||||
private string GetCardStyle(string? status)
|
||||
{
|
||||
var hex = GetStatusHex(status);
|
||||
return $"border: 1px solid #E2E8F0; border-left: 6px solid {hex}; background: #ffffff; box-shadow: 0 2px 4px rgba(0,0,0,0.02);";
|
||||
}
|
||||
|
||||
private string GetDuration(DateTime? start, DateTime? end)
|
||||
{
|
||||
if (!start.HasValue || !end.HasValue) return "N/A";
|
||||
var diff = end.Value - start.Value;
|
||||
return $"{(int)diff.TotalHours}h {diff.Minutes}m";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingScheduler.Cqrs;
|
||||
|
||||
public class GetBookingSchedulerListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Subject { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public string? ResourceName { get; set; }
|
||||
public string? ResourceGroupName { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public record GetBookingSchedulerListQuery() : IRequest<List<GetBookingSchedulerListResponse>>;
|
||||
|
||||
public class GetBookingSchedulerListHandler : IRequestHandler<GetBookingSchedulerListQuery, List<GetBookingSchedulerListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetBookingSchedulerListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetBookingSchedulerListResponse>> Handle(GetBookingSchedulerListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Booking
|
||||
.AsNoTracking()
|
||||
.Include(x => x.BookingResource)
|
||||
.ThenInclude(x => x!.BookingGroup)
|
||||
.OrderBy(x => x.StartTime)
|
||||
.Select(x => new GetBookingSchedulerListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
Subject = x.Subject,
|
||||
StartTime = x.StartTime,
|
||||
EndTime = x.EndTime,
|
||||
Status = x.Status.GetDescription(),
|
||||
ResourceName = x.BookingResource != null ? x.BookingResource.Name : "Unassigned",
|
||||
ResourceGroupName = x.BookingResource != null && x.BookingResource.BookingGroup != null
|
||||
? x.BookingResource.BookingGroup.Name : "General",
|
||||
Description = x.Description
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
@page "/utilities/program-manager"
|
||||
@using Indotalent.Features.Utilities.ProgramManager.Cqrs
|
||||
@using Indotalent.Features.Utilities.ProgramManager.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_ProgramManagerCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_ProgramManagerUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_ProgramManagerDataTable 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 UpdateProgramManagerRequest? _selectedData;
|
||||
private void ShowCreate() => _currentView = ViewMode.Create;
|
||||
private void ShowUpdate(UpdateProgramManagerRequest 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,106 @@
|
||||
@using Indotalent.Features.Utilities.ProgramManager.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject ProgramManagerService ProgramManagerService
|
||||
@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 Program</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Initiate a new program management record.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Program Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title" For="@(() => _model.Title)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Priority</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.ProgramManagerPriority" @bind-Value="_model.Priority" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true">
|
||||
@foreach (var item in _lookup.Priorities)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.ProgramManagerPriority)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.ProgramManagerStatus" @bind-Value="_model.Status" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true">
|
||||
@foreach (var item in _lookup.Statuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.ProgramManagerStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Assign Resource</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.ProgramManagerResourceId" For="@(() => _model.ProgramManagerResourceId)" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true">
|
||||
@foreach (var item in _lookup.Resources)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Summary</MudText>
|
||||
<MudTextField @bind-Value="_model.Summary" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<div class="d-flex justify-end gap-2 mt-8">
|
||||
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Style="border-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">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 Size="Size.Small" Indeterminate="true" Class="ms-n1" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Create Program</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
private MudForm _form = default!;
|
||||
private CreateProgramManagerValidator _validator = new();
|
||||
private CreateProgramManagerRequest _model = new() { Status = Indotalent.Data.Enums.ProgramManagerStatus.Draft, Priority = Indotalent.Data.Enums.ProgramManagerPriority.Normal };
|
||||
private ProgramManagerLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await ProgramManagerService.GetLookupDataAsync();
|
||||
if (res != null && res.IsSuccess) { _lookup = res.Value!; }
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await ProgramManagerService.CreateProgramManagerAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess) { Snackbar.Add("Created successfully", Severity.Success); await OnSuccess.InvokeAsync(); }
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.ProgramManager
|
||||
@using Indotalent.Features.Utilities.ProgramManager.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject ProgramManagerService ProgramManagerService
|
||||
@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: 600; color: #111827;">Program Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Oversee and manage programs, resources, and priorities.</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;">Utilities</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">ProgramManager</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"
|
||||
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;">
|
||||
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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; color: #6B7280;">
|
||||
@if (_isExporting) { <MudProgressCircular Size="Size.Small" Indeterminate="true" /> } 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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; color: #6B7280;">
|
||||
@if (_isRefreshing) { <MudProgressCircular 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 (_selectedItem != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedItem = 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;">
|
||||
Add New Program
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Items="@GetPagedData()" Striped="true" Class="mud-table-styled" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetProgramManagerListResponse" OnRowClick="@((args) => _selectedItem = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #ffffff; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetProgramManagerListResponse, object>(x => x.AutoNumber!)">No</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetProgramManagerListResponse, object>(x => x.Title!)">Title</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetProgramManagerListResponse, object>(x => x.ResourceName!)">Resource</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetProgramManagerListResponse, object>(x => x.Priority!)">Priority</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetProgramManagerListResponse, object>(x => x.Status!)">Status</MudTableSortLabel>
|
||||
</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;"><MudCheckBox T="bool" Value="@(_selectedItem?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" /></MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">@context.AutoNumber</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;"><MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.Title</MudText></MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">@context.ResourceName</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">
|
||||
<MudChip T="string" Color="@GetPriorityColor(context.Priority)" Size="Size.Small" Variant="Variant.Text" Style="font-weight: 600;">@context.Priority?.ToUpper()</MudChip>
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">
|
||||
<MudChip T="string" Color="@GetStatusColor(context.Status)" Size="Size.Small" Variant="Variant.Filled" Style="font-weight: 600; ">@context.Status?.ToUpper()</MudChip>
|
||||
</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="color: #9CA3AF; margin-left: 12px; font-size: 0.75rem; font-weight: 500;">
|
||||
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;")" />
|
||||
<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: #374151; border: 1px solid #D1D5DB; border-radius: 6px; background: white;")">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: #374151; border: 1px solid #D1D5DB; border-radius: 6px; background: white;")">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;" : "background-color: white; border: 1px solid #D1D5DB; color: #6B7280;")" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<style>
|
||||
.mud-input-outlined-border { border-radius: 8px !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<UpdateProgramManagerRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateProgramManagerRequest> OnView { get; set; }
|
||||
|
||||
private List<GetProgramManagerListResponse> _items = new();
|
||||
private GetProgramManagerListResponse? _selectedItem;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
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;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedItem = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var response = await ProgramManagerService.GetProgramManagerListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess) { _items = response.Value ?? new(); }
|
||||
}
|
||||
finally { _isRefreshing = false; StateHasChanged(); }
|
||||
}
|
||||
|
||||
private IEnumerable<GetProgramManagerListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _items;
|
||||
return _items.Where(x =>
|
||||
(x.Title?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.ResourceName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
private IEnumerable<GetProgramManagerListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private Color GetPriorityColor(string? priority) => priority switch {
|
||||
"Critical" => Color.Error, "High" => Color.Warning, "Normal" => Color.Info, _ => Color.Default
|
||||
};
|
||||
|
||||
private Color GetStatusColor(string? status) => status switch {
|
||||
"Done" => Color.Success, "OnProgress" => Color.Info, "Confirmed" => Color.Primary, "Cancelled" => Color.Error, _ => Color.Default
|
||||
};
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("Programs");
|
||||
worksheet.Cell(1, 1).Value = "No"; worksheet.Cell(1, 2).Value = "Title";
|
||||
worksheet.Cell(1, 3).Value = "Resource"; worksheet.Cell(1, 4).Value = "Priority";
|
||||
worksheet.Cell(1, 5).Value = "Status";
|
||||
var row = 1;
|
||||
foreach (var item in GetFilteredData())
|
||||
{
|
||||
row++;
|
||||
worksheet.Cell(row, 1).Value = item.AutoNumber; worksheet.Cell(row, 2).Value = item.Title;
|
||||
worksheet.Cell(row, 3).Value = item.ResourceName; worksheet.Cell(row, 4).Value = item.Priority;
|
||||
worksheet.Cell(row, 5).Value = item.Status;
|
||||
}
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "Program_List.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { _isExporting = false; }
|
||||
}
|
||||
|
||||
private void OnSearchClick() { _skip = 0; _selectedItem = null; StateHasChanged(); }
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter") OnSearchClick(); }
|
||||
private void OnPageChanged(int page) { _skip = (page - 1) * _top; _selectedItem = null; }
|
||||
private void OnPageSizeChanged(int size) { _top = size; _skip = 0; }
|
||||
|
||||
private async Task InvokeEdit() { if (_selectedItem == null) return; var request = await MapToUpdateRequest(_selectedItem.Id!); if (request != null) await OnEdit.InvokeAsync(request); }
|
||||
private async Task InvokeView() { if (_selectedItem == null) return; var request = await MapToUpdateRequest(_selectedItem.Id!); if (request != null) await OnView.InvokeAsync(request); }
|
||||
|
||||
private async Task<UpdateProgramManagerRequest?> MapToUpdateRequest(string id)
|
||||
{
|
||||
var response = await ProgramManagerService.GetProgramManagerByIdAsync(id);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
var d = response.Value!;
|
||||
return new UpdateProgramManagerRequest { Id = d.Id, Title = d.Title, Summary = d.Summary, Status = d.Status, Priority = d.Priority, ProgramManagerResourceId = d.ProgramManagerResourceId, CreatedAt = d.CreatedAt, CreatedBy = d.CreatedBy, UpdatedAt = d.UpdatedAt, UpdatedBy = d.UpdatedBy };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedItem == null) return;
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedItem.Title } };
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, new DialogOptions { MaxWidth = MaxWidth.ExtraSmall, FullWidth = true });
|
||||
var result = await dialog.Result;
|
||||
if (result != null && !result.Canceled) { if (await ProgramManagerService.DeleteProgramManagerAsync(_selectedItem.Id!)) { await LoadData(); Snackbar.Add("Deleted successfully", Severity.Success); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
@using Indotalent.Features.Utilities.ProgramManager.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@inject ProgramManagerService ProgramManagerService
|
||||
@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 ? "Program Details" : "Edit Program")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing program details." : "Update program information and status.")</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
@if (_isDataLoading)
|
||||
{
|
||||
<div class="d-flex justify-center pa-10"><MudProgressCircular Color="Color.Primary" Indeterminate="true" /></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Program Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title" For="@(() => _model.Title)" 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">Priority</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.ProgramManagerPriority" @bind-Value="_model.Priority" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true">
|
||||
@foreach (var item in _lookup.Priorities)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.ProgramManagerPriority)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.ProgramManagerStatus" @bind-Value="_model.Status" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true">
|
||||
@foreach (var item in _lookup.Statuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.ProgramManagerStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Assigned Resource</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.ProgramManagerResourceId" For="@(() => _model.ProgramManagerResourceId)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true">
|
||||
@foreach (var item in _lookup.Resources)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Summary</MudText>
|
||||
<MudTextField @bind-Value="_model.Summary" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" 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" Style="border-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">@(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 Size="Size.Small" Indeterminate="true" Class="ms-n1" />
|
||||
<MudText Class="ms-2">Updating...</MudText>
|
||||
} else
|
||||
{
|
||||
<MudText>Save Changes</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</MudForm>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public UpdateProgramManagerRequest 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 UpdateProgramManagerValidator _validator = new();
|
||||
private UpdateProgramManagerRequest _model = new();
|
||||
private ProgramManagerLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
private bool _isDataLoading = true;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await ProgramManagerService.GetLookupDataAsync();
|
||||
if (res != null && res.IsSuccess) { _lookup = res.Value!; }
|
||||
_model = Data; _isDataLoading = false;
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await ProgramManagerService.UpdateProgramManagerAsync(_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,50 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class CreateProgramManagerRequest
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public ProgramManagerStatus Status { get; set; }
|
||||
public ProgramManagerPriority Priority { get; set; }
|
||||
public string? ProgramManagerResourceId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateProgramManagerResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
|
||||
public record CreateProgramManagerCommand(CreateProgramManagerRequest Data) : IRequest<CreateProgramManagerResponse>;
|
||||
|
||||
public class CreateProgramManagerHandler : IRequestHandler<CreateProgramManagerCommand, CreateProgramManagerResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateProgramManagerHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateProgramManagerResponse> Handle(CreateProgramManagerCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new Data.Entities.ProgramManager
|
||||
{
|
||||
Title = request.Data.Title,
|
||||
Summary = request.Data.Summary,
|
||||
Status = request.Data.Status,
|
||||
Priority = request.Data.Priority,
|
||||
ProgramManagerResourceId = request.Data.ProgramManagerResourceId
|
||||
};
|
||||
|
||||
_context.ProgramManager.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateProgramManagerResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Title = entity.Title
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class CreateProgramManagerValidator : AbstractValidator<CreateProgramManagerRequest>
|
||||
{
|
||||
public CreateProgramManagerValidator()
|
||||
{
|
||||
RuleFor(x => x.Title).NotEmpty().MaximumLength(GlobalConsts.StringLengthMedium);
|
||||
RuleFor(x => x.ProgramManagerResourceId).NotEmpty().WithMessage("Resource is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public record DeleteProgramManagerCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteProgramManagerHandler : IRequestHandler<DeleteProgramManagerCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteProgramManagerHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteProgramManagerCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.ProgramManager
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.ProgramManager.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class GetProgramManagerByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public ProgramManagerStatus Status { get; set; }
|
||||
public ProgramManagerPriority Priority { get; set; }
|
||||
public string? ProgramManagerResourceId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetProgramManagerByIdQuery(string Id) : IRequest<GetProgramManagerByIdResponse?>;
|
||||
|
||||
public class GetProgramManagerByIdHandler : IRequestHandler<GetProgramManagerByIdQuery, GetProgramManagerByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetProgramManagerByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetProgramManagerByIdResponse?> Handle(GetProgramManagerByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.ProgramManager
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetProgramManagerByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
Summary = x.Summary,
|
||||
Status = x.Status,
|
||||
Priority = x.Priority,
|
||||
ProgramManagerResourceId = x.ProgramManagerResourceId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class GetProgramManagerListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? ResourceName { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public string? Priority { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetProgramManagerListQuery() : IRequest<List<GetProgramManagerListResponse>>;
|
||||
|
||||
public class GetProgramManagerListHandler : IRequestHandler<GetProgramManagerListQuery, List<GetProgramManagerListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetProgramManagerListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetProgramManagerListResponse>> Handle(GetProgramManagerListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.ProgramManager
|
||||
.AsNoTracking()
|
||||
.Include(x => x.ProgramManagerResource)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetProgramManagerListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
ResourceName = x.ProgramManagerResource != null ? x.ProgramManagerResource.Name : string.Empty,
|
||||
Status = x.Status.GetDescription(),
|
||||
Priority = x.Priority.GetDescription(),
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Data.Enums;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class ProgramManagerLookupResponse
|
||||
{
|
||||
public List<LookupItem> Resources { get; set; } = new();
|
||||
public List<LookupItem> Statuses { get; set; } = new();
|
||||
public List<LookupItem> Priorities { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
|
||||
public record GetProgramManagerLookupQuery() : IRequest<ProgramManagerLookupResponse>;
|
||||
|
||||
public class GetProgramManagerLookupHandler : IRequestHandler<GetProgramManagerLookupQuery, ProgramManagerLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetProgramManagerLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<ProgramManagerLookupResponse> Handle(GetProgramManagerLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new ProgramManagerLookupResponse();
|
||||
|
||||
response.Resources = await _context.ProgramManagerResource
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Statuses = Enum.GetValues(typeof(ProgramManagerStatus))
|
||||
.Cast<ProgramManagerStatus>()
|
||||
.Select(e => new LookupItem { Value = (int)e, Name = e.GetDescription() })
|
||||
.ToList();
|
||||
|
||||
response.Priorities = Enum.GetValues(typeof(ProgramManagerPriority))
|
||||
.Cast<ProgramManagerPriority>()
|
||||
.Select(e => new LookupItem { Value = (int)e, Name = e.GetDescription() })
|
||||
.ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class UpdateProgramManagerRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public ProgramManagerStatus Status { get; set; }
|
||||
public ProgramManagerPriority Priority { get; set; }
|
||||
public string? ProgramManagerResourceId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateProgramManagerResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateProgramManagerCommand(UpdateProgramManagerRequest Data) : IRequest<UpdateProgramManagerResponse>;
|
||||
|
||||
public class UpdateProgramManagerHandler : IRequestHandler<UpdateProgramManagerCommand, UpdateProgramManagerResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateProgramManagerHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateProgramManagerResponse> Handle(UpdateProgramManagerCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.ProgramManager
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateProgramManagerResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Title = request.Data.Title;
|
||||
entity.Summary = request.Data.Summary;
|
||||
entity.Status = request.Data.Status;
|
||||
entity.Priority = request.Data.Priority;
|
||||
entity.ProgramManagerResourceId = request.Data.ProgramManagerResourceId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateProgramManagerResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class UpdateProgramManagerValidator : AbstractValidator<UpdateProgramManagerRequest>
|
||||
{
|
||||
public UpdateProgramManagerValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Title).NotEmpty().MaximumLength(GlobalConsts.StringLengthMedium);
|
||||
RuleFor(x => x.ProgramManagerResourceId).NotEmpty().WithMessage("Resource is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager;
|
||||
|
||||
public static class ProgramManagerEndpoint
|
||||
{
|
||||
public static void MapProgramManagerEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/program-manager").WithTags("ProgramManager")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/lookup", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetProgramManagerLookupQuery());
|
||||
return result.ToApiResponse("Lookup data retrieved successfully");
|
||||
})
|
||||
.WithName("GetProgramManagerLookup");
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetProgramManagerListQuery());
|
||||
return result.ToApiResponse("Program list retrieved successfully");
|
||||
})
|
||||
.WithName("GetProgramManagerList");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetProgramManagerByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Program detail retrieved successfully"
|
||||
: "Program not found");
|
||||
})
|
||||
.WithName("GetProgramManagerById");
|
||||
|
||||
group.MapPost("/", async (CreateProgramManagerRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateProgramManagerCommand(request));
|
||||
return result.ToApiResponse("Program created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateProgramManager");
|
||||
|
||||
group.MapPost("/update", async (UpdateProgramManagerRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateProgramManagerCommand(request));
|
||||
return result.ToApiResponse("Program updated successfully");
|
||||
})
|
||||
.WithName("UpdateProgramManager");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteProgramManagerCommand(id));
|
||||
return result.ToApiResponse("Program deleted successfully");
|
||||
})
|
||||
.WithName("DeleteProgramManager");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager;
|
||||
|
||||
public class ProgramManagerService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public ProgramManagerService(
|
||||
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<ProgramManagerLookupResponse>?> GetLookupDataAsync()
|
||||
{
|
||||
var request = new RestRequest("api/program-manager/lookup", Method.Get);
|
||||
return await ExecuteWithResponseAsync<ProgramManagerLookupResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<List<GetProgramManagerListResponse>>?> GetProgramManagerListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/program-manager", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetProgramManagerListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetProgramManagerByIdResponse>?> GetProgramManagerByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/program-manager/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetProgramManagerByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateProgramManagerResponse>?> CreateProgramManagerAsync(CreateProgramManagerRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/program-manager", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateProgramManagerResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateProgramManagerResponse>?> UpdateProgramManagerAsync(UpdateProgramManagerRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/program-manager/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateProgramManagerResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteProgramManagerAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/program-manager/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
@page "/utilities/program-resource"
|
||||
@using Indotalent.Features.Utilities.ProgramResource.Cqrs
|
||||
@using Indotalent.Features.Utilities.ProgramResource.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_ProgramResourceCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_ProgramResourceUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_ProgramResourceDataTable 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 UpdateProgramResourceRequest? _selectedData;
|
||||
|
||||
private void ShowCreate() => _currentView = ViewMode.Create;
|
||||
private void ShowUpdate(UpdateProgramResourceRequest 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,95 @@
|
||||
@using Indotalent.Features.Utilities.ProgramResource.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject ProgramResourceService ProgramResourceService
|
||||
@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 Resource</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Create a new master resource for program manager.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Resource Name</MudText>
|
||||
<MudTextField @bind-Value="_model.Name"
|
||||
For="@(() => _model.Name)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. Server Infrastructure" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" 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-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">
|
||||
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 Resource</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
|
||||
private MudForm _form = default!;
|
||||
private CreateProgramResourceValidator _validator = new();
|
||||
private CreateProgramResourceRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await ProgramResourceService.CreateProgramResourceAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Resource created successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.ProgramResource
|
||||
@using Indotalent.Features.Utilities.ProgramResource.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject ProgramResourceService ProgramResourceService
|
||||
@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: 600; color: #111827;">Program Resource</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Manage master resources for program management.</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;">Utilities</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">ProgramResource</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"
|
||||
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;">
|
||||
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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; 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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; 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 (_selectedItem != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedItem = 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;">
|
||||
Add New Resource
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Items="@GetPagedData()" Striped="true" Class="mud-table-styled" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetProgramResourceListResponse" OnRowClick="@((args) => _selectedItem = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #ffffff; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetProgramResourceListResponse, object>(x => x.Name!)">Resource Name</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Description</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>
|
||||
<MudCheckBox T="bool" Value="@(_selectedItem?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">
|
||||
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.Name</MudText>
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">@context.Description</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 rounded-0">
|
||||
<MudSelectItem Value="5" />
|
||||
<MudSelectItem Value="10" />
|
||||
<MudSelectItem Value="50" />
|
||||
<MudSelectItem Value="500" />
|
||||
<MudSelectItem Value="1000" />
|
||||
</MudSelect>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF; margin-left: 12px; font-size: 0.75rem; font-weight: 500;">
|
||||
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)" />
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small">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">Next</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
<style>
|
||||
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
||||
.mud-input-outlined-border { border-radius: 8px !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; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnAdd { get; set; }
|
||||
[Parameter] public EventCallback<UpdateProgramResourceRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateProgramResourceRequest> OnView { get; set; }
|
||||
|
||||
private List<GetProgramResourceListResponse> _items = new();
|
||||
private GetProgramResourceListResponse? _selectedItem;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
|
||||
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;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedItem = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var response = await ProgramResourceService.GetProgramResourceListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_items = response.Value ?? new();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRefreshing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GetProgramResourceListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _items;
|
||||
return _items.Where(x => (x.Name?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false));
|
||||
}
|
||||
|
||||
private IEnumerable<GetProgramResourceListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private void OnSearchClick() { _skip = 0; _selectedItem = null; StateHasChanged(); }
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter") OnSearchClick(); }
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
try
|
||||
{
|
||||
await Task.Delay(500);
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("Resources");
|
||||
worksheet.Cell(1, 1).Value = "Resource Name";
|
||||
worksheet.Cell(1, 2).Value = "Description";
|
||||
var currentRow = 1;
|
||||
foreach (var item in GetFilteredData())
|
||||
{
|
||||
currentRow++;
|
||||
worksheet.Cell(currentRow, 1).Value = item.Name;
|
||||
worksheet.Cell(currentRow, 2).Value = item.Description;
|
||||
}
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "ProgramResource_List.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
|
||||
Snackbar.Add("Exported successfully", Severity.Success);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { _isExporting = false; }
|
||||
}
|
||||
|
||||
private void OnPageChanged(int page) { _skip = (page - 1) * _top; _selectedItem = null; }
|
||||
private void OnPageSizeChanged(int size) { _top = size; _skip = 0; }
|
||||
|
||||
private async Task InvokeEdit()
|
||||
{
|
||||
if (_selectedItem == null) return;
|
||||
var response = await ProgramResourceService.GetProgramResourceByIdAsync(_selectedItem.Id!);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
await OnEdit.InvokeAsync(new UpdateProgramResourceRequest { Id = response.Value!.Id, Name = response.Value.Name, Description = response.Value.Description });
|
||||
}
|
||||
}
|
||||
|
||||
private async Task InvokeView()
|
||||
{
|
||||
if (_selectedItem == null) return;
|
||||
var response = await ProgramResourceService.GetProgramResourceByIdAsync(_selectedItem.Id!);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
await OnView.InvokeAsync(new UpdateProgramResourceRequest { Id = response.Value!.Id, Name = response.Value.Name, Description = response.Value.Description });
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedItem == null) return;
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedItem.Name } };
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, new DialogOptions { MaxWidth = MaxWidth.ExtraSmall, FullWidth = true });
|
||||
var result = await dialog.Result;
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
if (await ProgramResourceService.DeleteProgramResourceAsync(_selectedItem.Id!))
|
||||
{
|
||||
await LoadData();
|
||||
Snackbar.Add("Deleted successfully", Severity.Success);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
@using Indotalent.Features.Utilities.ProgramResource.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@inject ProgramResourceService ProgramResourceService
|
||||
@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 ? "Resource Details" : "Edit Resource")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing resource details." : "Modify existing resource information.")</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
@if (_isDataLoading)
|
||||
{
|
||||
<div class="d-flex justify-center pa-10"><MudProgressCircular Color="Color.Primary" Indeterminate="true" /></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Resource 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">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" 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(_auditData?.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(_auditData?.CreatedBy) ? _auditData?.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(_auditData?.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(_auditData?.UpdatedBy) ? _auditData?.UpdatedBy : "System")</MudText>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<div class="d-flex justify-end gap-2 mt-10">
|
||||
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Style="border-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">@(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 UpdateProgramResourceRequest 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 UpdateProgramResourceValidator _validator = new();
|
||||
private UpdateProgramResourceRequest _model = new();
|
||||
private GetProgramResourceByIdResponse? _auditData;
|
||||
private bool _processing = false;
|
||||
private bool _isDataLoading = true;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_isDataLoading = true;
|
||||
try
|
||||
{
|
||||
var response = await ProgramResourceService.GetProgramResourceByIdAsync(Data.Id!);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_auditData = response.Value;
|
||||
_model = new UpdateProgramResourceRequest
|
||||
{
|
||||
Id = _auditData!.Id,
|
||||
Name = _auditData.Name,
|
||||
Description = _auditData.Description
|
||||
};
|
||||
}
|
||||
}
|
||||
finally { _isDataLoading = false; }
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await ProgramResourceService.UpdateProgramResourceAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Resource updated successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramResource.Cqrs;
|
||||
|
||||
public class CreateProgramResourceRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public class CreateProgramResourceResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record CreateProgramResourceCommand(CreateProgramResourceRequest Data) : IRequest<CreateProgramResourceResponse>;
|
||||
|
||||
public class CreateProgramResourceHandler : IRequestHandler<CreateProgramResourceCommand, CreateProgramResourceResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateProgramResourceHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateProgramResourceResponse> Handle(CreateProgramResourceCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new Data.Entities.ProgramManagerResource
|
||||
{
|
||||
Name = request.Data.Name,
|
||||
Description = request.Data.Description
|
||||
};
|
||||
|
||||
_context.ProgramManagerResource.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateProgramResourceResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramResource.Cqrs;
|
||||
|
||||
public class CreateProgramResourceValidator : AbstractValidator<CreateProgramResourceRequest>
|
||||
{
|
||||
public CreateProgramResourceValidator()
|
||||
{
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramResource.Cqrs;
|
||||
|
||||
public record DeleteProgramResourceCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteProgramResourceHandler : IRequestHandler<DeleteProgramResourceCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteProgramResourceHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteProgramResourceCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.ProgramManagerResource
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_context.ProgramManagerResource.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramResource.Cqrs;
|
||||
|
||||
public class GetProgramResourceByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetProgramResourceByIdQuery(string Id) : IRequest<GetProgramResourceByIdResponse?>;
|
||||
|
||||
public class GetProgramResourceByIdHandler : IRequestHandler<GetProgramResourceByIdQuery, GetProgramResourceByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetProgramResourceByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetProgramResourceByIdResponse?> Handle(GetProgramResourceByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.ProgramManagerResource
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetProgramResourceByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
Description = x.Description,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramResource.Cqrs;
|
||||
|
||||
public class GetProgramResourceListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public record GetProgramResourceListQuery() : IRequest<List<GetProgramResourceListResponse>>;
|
||||
|
||||
public class GetProgramResourceListHandler : IRequestHandler<GetProgramResourceListQuery, List<GetProgramResourceListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetProgramResourceListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetProgramResourceListResponse>> Handle(GetProgramResourceListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.ProgramManagerResource
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new GetProgramResourceListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
Description = x.Description
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramResource.Cqrs;
|
||||
|
||||
public class UpdateProgramResourceRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateProgramResourceResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateProgramResourceCommand(UpdateProgramResourceRequest Data) : IRequest<UpdateProgramResourceResponse>;
|
||||
|
||||
public class UpdateProgramResourceHandler : IRequestHandler<UpdateProgramResourceCommand, UpdateProgramResourceResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateProgramResourceHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateProgramResourceResponse> Handle(UpdateProgramResourceCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.ProgramManagerResource
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateProgramResourceResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Name = request.Data.Name;
|
||||
entity.Description = request.Data.Description;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateProgramResourceResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramResource.Cqrs;
|
||||
|
||||
public class UpdateProgramResourceValidator : AbstractValidator<UpdateProgramResourceRequest>
|
||||
{
|
||||
public UpdateProgramResourceValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required");
|
||||
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Utilities.ProgramResource.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramResource;
|
||||
|
||||
public static class ProgramResourceEndpoint
|
||||
{
|
||||
public static void MapProgramResourceEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/program-resource").WithTags("ProgramResource")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetProgramResourceListQuery());
|
||||
return result.ToApiResponse("Resource list retrieved successfully");
|
||||
})
|
||||
.WithName("GetProgramResourceList");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetProgramResourceByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Resource detail retrieved successfully"
|
||||
: "Resource not found");
|
||||
})
|
||||
.WithName("GetProgramResourceById");
|
||||
|
||||
group.MapPost("/", async (CreateProgramResourceRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateProgramResourceCommand(request));
|
||||
return result.ToApiResponse("Resource created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateProgramResource");
|
||||
|
||||
group.MapPost("/update", async (UpdateProgramResourceRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateProgramResourceCommand(request));
|
||||
return result.ToApiResponse("Resource updated successfully");
|
||||
})
|
||||
.WithName("UpdateProgramResource");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteProgramResourceCommand(id));
|
||||
return result.ToApiResponse("Resource deleted successfully");
|
||||
})
|
||||
.WithName("DeleteProgramResource");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Utilities.ProgramResource.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramResource;
|
||||
|
||||
public class ProgramResourceService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public ProgramResourceService(
|
||||
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<GetProgramResourceListResponse>>?> GetProgramResourceListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/program-resource", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetProgramResourceListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetProgramResourceByIdResponse>?> GetProgramResourceByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/program-resource/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetProgramResourceByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateProgramResourceResponse>?> CreateProgramResourceAsync(CreateProgramResourceRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/program-resource", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateProgramResourceResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateProgramResourceResponse>?> UpdateProgramResourceAsync(UpdateProgramResourceRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/program-resource/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateProgramResourceResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteProgramResourceAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/program-resource/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
@page "/utilities/todo"
|
||||
@using Indotalent.Features.Utilities.Todo
|
||||
@using Indotalent.Features.Utilities.Todo.Cqrs
|
||||
@using Indotalent.Features.Utilities.Todo.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_TodoCreateForm OnCancel="BackToTable"
|
||||
OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_TodoUpdateForm Data="_selectedData!"
|
||||
ReadOnly="@(_currentView == ViewMode.View)"
|
||||
OnCancel="BackToTable"
|
||||
OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_TodoDataTable 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 UpdateTodoRequest? _selectedData;
|
||||
|
||||
private void ShowCreate()
|
||||
{
|
||||
_currentView = ViewMode.Create;
|
||||
}
|
||||
|
||||
private void ShowUpdate(UpdateTodoRequest 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,137 @@
|
||||
@using Indotalent.Features.Utilities.Todo
|
||||
@using Indotalent.Features.Utilities.Todo.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject TodoService TodoService
|
||||
@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 Todo</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Create a new master todo and its items.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Todo Name</MudText>
|
||||
<MudTextField @bind-Value="_model.Name"
|
||||
For="@(() => _model.Name)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Placeholder="e.g. Project Launch" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Date</MudText>
|
||||
<MudDatePicker @bind-Date="_startDate"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Time</MudText>
|
||||
<MudTimePicker @bind-Time="_startTime"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Date</MudText>
|
||||
<MudDatePicker @bind-Date="_endDate"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Time</MudText>
|
||||
<MudTimePicker @bind-Time="_endTime"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudCheckBox @bind-Value="_model.IsCompleted" Label="Completed" Color="Color.Primary" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description"
|
||||
For="@(() => _model.Description)"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" 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-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">
|
||||
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 Todo</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
|
||||
private MudForm _form = default!;
|
||||
private CreateTodoValidator _validator = new();
|
||||
private CreateTodoRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
private DateTime? _startDate = DateTime.Today;
|
||||
private TimeSpan? _startTime = DateTime.Now.TimeOfDay;
|
||||
private DateTime? _endDate = DateTime.Today;
|
||||
private TimeSpan? _endTime = DateTime.Now.TimeOfDay.Add(TimeSpan.FromHours(1));
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (_startDate.HasValue && _startTime.HasValue)
|
||||
_model.StartTime = _startDate.Value.Date.Add(_startTime.Value);
|
||||
|
||||
if (_endDate.HasValue && _endTime.HasValue)
|
||||
_model.EndTime = _endDate.Value.Date.Add(_endTime.Value);
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await TodoService.CreateTodoAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Todo created successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,404 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.Todo
|
||||
@using Indotalent.Features.Utilities.Todo.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject TodoService TodoService
|
||||
@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: 600; color: #111827;">Todo Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Manage your daily tasks and activities.</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;">Utilities</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Todo</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;">
|
||||
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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; 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="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB; 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 (_selectedTodo != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background-color: white; border: 1px solid #D1D5DB; color: #6B7280;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedTodo = 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;">
|
||||
Add New Todo
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Items="@GetPagedData()" Striped="true" Class="mud-table-styled" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetTodoListResponse" OnRowClick="@((args) => _selectedTodo = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #ffffff; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetTodoListResponse, object>(x => x.AutoNumber!)">No</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetTodoListResponse, object>(x => x.Name!)">Todo Name</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Start Time</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Status</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Description</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>
|
||||
<MudCheckBox T="bool" Value="@(_selectedTodo?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">@context.AutoNumber</MudTd>
|
||||
<MudTd>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudAvatar Color="Color.Info" Variant="Variant.Filled" Size="Size.Small" Style="border-radius: 50%; font-size: 10px; font-weight: 800;">
|
||||
@(!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; color: #374151; font-size: 0.875rem;">@DateTimeExtensions.ToString(context.StartTime)</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">
|
||||
@if (context.IsCompleted)
|
||||
{
|
||||
<MudChip T="string" Color="Color.Success" Size="Size.Small" Variant="Variant.Text" Style="font-weight: 600;">COMPLETED</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip T="string" Color="Color.Warning" Size="Size.Small" Variant="Variant.Text" Style="font-weight: 600;">PENDING</MudChip>
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #374151; font-size: 0.875rem;">@context.Description</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="color: #9CA3AF; margin-left: 12px; font-size: 0.75rem; font-weight: 500;">
|
||||
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;")" />
|
||||
<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: #374151; border: 1px solid #D1D5DB; border-radius: 6px; background: white;")">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: #374151; border: 1px solid #D1D5DB; border-radius: 6px; background: white;")">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;" : "background-color: white; border: 1px solid #D1D5DB; color: #6B7280;")" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
<style>
|
||||
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
||||
.mud-input-outlined-border { border-radius: 8px !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; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnAdd { get; set; }
|
||||
[Parameter] public EventCallback<UpdateTodoRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateTodoRequest> OnView { get; set; }
|
||||
|
||||
private List<GetTodoListResponse> _todos = new();
|
||||
private GetTodoListResponse? _selectedTodo;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
|
||||
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;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedTodo = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var response = await TodoService.GetTodoListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_todos = response.Value ?? new List<GetTodoListResponse>();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRefreshing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GetTodoListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _todos;
|
||||
return _todos.Where(x =>
|
||||
(x.Name?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.Description?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
private IEnumerable<GetTodoListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private void OnSearchClick()
|
||||
{
|
||||
_skip = 0;
|
||||
_selectedTodo = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Enter") OnSearchClick();
|
||||
}
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("Todos");
|
||||
var currentRow = 1;
|
||||
|
||||
worksheet.Cell(currentRow, 1).Value = "Auto Number";
|
||||
worksheet.Cell(currentRow, 2).Value = "Todo Name";
|
||||
worksheet.Cell(currentRow, 3).Value = "Start Time";
|
||||
worksheet.Cell(currentRow, 4).Value = "End Time";
|
||||
worksheet.Cell(currentRow, 5).Value = "Status";
|
||||
worksheet.Cell(currentRow, 6).Value = "Description";
|
||||
|
||||
var headerRange = worksheet.Range(1, 1, 1, 6);
|
||||
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.StartTime?.ToString("yyyy-MM-dd HH:mm");
|
||||
worksheet.Cell(currentRow, 4).Value = item.EndTime?.ToString("yyyy-MM-dd HH:mm");
|
||||
worksheet.Cell(currentRow, 5).Value = item.IsCompleted ? "Completed" : "Pending";
|
||||
worksheet.Cell(currentRow, 6).Value = item.Description;
|
||||
}
|
||||
|
||||
worksheet.Columns().AdjustToContents();
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "Todo_List.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 OnPageChanged(int page)
|
||||
{
|
||||
if (page >= 1 && page <= _totalPage)
|
||||
{
|
||||
_skip = (page - 1) * _top;
|
||||
_selectedTodo = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageSizeChanged(int size)
|
||||
{
|
||||
_top = size;
|
||||
_skip = 0;
|
||||
_selectedTodo = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task InvokeEdit()
|
||||
{
|
||||
if (_selectedTodo == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedTodo.Id!);
|
||||
if (request != null) await OnEdit.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task InvokeView()
|
||||
{
|
||||
if (_selectedTodo == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedTodo.Id!);
|
||||
if (request != null) await OnView.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task<UpdateTodoRequest?> MapToUpdateRequest(string id)
|
||||
{
|
||||
var response = await TodoService.GetTodoByIdAsync(id);
|
||||
if (response != null && response.IsSuccess && response.Value != null)
|
||||
{
|
||||
var detail = response.Value;
|
||||
return new UpdateTodoRequest
|
||||
{
|
||||
Id = detail.Id,
|
||||
Name = detail.Name,
|
||||
Description = detail.Description,
|
||||
StartTime = detail.StartTime,
|
||||
EndTime = detail.EndTime,
|
||||
IsCompleted = detail.IsCompleted,
|
||||
CreatedAt = detail.CreatedAt,
|
||||
CreatedBy = detail.CreatedBy,
|
||||
UpdatedAt = detail.UpdatedAt,
|
||||
UpdatedBy = detail.UpdatedBy
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedTodo == null) return;
|
||||
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedTodo.Name } };
|
||||
var options = new DialogOptions { CloseButton = false, MaxWidth = MaxWidth.ExtraSmall, FullWidth = true };
|
||||
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, options);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
var isSuccess = await TodoService.DeleteTodoByIdAsync(_selectedTodo.Id!);
|
||||
if (isSuccess)
|
||||
{
|
||||
_selectedTodo = null;
|
||||
await LoadData();
|
||||
Snackbar.Add("Todo deleted successfully", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Delete failed.", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
@using Indotalent.Features.Utilities.Todo.Cqrs
|
||||
@using MudBlazor
|
||||
@inject TodoService TodoService
|
||||
@inject ISnackbar Snackbar
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Item Name</MudText>
|
||||
<MudTextField @bind-Value="_model.Name" Required="true" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Date</MudText>
|
||||
<MudDatePicker @bind-Date="_startDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Time</MudText>
|
||||
<MudTimePicker @bind-Time="_startTime" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Date</MudText>
|
||||
<MudDatePicker @bind-Date="_endDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Time</MudText>
|
||||
<MudTimePicker @bind-Time="_endTime" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudCheckBox @bind-Value="_model.IsCompleted" Label="Completed" Color="Color.Primary" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudForm>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel" Variant="Variant.Text">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Submit" Variant="Variant.Filled" Disabled="_processing" Style="text-transform: none; font-weight: 700; border-radius: 4px;">
|
||||
@if (_processing)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Add Item</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
|
||||
[Parameter] public string TodoId { get; set; } = string.Empty;
|
||||
private MudForm _form = default!;
|
||||
private CreateTodoItemRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
private DateTime? _startDate = DateTime.Today;
|
||||
private TimeSpan? _startTime = DateTime.Now.TimeOfDay;
|
||||
private DateTime? _endDate = DateTime.Today;
|
||||
private TimeSpan? _endTime = DateTime.Now.TimeOfDay.Add(TimeSpan.FromHours(1));
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (_startDate.HasValue && _startTime.HasValue)
|
||||
_model.StartTime = _startDate.Value.Date.Add(_startTime.Value);
|
||||
|
||||
if (_endDate.HasValue && _endTime.HasValue)
|
||||
_model.EndTime = _endDate.Value.Date.Add(_endTime.Value);
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
_model.TodoId = TodoId;
|
||||
try
|
||||
{
|
||||
var response = await TodoService.CreateTodoItemAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Item added successfully", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.Todo
|
||||
@using Indotalent.Features.Utilities.Todo.Cqrs
|
||||
@using MudBlazor
|
||||
@using Indotalent.Features.Root.Shared
|
||||
@inject TodoService TodoService
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; 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;">
|
||||
<MudText Typo="Typo.button" Color="Color.Default" Style="font-weight: 600; color: #111827;">Todo Items</MudText>
|
||||
@if (!ReadOnly)
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="OnAddClick" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px;">
|
||||
Add Item
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
|
||||
<MudTable Items="Items" Striped="true" Class="mud-table-styled" Hover="true" Elevation="0" Dense="true" T="TodoItemResponse">
|
||||
<HeaderContent>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Name</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Start Time</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Status</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Description</MudTh>
|
||||
@if (!ReadOnly)
|
||||
{
|
||||
<MudTh Style="width: 100px; text-align: right; font-weight: 600; color: #6B7280;">Actions</MudTh>
|
||||
}
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Name">@context.Name</MudTd>
|
||||
<MudTd DataLabel="Start Time">@DateTimeExtensions.ToString(context.StartTime)</MudTd>
|
||||
<MudTd DataLabel="Status">
|
||||
@if (context.IsCompleted)
|
||||
{
|
||||
<MudChip T="string" Color="Color.Success" Size="Size.Small" Variant="Variant.Text">COMPLETED</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip T="string" Color="Color.Warning" Size="Size.Small" Variant="Variant.Text">PENDING</MudChip>
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Description">@context.Description</MudTd>
|
||||
@if (!ReadOnly)
|
||||
{
|
||||
<MudTd Style="text-align: right;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small" Color="Color.Primary" OnClick="@(() => OnEditClick(context))" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error" OnClick="@(() => OnDeleteClick(context))" />
|
||||
</MudTd>
|
||||
}
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
<style>
|
||||
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
||||
.mud-input-outlined-border { border-radius: 8px !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; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public string TodoId { get; set; } = string.Empty;
|
||||
[Parameter] public List<TodoItemResponse> Items { get; set; } = new();
|
||||
[Parameter] public bool ReadOnly { get; set; } = false;
|
||||
[Parameter] public EventCallback OnChanged { get; set; }
|
||||
|
||||
private async Task OnAddClick()
|
||||
{
|
||||
var parameters = new DialogParameters { ["TodoId"] = TodoId };
|
||||
var options = new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true, CloseButton = true };
|
||||
var dialog = await DialogService.ShowAsync<_TodoItemCreateForm>("Add Todo Item", parameters, options);
|
||||
var result = await dialog.Result;
|
||||
if (result != null && !result.Canceled) await OnChanged.InvokeAsync();
|
||||
}
|
||||
|
||||
private async Task OnEditClick(TodoItemResponse item)
|
||||
{
|
||||
var parameters = new DialogParameters { ["Data"] = item };
|
||||
var options = new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true, CloseButton = true };
|
||||
var dialog = await DialogService.ShowAsync<_TodoItemUpdateForm>("Edit Todo Item", parameters, options);
|
||||
var result = await dialog.Result;
|
||||
if (result != null && !result.Canceled) await OnChanged.InvokeAsync();
|
||||
}
|
||||
|
||||
private async Task OnDeleteClick(TodoItemResponse item)
|
||||
{
|
||||
var parameters = new DialogParameters { ["ContentText"] = $"Are you sure you want to remove {item.Name}?" };
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("Delete Confirmation", parameters, new DialogOptions { MaxWidth = MaxWidth.ExtraSmall, FullWidth = true });
|
||||
var result = await dialog.Result;
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
var success = await TodoService.DeleteTodoItemAsync(item.Id!);
|
||||
if (success)
|
||||
{
|
||||
Snackbar.Add("Item removed successfully", Severity.Success);
|
||||
await OnChanged.InvokeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
@using Indotalent.Features.Utilities.Todo.Cqrs
|
||||
@using MudBlazor
|
||||
@inject TodoService TodoService
|
||||
@inject ISnackbar Snackbar
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Item Name</MudText>
|
||||
<MudTextField @bind-Value="_model.Name" Required="true" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Date</MudText>
|
||||
<MudDatePicker @bind-Date="_startDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Time</MudText>
|
||||
<MudTimePicker @bind-Time="_startTime" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Date</MudText>
|
||||
<MudDatePicker @bind-Date="_endDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Time</MudText>
|
||||
<MudTimePicker @bind-Time="_endTime" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudCheckBox @bind-Value="_model.IsCompleted" Label="Completed" Color="Color.Primary" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudForm>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel" Variant="Variant.Text">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Submit" Variant="Variant.Filled" Disabled="_processing" Style="text-transform: none; font-weight: 700; border-radius: 4px;">
|
||||
@if (_processing)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2">Updating...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Save Changes</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
|
||||
[Parameter] public TodoItemResponse Data { get; set; } = new();
|
||||
private MudForm _form = default!;
|
||||
private UpdateTodoItemRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
private DateTime? _startDate;
|
||||
private TimeSpan? _startTime;
|
||||
private DateTime? _endDate;
|
||||
private TimeSpan? _endTime;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_model.Id = Data.Id;
|
||||
_model.Name = Data.Name;
|
||||
_model.Description = Data.Description;
|
||||
_model.IsCompleted = Data.IsCompleted;
|
||||
_model.StartTime = Data.StartTime;
|
||||
_model.EndTime = Data.EndTime;
|
||||
|
||||
_startDate = _model.StartTime?.Date;
|
||||
_startTime = _model.StartTime?.TimeOfDay;
|
||||
_endDate = _model.EndTime?.Date;
|
||||
_endTime = _model.EndTime?.TimeOfDay;
|
||||
}
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (_startDate.HasValue && _startTime.HasValue)
|
||||
_model.StartTime = _startDate.Value.Date.Add(_startTime.Value);
|
||||
|
||||
if (_endDate.HasValue && _endTime.HasValue)
|
||||
_model.EndTime = _endDate.Value.Date.Add(_endTime.Value);
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await TodoService.UpdateTodoItemAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.Value!.Success)
|
||||
{
|
||||
Snackbar.Add("Item updated successfully", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Utilities.Todo
|
||||
@using Indotalent.Features.Utilities.Todo.Cqrs
|
||||
@using Indotalent.Features.Utilities.Todo.Components
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject TodoService TodoService
|
||||
@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 ? "Todo Details" : "Edit Todo")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing todo specification." : "Modify existing todo information.")</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Todo 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">Start Date</MudText>
|
||||
<MudDatePicker @bind-Date="_startDate" ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Time</MudText>
|
||||
<MudTimePicker @bind-Time="_startTime" ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Date</MudText>
|
||||
<MudDatePicker @bind-Date="_endDate" ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Time</MudText>
|
||||
<MudTimePicker @bind-Time="_endTime" ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudCheckBox @bind-Value="_model.IsCompleted" Label="Completed" Color="Color.Primary" ReadOnly="ReadOnly" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description"
|
||||
For="@(() => _model.Description)"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" Class="mt-6">
|
||||
<_TodoItemDataTable Items="_items" TodoId="@(_model.Id ?? string.Empty)" ReadOnly="ReadOnly" OnChanged="RefreshItems" />
|
||||
</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-radius: 4px; text-transform: none; font-weight: 700;border: 1px solid #e0e0e0;">
|
||||
@(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 UpdateTodoRequest 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 UpdateTodoValidator _validator = new();
|
||||
private UpdateTodoRequest _model = new();
|
||||
private List<TodoItemResponse> _items = new();
|
||||
private bool _processing = false;
|
||||
|
||||
private DateTime? _startDate;
|
||||
private TimeSpan? _startTime;
|
||||
private DateTime? _endDate;
|
||||
private TimeSpan? _endTime;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_model = new UpdateTodoRequest
|
||||
{
|
||||
Id = Data.Id,
|
||||
Name = Data.Name,
|
||||
Description = Data.Description,
|
||||
StartTime = Data.StartTime,
|
||||
EndTime = Data.EndTime,
|
||||
IsCompleted = Data.IsCompleted,
|
||||
CreatedAt = Data.CreatedAt,
|
||||
CreatedBy = Data.CreatedBy,
|
||||
UpdatedAt = Data.UpdatedAt,
|
||||
UpdatedBy = Data.UpdatedBy
|
||||
};
|
||||
|
||||
_startDate = _model.StartTime?.Date;
|
||||
_startTime = _model.StartTime?.TimeOfDay;
|
||||
_endDate = _model.EndTime?.Date;
|
||||
_endTime = _model.EndTime?.TimeOfDay;
|
||||
|
||||
await RefreshItems();
|
||||
}
|
||||
|
||||
private async Task RefreshItems()
|
||||
{
|
||||
var response = await TodoService.GetTodoByIdAsync(_model.Id!);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_items = response.Value?.TodoItems ?? new();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (ReadOnly) return;
|
||||
|
||||
if (_startDate.HasValue && _startTime.HasValue)
|
||||
_model.StartTime = _startDate.Value.Date.Add(_startTime.Value);
|
||||
|
||||
if (_endDate.HasValue && _endTime.HasValue)
|
||||
_model.EndTime = _endDate.Value.Date.Add(_endTime.Value);
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await TodoService.UpdateTodoAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Todo updated successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
|
||||
public class CreateTodoRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public bool IsCompleted { get; set; }
|
||||
}
|
||||
|
||||
public class CreateTodoResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record CreateTodoCommand(CreateTodoRequest Data) : IRequest<CreateTodoResponse>;
|
||||
|
||||
public class CreateTodoHandler : IRequestHandler<CreateTodoCommand, CreateTodoResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateTodoHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateTodoResponse> Handle(CreateTodoCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.Booking);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.Todo
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
Name = request.Data.Name,
|
||||
Description = request.Data.Description,
|
||||
StartTime = request.Data.StartTime,
|
||||
EndTime = request.Data.EndTime,
|
||||
IsCompleted = request.Data.IsCompleted
|
||||
};
|
||||
|
||||
_context.Todo.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateTodoResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
|
||||
public class CreateTodoItemRequest
|
||||
{
|
||||
public string? TodoId { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public bool IsCompleted { get; set; }
|
||||
}
|
||||
|
||||
public class CreateTodoItemResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record CreateTodoItemCommand(CreateTodoItemRequest Data) : IRequest<CreateTodoItemResponse>;
|
||||
|
||||
public class CreateTodoItemHandler : IRequestHandler<CreateTodoItemCommand, CreateTodoItemResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateTodoItemHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateTodoItemResponse> Handle(CreateTodoItemCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new Data.Entities.TodoItem
|
||||
{
|
||||
TodoId = request.Data.TodoId,
|
||||
Name = request.Data.Name,
|
||||
Description = request.Data.Description,
|
||||
StartTime = request.Data.StartTime,
|
||||
EndTime = request.Data.EndTime,
|
||||
IsCompleted = request.Data.IsCompleted
|
||||
};
|
||||
|
||||
_context.TodoItem.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateTodoItemResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
|
||||
public class CreateTodoValidator : AbstractValidator<CreateTodoRequest>
|
||||
{
|
||||
public CreateTodoValidator()
|
||||
{
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
|
||||
public class DeleteTodoByIdRequest
|
||||
{
|
||||
public DeleteTodoByIdRequest(string id) => Id = id;
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public record DeleteTodoByIdCommand(DeleteTodoByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteTodoByIdHandler : IRequestHandler<DeleteTodoByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteTodoByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteTodoByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Todo
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_context.Todo.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
|
||||
public record DeleteTodoItemCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteTodoItemHandler : IRequestHandler<DeleteTodoItemCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteTodoItemHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteTodoItemCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.TodoItem
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_context.TodoItem.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
|
||||
public class TodoItemResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public bool IsCompleted { get; set; }
|
||||
}
|
||||
|
||||
public class GetTodoByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public bool IsCompleted { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
public List<TodoItemResponse> TodoItems { get; set; } = new List<TodoItemResponse>();
|
||||
}
|
||||
|
||||
public record GetTodoByIdQuery(string Id) : IRequest<GetTodoByIdResponse?>;
|
||||
|
||||
public class GetTodoByIdHandler : IRequestHandler<GetTodoByIdQuery, GetTodoByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetTodoByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetTodoByIdResponse?> Handle(GetTodoByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Todo
|
||||
.AsNoTracking()
|
||||
.Include(x => x.TodoItemList)
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetTodoByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Name = x.Name,
|
||||
Description = x.Description,
|
||||
StartTime = x.StartTime,
|
||||
EndTime = x.EndTime,
|
||||
IsCompleted = x.IsCompleted,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy,
|
||||
TodoItems = x.TodoItemList
|
||||
.OrderBy(i => i.StartTime)
|
||||
.Select(i => new TodoItemResponse
|
||||
{
|
||||
Id = i.Id,
|
||||
Name = i.Name,
|
||||
Description = i.Description,
|
||||
StartTime = i.StartTime,
|
||||
EndTime = i.EndTime,
|
||||
IsCompleted = i.IsCompleted
|
||||
}).ToList()
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
|
||||
public class GetTodoListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public bool IsCompleted { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetTodoListQuery() : IRequest<List<GetTodoListResponse>>;
|
||||
|
||||
public class GetTodoListHandler : IRequestHandler<GetTodoListQuery, List<GetTodoListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetTodoListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetTodoListResponse>> Handle(GetTodoListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Todo
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetTodoListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Name = x.Name,
|
||||
Description = x.Description,
|
||||
StartTime = x.StartTime,
|
||||
EndTime = x.EndTime,
|
||||
IsCompleted = x.IsCompleted,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy,
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
|
||||
public class UpdateTodoRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public bool IsCompleted { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateTodoResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateTodoCommand(UpdateTodoRequest Data) : IRequest<UpdateTodoResponse>;
|
||||
|
||||
public class UpdateTodoHandler : IRequestHandler<UpdateTodoCommand, UpdateTodoResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateTodoHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateTodoResponse> Handle(UpdateTodoCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Todo
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateTodoResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Name = request.Data.Name;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.StartTime = request.Data.StartTime;
|
||||
entity.EndTime = request.Data.EndTime;
|
||||
entity.IsCompleted = request.Data.IsCompleted;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateTodoResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
|
||||
public class UpdateTodoItemRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public bool IsCompleted { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateTodoItemResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateTodoItemCommand(UpdateTodoItemRequest Data) : IRequest<UpdateTodoItemResponse>;
|
||||
|
||||
public class UpdateTodoItemHandler : IRequestHandler<UpdateTodoItemCommand, UpdateTodoItemResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateTodoItemHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateTodoItemResponse> Handle(UpdateTodoItemCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.TodoItem
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateTodoItemResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Name = request.Data.Name;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.StartTime = request.Data.StartTime;
|
||||
entity.EndTime = request.Data.EndTime;
|
||||
entity.IsCompleted = request.Data.IsCompleted;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateTodoItemResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
|
||||
public class UpdateTodoValidator : AbstractValidator<UpdateTodoRequest>
|
||||
{
|
||||
public UpdateTodoValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required");
|
||||
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo;
|
||||
|
||||
public static class TodoEndpoint
|
||||
{
|
||||
public static void MapTodoEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/todo").WithTags("Todos")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetTodoListQuery());
|
||||
return result.ToApiResponse("Todo list retrieved successfully");
|
||||
})
|
||||
.WithName("GetTodoList")
|
||||
.WithTags("Todos");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetTodoByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Todo detail retrieved successfully"
|
||||
: $"Todo with ID {id} not found");
|
||||
})
|
||||
.WithName("GetTodoById")
|
||||
.WithTags("Todos");
|
||||
|
||||
group.MapPost("/", async (CreateTodoRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateTodoCommand(request));
|
||||
return result.ToApiResponse("Todo has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateTodo")
|
||||
.WithTags("Todos");
|
||||
|
||||
group.MapPost("/update", async (UpdateTodoRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateTodoCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The todo data could not be found.");
|
||||
}
|
||||
return result.ToApiResponse("Todo has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateTodo")
|
||||
.WithTags("Todos");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteTodoByIdCommand(new DeleteTodoByIdRequest(id)));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The todo data could not be found.");
|
||||
}
|
||||
return true.ToApiResponse("Todo has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteTodoById")
|
||||
.WithTags("Todos");
|
||||
|
||||
group.MapPost("/todo-item", async (CreateTodoItemRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateTodoItemCommand(request));
|
||||
return result.ToApiResponse("Todo item has been added successfully");
|
||||
})
|
||||
.WithName("CreateTodoItemChild")
|
||||
.WithTags("Todos");
|
||||
|
||||
group.MapPost("/todo-item/update", async (UpdateTodoItemRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateTodoItemCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. Todo item not found.");
|
||||
}
|
||||
return result.ToApiResponse("Todo item has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateTodoItemChild")
|
||||
.WithTags("Todos");
|
||||
|
||||
group.MapPost("/todo-item/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteTodoItemCommand(id));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. Todo item not found.");
|
||||
}
|
||||
return true.ToApiResponse("Todo item has been removed successfully");
|
||||
})
|
||||
.WithName("DeleteTodoItemChild")
|
||||
.WithTags("Todos");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Utilities.Todo.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Utilities.Todo;
|
||||
|
||||
public class TodoService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public TodoService(
|
||||
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<GetTodoListResponse>>?> GetTodoListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/todo", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetTodoListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetTodoByIdResponse>?> GetTodoByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/todo/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetTodoByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateTodoResponse>?> CreateTodoAsync(CreateTodoRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/todo", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateTodoResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteTodoByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/todo/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateTodoResponse>?> UpdateTodoAsync(UpdateTodoRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/todo/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateTodoResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateTodoItemResponse>?> CreateTodoItemAsync(CreateTodoItemRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/todo/todo-item", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateTodoItemResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateTodoItemResponse>?> UpdateTodoItemAsync(UpdateTodoItemRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/todo/todo-item/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateTodoItemResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteTodoItemAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/todo/todo-item/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
@page "/utilities"
|
||||
@using Indotalent.Features.Utilities.BookingGroup.Components
|
||||
@using Indotalent.Features.Utilities.BookingManager.Components
|
||||
@using Indotalent.Features.Utilities.BookingResource.Components
|
||||
@using Indotalent.Features.Utilities.BookingScheduler.Components
|
||||
@using Indotalent.Features.Utilities.ProgramManager.Components
|
||||
@using Indotalent.Features.Utilities.ProgramResource.Components
|
||||
@using Indotalent.Features.Utilities.Todo.Components
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Indotalent.Infrastructure.Authorization.Identity
|
||||
@using MudBlazor
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
|
||||
@attribute [Authorize(Roles = $"{ApplicationRoles.Admin},{ApplicationRoles.Member}")]
|
||||
|
||||
<style>
|
||||
.clean-white-tabs .mud-tabs-toolbar {
|
||||
background-color: white !important;
|
||||
border-bottom: 2px solid #DCEBFA;
|
||||
border-radius: 4px !important;
|
||||
}
|
||||
|
||||
.clean-white-tabs .mud-tab {
|
||||
color: #94a3b8 !important;
|
||||
text-transform: none;
|
||||
font-weight: 500;
|
||||
min-width: 160px;
|
||||
border-radius: 4px !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"
|
||||
ScrollButtons="ScrollButtons.Always">
|
||||
|
||||
<MudTabPanel Text="Booking Group" Icon="@Icons.Material.Outlined.Workspaces">
|
||||
<BookingGroupPage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Booking Resource" Icon="@Icons.Material.Outlined.Construction">
|
||||
<BookingResourcePage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Booking Manager" Icon="@Icons.Material.Outlined.SettingsSuggest">
|
||||
<BookingManagerPage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Scheduler" Icon="@Icons.Material.Outlined.CalendarMonth">
|
||||
<BookingSchedulerPage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Prog Resource" Icon="@Icons.Material.Outlined.Source">
|
||||
<ProgramResourcePage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Prog Manager" Icon="@Icons.Material.Outlined.AccountTree">
|
||||
<ProgramManagerPage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="To-Do List" Icon="@Icons.Material.Outlined.PlaylistAddCheck">
|
||||
<TodoPage />
|
||||
</MudTabPanel>
|
||||
|
||||
</MudTabs>
|
||||
</div>
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
private int _activeTabIndex = 0;
|
||||
|
||||
private readonly Dictionary<int, string> _tabMapping = new()
|
||||
{
|
||||
{ 0, "booking-group" },
|
||||
{ 1, "booking-resource" },
|
||||
{ 2, "booking-manager" },
|
||||
{ 3, "scheduler" },
|
||||
{ 4, "prog-resource" },
|
||||
{ 5, "prog-manager" },
|
||||
{ 6, "todo" }
|
||||
};
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var uri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
|
||||
if (Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query).TryGetValue("tab", out var tabValue))
|
||||
{
|
||||
var tabStr = tabValue.ToString().ToLower();
|
||||
var match = _tabMapping.FirstOrDefault(x => x.Value == tabStr);
|
||||
_activeTabIndex = match.Value != null ? match.Key : 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTabChanged(int index)
|
||||
{
|
||||
_activeTabIndex = index;
|
||||
_tabMapping.TryGetValue(index, out var tabName);
|
||||
|
||||
NavigationManager.NavigateTo($"/utilities?tab={tabName ?? "booking-group"}", replace: false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user