initial commit

This commit is contained in:
2026-07-21 14:41:46 +07:00
commit 1bfa3dd1c2
1159 changed files with 88228 additions and 0 deletions
@@ -0,0 +1,63 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.VendorContact.Cqrs;
public class CreateVendorContactRequest
{
public string? Name { get; set; }
public string? JobTitle { get; set; }
public string? PhoneNumber { get; set; }
public string? EmailAddress { get; set; }
public string? Description { get; set; }
public string? VendorId { get; set; }
}
public class CreateVendorContactResponse
{
public string? Id { get; set; }
public string? Name { get; set; }
}
public record CreateVendorContactCommand(CreateVendorContactRequest Data) : IRequest<CreateVendorContactResponse>;
public class CreateVendorContactHandler : IRequestHandler<CreateVendorContactCommand, CreateVendorContactResponse>
{
private readonly AppDbContext _context;
public CreateVendorContactHandler(AppDbContext context) => _context = context;
public async Task<CreateVendorContactResponse> Handle(CreateVendorContactCommand request, CancellationToken cancellationToken)
{
var entityName = nameof(Data.Entities.VendorContact);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.VendorContact
{
AutoNumber = autoNo,
Name = request.Data.Name,
JobTitle = request.Data.JobTitle,
PhoneNumber = request.Data.PhoneNumber,
EmailAddress = request.Data.EmailAddress,
Description = request.Data.Description,
VendorId = request.Data.VendorId
};
_context.VendorContact.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateVendorContactResponse
{
Id = entity.Id,
Name = entity.Name
};
}
}
@@ -0,0 +1,20 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Thirdparty.VendorContact.Cqrs;
public class CreateVendorContactValidator : AbstractValidator<CreateVendorContactRequest>
{
public CreateVendorContactValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Contact Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.VendorId)
.NotEmpty().WithMessage("Vendor is required");
RuleFor(x => x.EmailAddress)
.EmailAddress().When(x => !string.IsNullOrEmpty(x.EmailAddress));
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.VendorContact.Cqrs;
public record DeleteVendorContactByIdRequest(string Id);
public record DeleteVendorContactByIdCommand(DeleteVendorContactByIdRequest Data) : IRequest<bool>;
public class DeleteVendorContactByIdHandler : IRequestHandler<DeleteVendorContactByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteVendorContactByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteVendorContactByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.VendorContact
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.VendorContact.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,53 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.VendorContact.Cqrs;
public class GetVendorContactByIdResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? Name { get; set; }
public string? JobTitle { get; set; }
public string? PhoneNumber { get; set; }
public string? EmailAddress { get; set; }
public string? Description { get; set; }
public string? VendorId { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetVendorContactByIdQuery(string Id) : IRequest<GetVendorContactByIdResponse?>;
public class GetVendorContactByIdHandler : IRequestHandler<GetVendorContactByIdQuery, GetVendorContactByIdResponse?>
{
private readonly AppDbContext _context;
public GetVendorContactByIdHandler(AppDbContext context) => _context = context;
public async Task<GetVendorContactByIdResponse?> Handle(GetVendorContactByIdQuery request, CancellationToken cancellationToken)
{
return await _context.VendorContact
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetVendorContactByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Name = x.Name,
JobTitle = x.JobTitle,
PhoneNumber = x.PhoneNumber,
EmailAddress = x.EmailAddress,
Description = x.Description,
VendorId = x.VendorId,
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.Thirdparty.VendorContact.Cqrs;
public class GetVendorContactListResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? Name { get; set; }
public string? JobTitle { get; set; }
public string? PhoneNumber { get; set; }
public string? EmailAddress { get; set; }
public string? VendorName { get; set; }
}
public record GetVendorContactListQuery() : IRequest<List<GetVendorContactListResponse>>;
public class GetVendorContactListHandler : IRequestHandler<GetVendorContactListQuery, List<GetVendorContactListResponse>>
{
private readonly AppDbContext _context;
public GetVendorContactListHandler(AppDbContext context) => _context = context;
public async Task<List<GetVendorContactListResponse>> Handle(GetVendorContactListQuery request, CancellationToken cancellationToken)
{
return await _context.VendorContact
.AsNoTracking()
.Include(x => x.Vendor)
.OrderBy(x => x.Name)
.Select(x => new GetVendorContactListResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Name = x.Name,
JobTitle = x.JobTitle,
PhoneNumber = x.PhoneNumber,
EmailAddress = x.EmailAddress,
VendorName = x.Vendor != null ? x.Vendor.Name : string.Empty
})
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,38 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.VendorContact.Cqrs;
public class LookupVendorContactResponse
{
public List<LookupItem> Vendors { get; set; } = new();
}
public class LookupItem
{
public string? Id { get; set; }
public string? Name { get; set; }
}
public record LookupVendorContactQuery() : IRequest<LookupVendorContactResponse>;
public class LookupVendorContactHandler : IRequestHandler<LookupVendorContactQuery, LookupVendorContactResponse>
{
private readonly AppDbContext _context;
public LookupVendorContactHandler(AppDbContext context) => _context = context;
public async Task<LookupVendorContactResponse> Handle(LookupVendorContactQuery request, CancellationToken cancellationToken)
{
var result = new LookupVendorContactResponse();
result.Vendors = await _context.Vendor
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
.ToListAsync(cancellationToken);
return result;
}
}
@@ -0,0 +1,62 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.VendorContact.Cqrs;
public class UpdateVendorContactRequest
{
public string? Id { get; set; }
public string? Name { get; set; }
public string? JobTitle { get; set; }
public string? PhoneNumber { get; set; }
public string? EmailAddress { get; set; }
public string? Description { get; set; }
public string? VendorId { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdateVendorContactResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdateVendorContactCommand(UpdateVendorContactRequest Data) : IRequest<UpdateVendorContactResponse>;
public class UpdateVendorContactHandler : IRequestHandler<UpdateVendorContactCommand, UpdateVendorContactResponse>
{
private readonly AppDbContext _context;
public UpdateVendorContactHandler(AppDbContext context) => _context = context;
public async Task<UpdateVendorContactResponse> Handle(UpdateVendorContactCommand request, CancellationToken cancellationToken)
{
var entity = await _context.VendorContact
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
return new UpdateVendorContactResponse { Id = request.Data.Id, Success = false };
}
entity.Name = request.Data.Name;
entity.JobTitle = request.Data.JobTitle;
entity.PhoneNumber = request.Data.PhoneNumber;
entity.EmailAddress = request.Data.EmailAddress;
entity.Description = request.Data.Description;
entity.VendorId = request.Data.VendorId;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateVendorContactResponse
{
Id = entity.Id,
Success = true
};
}
}
@@ -0,0 +1,23 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Thirdparty.VendorContact.Cqrs;
public class UpdateVendorContactValidator : AbstractValidator<UpdateVendorContactRequest>
{
public UpdateVendorContactValidator()
{
RuleFor(x => x.Id)
.NotEmpty().WithMessage("ID is required for update");
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Contact Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.VendorId)
.NotEmpty().WithMessage("Vendor is required");
RuleFor(x => x.EmailAddress)
.EmailAddress().When(x => !string.IsNullOrEmpty(x.EmailAddress));
}
}