From 2743493a11b152ff28f2161922e093739c0408ac Mon Sep 17 00:00:00 2001 From: MahanCh Date: Sat, 9 Aug 2025 11:02:32 +0330 Subject: [PATCH] add correct validation for create ContractingPartyBankAccounts --- ...ContractingPartyBankAccountsApplication.cs | 70 +++++++++++-------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/CompanyManagment.Application/ContractingPartyBankAccountsApplication.cs b/CompanyManagment.Application/ContractingPartyBankAccountsApplication.cs index 989e9820..e9a81eba 100644 --- a/CompanyManagment.Application/ContractingPartyBankAccountsApplication.cs +++ b/CompanyManagment.Application/ContractingPartyBankAccountsApplication.cs @@ -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 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 Create(List 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 GetList( @@ -91,7 +102,8 @@ public class ContractingPartyBankAccountsApplication:IContractingPartyBankAccoun public async Task> ContractingPartyOrAccountHolderNameSelectList(string search, string selected) { - return await _contractingPartyBankAccountsRepository.ContractingPartyOrAccountHolderNameSelectList(search, selected); + return await _contractingPartyBankAccountsRepository.ContractingPartyOrAccountHolderNameSelectList(search, + selected); } public async Task> CardNumberSelectList(string search, string selected) @@ -108,7 +120,7 @@ public class ContractingPartyBankAccountsApplication:IContractingPartyBankAccoun { return await _contractingPartyBankAccountsRepository.AccountNumberSelectList(search, selected); } - + public async Task> 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); } -} +} \ No newline at end of file