I am learning a clean architechture.
I have the following structure:
Application, Base, Domain, Infrastructure, Shared, Web
So I put some command under Application - Services - ModuleName - Command - CreateBusinessSectorCommand.cs
The code is:
namespace CBS.Web.USI.DanaPensiun.Application.Services.AdminMaster.BusinessSector.Command;
public sealed class CreateNewBusinessSectorCommand : IRequest<BaseResponse>
{
public string BusinessSectorCode { get; set; } = null!;
public string? BusinessSectorDescription { get; set; }
[ForeignKey(nameof(BusinessSector))]
public string? BusinessLineCode { get; set; }
public Mfbl? Mfbl { get; set; }
}
public sealed class CreateNewBusinessSectorHandler : IRequestHandler<CreateNewBusinessSectorCommand, BaseResponse>
{
private readonly IDapperRepository<object> _dapperRepository;
private readonly IRepository<object> _repository;
public CreateNewBusinessSectorHandler(IDapperRepository<Object> dapperRepository, IRepository<Object> repository)
{
_dapperRepository = dapperRepository;
_repository = repository;
}
public async Task<BaseResponse> Handle(CreateNewBusinessSectorCommand request, CancellationToken cancellationToken)
{
var response = new BaseResponse();
try
{
var entity = new Mfbs
{
MfbsBsCode = request.BusinessSectorCode,
MfbsDescription = request.BusinessSectorDescription,
MfbsBlCode = request.BusinessLineCode
};
var query = await _repository.AddAsync(entity);
response.SetReturnSuccessStatus();
response.Data = query;
}
catch (Exception ex)
{
response.SetReturnStatus(DanaPensiunConstants.ERROR_STATUS, ex.Message);
response.Data = null;
throw new Exception(ex.Message);
}
return response;
}
}
As you can see on the top of the code, I put some DataAnnotation like ForeignKey. Do you think this is the best place to put it on?
Please advise.
Thank you.