initial commit

This commit is contained in:
2026-07-21 14:35:37 +07:00
commit 0027997ff9
798 changed files with 59083 additions and 0 deletions
@@ -0,0 +1,103 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class CreateEmployeeRequest
{
public string? Name { get; set; }
public string? Description { get; set; }
public string? Street { get; set; }
public string? City { get; set; }
public string? State { get; set; }
public string? ZipCode { get; set; }
public string? Country { get; set; }
public string? PhoneNumber { get; set; }
public string? FaxNumber { get; set; }
public string? EmailAddress { get; set; }
public string? Website { get; set; }
public string? WhatsApp { get; set; }
public string? LinkedIn { get; set; }
public string? Facebook { get; set; }
public string? Instagram { get; set; }
public string? TwitterX { get; set; }
public string? TikTok { get; set; }
public string? EmployeeGroupId { get; set; }
public string? EmployeeCategoryId { get; set; }
public string? JobTitle { get; set; }
public decimal CommissionRate { get; set; }
public string? EmployeeNumber { get; set; }
}
public class CreateEmployeeResponse
{
public string? Id { get; set; }
public string? Name { get; set; }
}
public record CreateEmployeeCommand(CreateEmployeeRequest Data) : IRequest<CreateEmployeeResponse>;
public class CreateEmployeeHandler : IRequestHandler<CreateEmployeeCommand, CreateEmployeeResponse>
{
private readonly AppDbContext _context;
public CreateEmployeeHandler(AppDbContext context) => _context = context;
public async Task<CreateEmployeeResponse> Handle(CreateEmployeeCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.Employee
.AnyAsync(x => x.Name == request.Data.Name, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Employee", request.Data.Name ?? string.Empty);
}
var entityName = nameof(Data.Entities.Employee);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.Employee
{
AutoNumber = autoNo,
Name = request.Data.Name,
Description = request.Data.Description,
Street = request.Data.Street,
City = request.Data.City,
State = request.Data.State,
ZipCode = request.Data.ZipCode,
Country = request.Data.Country,
PhoneNumber = request.Data.PhoneNumber,
FaxNumber = request.Data.FaxNumber,
EmailAddress = request.Data.EmailAddress,
Website = request.Data.Website,
WhatsApp = request.Data.WhatsApp,
LinkedIn = request.Data.LinkedIn,
Facebook = request.Data.Facebook,
Instagram = request.Data.Instagram,
TwitterX = request.Data.TwitterX,
TikTok = request.Data.TikTok,
EmployeeGroupId = request.Data.EmployeeGroupId,
EmployeeCategoryId = request.Data.EmployeeCategoryId,
JobTitle = request.Data.JobTitle,
CommissionRate = request.Data.CommissionRate,
EmployeeNumber = request.Data.EmployeeNumber
};
_context.Employee.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateEmployeeResponse
{
Id = entity.Id,
Name = entity.Name
};
}
}
@@ -0,0 +1,34 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class CreateEmployeeValidator : AbstractValidator<CreateEmployeeRequest>
{
public CreateEmployeeValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Employee Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.EmployeeNumber)
.NotEmpty().WithMessage("Employee Number is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.JobTitle)
.NotEmpty().WithMessage("Job Title is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.CommissionRate)
.GreaterThanOrEqualTo(0).WithMessage("Commission Rate cannot be negative");
RuleFor(x => x.EmailAddress)
.EmailAddress().When(x => !string.IsNullOrEmpty(x.EmailAddress));
RuleFor(x => x.EmployeeGroupId)
.NotEmpty().WithMessage("Employee Group is required");
RuleFor(x => x.EmployeeCategoryId)
.NotEmpty().WithMessage("Employee Category is required");
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public record DeleteEmployeeByIdRequest(string Id);
public record DeleteEmployeeByIdCommand(DeleteEmployeeByIdRequest Data) : IRequest<bool>;
public class DeleteEmployeeByIdHandler : IRequestHandler<DeleteEmployeeByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteEmployeeByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteEmployeeByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Employee
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.Employee.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,85 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class GetEmployeeByIdResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? Street { get; set; }
public string? City { get; set; }
public string? State { get; set; }
public string? ZipCode { get; set; }
public string? Country { get; set; }
public string? PhoneNumber { get; set; }
public string? FaxNumber { get; set; }
public string? EmailAddress { get; set; }
public string? Website { get; set; }
public string? WhatsApp { get; set; }
public string? LinkedIn { get; set; }
public string? Facebook { get; set; }
public string? Instagram { get; set; }
public string? TwitterX { get; set; }
public string? TikTok { get; set; }
public string? EmployeeGroupId { get; set; }
public string? EmployeeCategoryId { get; set; }
public string? JobTitle { get; set; }
public decimal CommissionRate { get; set; }
public string? EmployeeNumber { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetEmployeeByIdQuery(string Id) : IRequest<GetEmployeeByIdResponse?>;
public class GetEmployeeByIdHandler : IRequestHandler<GetEmployeeByIdQuery, GetEmployeeByIdResponse?>
{
private readonly AppDbContext _context;
public GetEmployeeByIdHandler(AppDbContext context) => _context = context;
public async Task<GetEmployeeByIdResponse?> Handle(GetEmployeeByIdQuery request, CancellationToken cancellationToken)
{
return await _context.Employee
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetEmployeeByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Name = x.Name,
Description = x.Description,
Street = x.Street,
City = x.City,
State = x.State,
ZipCode = x.ZipCode,
Country = x.Country,
PhoneNumber = x.PhoneNumber,
FaxNumber = x.FaxNumber,
EmailAddress = x.EmailAddress,
Website = x.Website,
WhatsApp = x.WhatsApp,
LinkedIn = x.LinkedIn,
Facebook = x.Facebook,
Instagram = x.Instagram,
TwitterX = x.TwitterX,
TikTok = x.TikTok,
EmployeeGroupId = x.EmployeeGroupId,
EmployeeCategoryId = x.EmployeeCategoryId,
JobTitle = x.JobTitle,
CommissionRate = x.CommissionRate,
EmployeeNumber = x.EmployeeNumber,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,45 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class GetEmployeeListResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? Name { get; set; }
public string? PhoneNumber { get; set; }
public string? EmailAddress { get; set; }
public string? EmployeeGroupName { get; set; }
public string? EmployeeCategoryName { get; set; }
}
public record GetEmployeeListQuery() : IRequest<List<GetEmployeeListResponse>>;
public class GetEmployeeListHandler : IRequestHandler<GetEmployeeListQuery, List<GetEmployeeListResponse>>
{
private readonly AppDbContext _context;
public GetEmployeeListHandler(AppDbContext context) => _context = context;
public async Task<List<GetEmployeeListResponse>> Handle(GetEmployeeListQuery request, CancellationToken cancellationToken)
{
return await _context.Employee
.AsNoTracking()
.Include(x => x.EmployeeGroup)
.Include(x => x.EmployeeCategory)
.OrderBy(x => x.Name)
.Select(x => new GetEmployeeListResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Name = x.Name,
PhoneNumber = x.PhoneNumber,
EmailAddress = x.EmailAddress,
EmployeeGroupName = x.EmployeeGroup != null ? x.EmployeeGroup.Name : string.Empty,
EmployeeCategoryName = x.EmployeeCategory != null ? x.EmployeeCategory.Name : string.Empty
})
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,45 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class LookupEmployeeResponse
{
public List<LookupItem> EmployeeGroups { get; set; } = new();
public List<LookupItem> EmployeeCategories { get; set; } = new();
}
public class LookupItem
{
public string? Id { get; set; }
public string? Name { get; set; }
}
public record LookupEmployeeQuery() : IRequest<LookupEmployeeResponse>;
public class LookupEmployeeHandler : IRequestHandler<LookupEmployeeQuery, LookupEmployeeResponse>
{
private readonly AppDbContext _context;
public LookupEmployeeHandler(AppDbContext context) => _context = context;
public async Task<LookupEmployeeResponse> Handle(LookupEmployeeQuery request, CancellationToken cancellationToken)
{
var result = new LookupEmployeeResponse();
result.EmployeeGroups = await _context.EmployeeGroup
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
result.EmployeeCategories = await _context.EmployeeCategory
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
return result;
}
}
@@ -0,0 +1,102 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class UpdateEmployeeRequest
{
public string? Id { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? Street { get; set; }
public string? City { get; set; }
public string? State { get; set; }
public string? ZipCode { get; set; }
public string? Country { get; set; }
public string? PhoneNumber { get; set; }
public string? FaxNumber { get; set; }
public string? EmailAddress { get; set; }
public string? Website { get; set; }
public string? WhatsApp { get; set; }
public string? LinkedIn { get; set; }
public string? Facebook { get; set; }
public string? Instagram { get; set; }
public string? TwitterX { get; set; }
public string? TikTok { get; set; }
public string? EmployeeGroupId { get; set; }
public string? EmployeeCategoryId { get; set; }
public string? JobTitle { get; set; }
public decimal CommissionRate { get; set; }
public string? EmployeeNumber { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdateEmployeeResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdateEmployeeCommand(UpdateEmployeeRequest Data) : IRequest<UpdateEmployeeResponse>;
public class UpdateEmployeeHandler : IRequestHandler<UpdateEmployeeCommand, UpdateEmployeeResponse>
{
private readonly AppDbContext _context;
public UpdateEmployeeHandler(AppDbContext context) => _context = context;
public async Task<UpdateEmployeeResponse> Handle(UpdateEmployeeCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.Employee
.AnyAsync(x => x.Name == request.Data.Name && x.Id != request.Data.Id, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Employee", request.Data.Name ?? string.Empty);
}
var entity = await _context.Employee
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
return new UpdateEmployeeResponse { Id = request.Data.Id, Success = false };
}
entity.Name = request.Data.Name;
entity.Description = request.Data.Description;
entity.Street = request.Data.Street;
entity.City = request.Data.City;
entity.State = request.Data.State;
entity.ZipCode = request.Data.ZipCode;
entity.Country = request.Data.Country;
entity.PhoneNumber = request.Data.PhoneNumber;
entity.FaxNumber = request.Data.FaxNumber;
entity.EmailAddress = request.Data.EmailAddress;
entity.Website = request.Data.Website;
entity.WhatsApp = request.Data.WhatsApp;
entity.LinkedIn = request.Data.LinkedIn;
entity.Facebook = request.Data.Facebook;
entity.Instagram = request.Data.Instagram;
entity.TwitterX = request.Data.TwitterX;
entity.TikTok = request.Data.TikTok;
entity.EmployeeGroupId = request.Data.EmployeeGroupId;
entity.EmployeeCategoryId = request.Data.EmployeeCategoryId;
entity.JobTitle = request.Data.JobTitle;
entity.CommissionRate = request.Data.CommissionRate;
entity.EmployeeNumber = request.Data.EmployeeNumber;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateEmployeeResponse
{
Id = entity.Id,
Success = true
};
}
}
@@ -0,0 +1,37 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Organization.Employee.Cqrs;
public class UpdateEmployeeValidator : AbstractValidator<UpdateEmployeeRequest>
{
public UpdateEmployeeValidator()
{
RuleFor(x => x.Id)
.NotEmpty().WithMessage("ID is required for update");
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Employee Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.EmployeeNumber)
.NotEmpty().WithMessage("Employee Number is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.JobTitle)
.NotEmpty().WithMessage("Job Title is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.CommissionRate)
.GreaterThanOrEqualTo(0).WithMessage("Commission Rate cannot be negative");
RuleFor(x => x.EmailAddress)
.EmailAddress().When(x => !string.IsNullOrEmpty(x.EmailAddress));
RuleFor(x => x.EmployeeGroupId)
.NotEmpty().WithMessage("Employee Group is required");
RuleFor(x => x.EmployeeCategoryId)
.NotEmpty().WithMessage("Employee Category is required");
}
}