initial commit

This commit is contained in:
2026-07-21 15:36:49 +07:00
commit 77f66132bc
2640 changed files with 850901 additions and 0 deletions
@@ -0,0 +1,82 @@
using Application.Common.Repositories;
using Application.Features.NumberSequenceManager;
using Domain.Entities;
using FluentValidation;
using MediatR;
namespace Application.Features.LeadContactManager.Commands;
public class CreateLeadContactResult
{
public LeadContact? Data { get; set; }
}
public class CreateLeadContactRequest : IRequest<CreateLeadContactResult>
{
public string? LeadId { get; init; }
public string? FullName { get; init; }
public string? Description { get; init; }
public string? AddressStreet { get; init; }
public string? AddressCity { get; init; }
public string? AddressState { get; init; }
public string? MobileNumber { get; init; }
public string? Email { get; init; }
public string? CreatedById { get; init; }
}
public class CreateLeadContactValidator : AbstractValidator<CreateLeadContactRequest>
{
public CreateLeadContactValidator()
{
RuleFor(x => x.LeadId).NotEmpty();
RuleFor(x => x.FullName).NotEmpty();
RuleFor(x => x.AddressStreet).NotEmpty();
RuleFor(x => x.AddressCity).NotEmpty();
RuleFor(x => x.AddressState).NotEmpty();
RuleFor(x => x.MobileNumber).NotEmpty();
RuleFor(x => x.Email).NotEmpty();
}
}
public class CreateLeadContactHandler : IRequestHandler<CreateLeadContactRequest, CreateLeadContactResult>
{
private readonly ICommandRepository<LeadContact> _repository;
private readonly IUnitOfWork _unitOfWork;
private readonly NumberSequenceService _numberSequenceService;
public CreateLeadContactHandler(
ICommandRepository<LeadContact> repository,
IUnitOfWork unitOfWork,
NumberSequenceService numberSequenceService
)
{
_repository = repository;
_unitOfWork = unitOfWork;
_numberSequenceService = numberSequenceService;
}
public async Task<CreateLeadContactResult> Handle(CreateLeadContactRequest request, CancellationToken cancellationToken = default)
{
var entity = new LeadContact
{
CreatedById = request.CreatedById,
LeadId = request.LeadId,
Number = _numberSequenceService.GenerateNumber(nameof(LeadContact), "", "LC"),
FullName = request.FullName,
Description = request.Description,
AddressStreet = request.AddressStreet,
AddressCity = request.AddressCity,
AddressState = request.AddressState,
MobileNumber = request.MobileNumber,
Email = request.Email
};
await _repository.CreateAsync(entity, cancellationToken);
await _unitOfWork.SaveAsync(cancellationToken);
return new CreateLeadContactResult
{
Data = entity
};
}
}
@@ -0,0 +1,60 @@
using Application.Common.Repositories;
using Domain.Entities;
using FluentValidation;
using MediatR;
namespace Application.Features.LeadContactManager.Commands;
public class DeleteLeadContactResult
{
public LeadContact? Data { get; set; }
}
public class DeleteLeadContactRequest : IRequest<DeleteLeadContactResult>
{
public string? Id { get; init; }
public string? DeletedById { get; init; }
}
public class DeleteLeadContactValidator : AbstractValidator<DeleteLeadContactRequest>
{
public DeleteLeadContactValidator()
{
RuleFor(x => x.Id).NotEmpty();
}
}
public class DeleteLeadContactHandler : IRequestHandler<DeleteLeadContactRequest, DeleteLeadContactResult>
{
private readonly ICommandRepository<LeadContact> _repository;
private readonly IUnitOfWork _unitOfWork;
public DeleteLeadContactHandler(
ICommandRepository<LeadContact> repository,
IUnitOfWork unitOfWork
)
{
_repository = repository;
_unitOfWork = unitOfWork;
}
public async Task<DeleteLeadContactResult> Handle(DeleteLeadContactRequest request, CancellationToken cancellationToken)
{
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
if (entity == null)
{
throw new Exception($"Entity not found: {request.Id}");
}
entity.UpdatedById = request.DeletedById;
_repository.Delete(entity);
await _unitOfWork.SaveAsync(cancellationToken);
return new DeleteLeadContactResult
{
Data = entity
};
}
}
@@ -0,0 +1,104 @@
using Application.Common.Repositories;
using Domain.Entities;
using FluentValidation;
using MediatR;
namespace Application.Features.LeadContactManager.Commands;
public class UpdateLeadContactResult
{
public LeadContact? Data { get; set; }
}
public class UpdateLeadContactRequest : IRequest<UpdateLeadContactResult>
{
public string? Id { get; init; }
public string? LeadId { get; init; }
public string? FullName { get; init; }
public string? Description { get; init; }
public string? AddressStreet { get; init; }
public string? AddressCity { get; init; }
public string? AddressState { get; init; }
public string? AddressZipCode { get; init; }
public string? AddressCountry { get; init; }
public string? PhoneNumber { get; init; }
public string? FaxNumber { get; init; }
public string? MobileNumber { get; init; }
public string? Email { get; init; }
public string? Website { get; init; }
public string? WhatsApp { get; init; }
public string? LinkedIn { get; init; }
public string? Facebook { get; init; }
public string? Twitter { get; init; }
public string? Instagram { get; init; }
public string? AvatarName { get; init; }
public string? UpdatedById { get; init; }
}
public class UpdateLeadContactValidator : AbstractValidator<UpdateLeadContactRequest>
{
public UpdateLeadContactValidator()
{
RuleFor(x => x.Id).NotEmpty();
RuleFor(x => x.FullName).NotEmpty();
RuleFor(x => x.AddressStreet).NotEmpty();
RuleFor(x => x.AddressCity).NotEmpty();
RuleFor(x => x.AddressState).NotEmpty();
RuleFor(x => x.MobileNumber).NotEmpty();
RuleFor(x => x.Email).NotEmpty();
}
}
public class UpdateLeadContactHandler : IRequestHandler<UpdateLeadContactRequest, UpdateLeadContactResult>
{
private readonly ICommandRepository<LeadContact> _repository;
private readonly IUnitOfWork _unitOfWork;
public UpdateLeadContactHandler(
ICommandRepository<LeadContact> repository,
IUnitOfWork unitOfWork
)
{
_repository = repository;
_unitOfWork = unitOfWork;
}
public async Task<UpdateLeadContactResult> Handle(UpdateLeadContactRequest request, CancellationToken cancellationToken)
{
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
if (entity == null)
{
throw new Exception($"Entity not found: {request.Id}");
}
entity.UpdatedById = request.UpdatedById;
entity.LeadId = request.LeadId;
entity.FullName = request.FullName;
entity.Description = request.Description;
entity.AddressStreet = request.AddressStreet;
entity.AddressCity = request.AddressCity;
entity.AddressState = request.AddressState;
entity.AddressZipCode = request.AddressZipCode;
entity.AddressCountry = request.AddressCountry;
entity.PhoneNumber = request.PhoneNumber;
entity.FaxNumber = request.FaxNumber;
entity.MobileNumber = request.MobileNumber;
entity.Email = request.Email;
entity.Website = request.Website;
entity.WhatsApp = request.WhatsApp;
entity.LinkedIn = request.LinkedIn;
entity.Facebook = request.Facebook;
entity.Twitter = request.Twitter;
entity.Instagram = request.Instagram;
entity.AvatarName = request.AvatarName;
_repository.Update(entity);
await _unitOfWork.SaveAsync(cancellationToken);
return new UpdateLeadContactResult
{
Data = entity
};
}
}