Пример #1
0
        /// <summary>
        /// Executes a given transfer
        /// </summary>
        /// <param name="transfer">The transfer to execture</param>
        /// <returns>a <see cref="Transfer"/> Object that has been executed.
        /// It's <see cref="Transfer.TransferStatus">TransferStatus</see> should be set to <see cref="TransferStatus.Approved">Approved</see></returns>
        private Transfer ExecuteTransfer(Transfer transfer)
        {
            Transfer executedTransfer = null;

            try
            {
                //todo: ask ben how to make transactions work good
                //using (TransactionScope transaction = new TransactionScope())//ben told me about this, but ben lied
                {
                    //todon't: make sure that the ID of the currently logged in user owns the toAccount on send transfers, or owns the fromAccount on request transfers. but maybe do this in another method
                    //deduct
                    decimal balanceBeforeDeduct = accountDAO.GetAccountById(transfer.AccountFromId).Balance;
                    accountDAO.DeductFromAccount(transfer.AccountFromId, transfer.Amount);
                    decimal balanceAfterDeduct     = accountDAO.GetAccountById(transfer.AccountFromId).Balance;
                    decimal amountActuallyDeducted = balanceBeforeDeduct - balanceAfterDeduct;

                    //deposit
                    accountDAO.DepositIntoAccount(transfer.AccountToId, amountActuallyDeducted);

                    //update
                    executedTransfer = transferDAO.UpdateTransferStatus(transfer.TransferId, TransferStatus.Approved);

                    //transaction.Complete();
                }
                return(executedTransfer);
            }
            catch (TransactionAbortedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw e;
            }
        }