private void SetResponse(TrasnferCompletedResponse res, Domain.Models.Transfer transfer)
 {
     res.Message        = transfer.Status ? "Transfer was completed successfully" : "Failure";
     res.TrasnferNumber = transfer.TrasnferNumber;
     res.CurrentBalance = transfer.Depositor.Balance;
     res.Status         = transfer.Status;
 }
        /// <summary>
        /// Safe Loading
        /// Check Beneficiary before load Depositor
        /// </summary>
        /// <returns>Transfer</returns>
        private async Task <Domain.Models.Transfer> LoadAsync(TransferCommand cmd, DomainValidation vld)
        {
            var transfer = new Domain.Models.Transfer()
            {
                Amount = cmd.Amount,
            };

            var beneficiary = await _accountRepo.GetAsync(
                agency : cmd.Beneficiary.Agency,
                accountNumber : cmd.Beneficiary.AccountNumber);

            vld = beneficiary.IsValidForReceiveAmount(cmd.Amount);

            if (!vld.IsSuccess)
            {
                return(null);
            }

            transfer.SetBeneficiary(beneficiary);

            var depositor = await _accountRepo.GetAsync(
                agency : cmd.Depositor.Agency,
                accountNumber : cmd.Depositor.AccountNumber);

            vld = depositor.IsValidForMakeDeposit(cmd.Amount);
            if (!vld.IsSuccess)
            {
                return(null);
            }

            transfer.SetDepositor(depositor);
            return(transfer);
        }
 private void SetUnitOfWork(Domain.Models.Transfer transfer)
 {
     _unitOfWork.Trasnfers.Add(transfer);
     _unitOfWork.Accounts.Attach(transfer.Depositor).State   = EntityState.Modified;
     _unitOfWork.Accounts.Attach(transfer.Beneficiary).State = EntityState.Modified;
 }