add correct validation for create ContractingPartyBankAccounts

This commit is contained in:
MahanCh
2025-08-09 11:02:32 +03:30
parent f9de490c13
commit 2743493a11

View File

@@ -8,12 +8,13 @@ using CompanyManagment.App.Contracts.PersonalContractingParty;
namespace CompanyManagment.Application;
public class ContractingPartyBankAccountsApplication:IContractingPartyBankAccountsApplication
public class ContractingPartyBankAccountsApplication : IContractingPartyBankAccountsApplication
{
private readonly IContractingPartyBankAccountsRepository _contractingPartyBankAccountsRepository;
private readonly IPersonalContractingPartyRepository _personalContractingPartyRepository;
public ContractingPartyBankAccountsApplication(IContractingPartyBankAccountsRepository contractingPartyBankAccountsRepository,
public ContractingPartyBankAccountsApplication(
IContractingPartyBankAccountsRepository contractingPartyBankAccountsRepository,
IPersonalContractingPartyRepository personalContractingPartyRepository)
{
_contractingPartyBankAccountsRepository = contractingPartyBankAccountsRepository;
@@ -23,13 +24,13 @@ public class ContractingPartyBankAccountsApplication:IContractingPartyBankAccoun
public async Task<OperationResult> Create(CreateContractingPartyBankAccounts command)
{
var operationResult = new OperationResult();
if (!_personalContractingPartyRepository.Exists(x => x.id == command.ContractingPartyId))
return operationResult.Failed("طرف حساب مورد نظر یافت نشد");
if (string.IsNullOrWhiteSpace(command.CardNumber))
return operationResult.Failed("شماره کارت خود را وارد کنید");
if (string.IsNullOrWhiteSpace(command.AccountNumber))
return operationResult.Failed("شماره حساب خود را وارد کنید");
@@ -38,16 +39,15 @@ public class ContractingPartyBankAccountsApplication:IContractingPartyBankAccoun
if (string.IsNullOrWhiteSpace(command.AccountHolderName))
return operationResult.Failed("نام صاحب حساب را وارد کنید");
var entity = new ContractingPartyBankAccount(command.ContractingPartyId, command.CardNumber,
command.AccountHolderName,command.AccountNumber, command.IBan,command.IsAuth);
command.AccountHolderName, command.AccountNumber, command.IBan, command.IsAuth);
await _contractingPartyBankAccountsRepository.CreateAsync(entity);
await _contractingPartyBankAccountsRepository.SaveChangesAsync();
return operationResult.Succcedded();
}
public async Task<OperationResult> Create(List<CreateContractingPartyBankAccounts> commands)
@@ -57,29 +57,40 @@ public class ContractingPartyBankAccountsApplication:IContractingPartyBankAccoun
{
if (!_personalContractingPartyRepository.Exists(x => x.id == command.ContractingPartyId))
return operationResult.Failed("طرف حساب مورد نظر یافت نشد");
if (string.IsNullOrWhiteSpace(command.CardNumber))
return operationResult.Failed("شماره کارت خود را وارد کنید");
if (string.IsNullOrWhiteSpace(command.AccountNumber))
return operationResult.Failed("شماره حساب خود را وارد کنید");
if (string.IsNullOrWhiteSpace(command.IBan))
return operationResult.Failed("شماره شبا خود را وارد کنید");
if (command.IsAuth)
{
if (string.IsNullOrWhiteSpace(command.CardNumber))
return operationResult.Failed("شماره کارت خود را وارد کنید");
if (string.IsNullOrWhiteSpace(command.AccountNumber))
return operationResult.Failed("شماره حساب خود را وارد کنید");
if (string.IsNullOrWhiteSpace(command.IBan))
return operationResult.Failed("شماره شبا خود را وارد کنید");
}
else if(string.IsNullOrWhiteSpace(command.CardNumber) &&
string.IsNullOrWhiteSpace(command.AccountNumber) &&
string.IsNullOrWhiteSpace(command.IBan))
{
return operationResult.Failed(" حداقل یکی از اطلاعات بانکی را وارد کنید: شماره کارت، شماره حساب یا شماره شبا");
}
if (string.IsNullOrWhiteSpace(command.AccountHolderName))
{
return operationResult.Failed("نام صاحب حساب را وارد کنید");
}
var entity = new ContractingPartyBankAccount(command.ContractingPartyId, command.CardNumber,
command.AccountHolderName,command.AccountNumber, command.IBan,command.IsAuth);
command.AccountHolderName, command.AccountNumber, command.IBan, command.IsAuth);
await _contractingPartyBankAccountsRepository.CreateAsync(entity);
}
await _contractingPartyBankAccountsRepository.SaveChangesAsync();
return operationResult.Succcedded();
await _contractingPartyBankAccountsRepository.SaveChangesAsync();
return operationResult.Succcedded();
}
public async Task<GetContractingPartyBankAccountViewModel> GetList(
@@ -91,7 +102,8 @@ public class ContractingPartyBankAccountsApplication:IContractingPartyBankAccoun
public async Task<List<string>> ContractingPartyOrAccountHolderNameSelectList(string search,
string selected)
{
return await _contractingPartyBankAccountsRepository.ContractingPartyOrAccountHolderNameSelectList(search, selected);
return await _contractingPartyBankAccountsRepository.ContractingPartyOrAccountHolderNameSelectList(search,
selected);
}
public async Task<List<string>> CardNumberSelectList(string search, string selected)
@@ -108,7 +120,7 @@ public class ContractingPartyBankAccountsApplication:IContractingPartyBankAccoun
{
return await _contractingPartyBankAccountsRepository.AccountNumberSelectList(search, selected);
}
public async Task<List<string>> GetAccountHolderNameSelectList(string search, string selected)
{
return await _contractingPartyBankAccountsRepository.GetAccountHolderNameSelectList(search, selected);
@@ -118,4 +130,4 @@ public class ContractingPartyBankAccountsApplication:IContractingPartyBankAccoun
{
return await _contractingPartyBankAccountsRepository.ContractingPartyNamesSelectList(search, selected);
}
}
}