// Index


        public List <AccountTransaction> GetListOfActiveTransactions()
        {
            // create object to return
            var bmAssetTransactionList = new List <AccountTransaction>();

            // get active transactions
            var dbAssetTransactionList = _unitOfWork.AssetTransactions.GetAllActiveByDueDate().ToList();

            // transfer dto to bm
            foreach (var dbAssetTransaction in dbAssetTransactionList)
            {
                // account information
                var dbAsset = _unitOfWork.Assets.Get(dbAssetTransaction.AssetId);
                if (dbAsset == null)
                {
                    return(new List <AccountTransaction>());
                }

                // format values
                dbAsset.Name = GetAssetNameWithAccountNumber(dbAsset);
                dbAssetTransaction.Amount = TransactionUtility.FormatAmount(
                    dbAssetTransaction.TransactionTypeId,
                    dbAssetTransaction.Amount);

                // transfer to bm
                bmAssetTransactionList.Add(new AccountTransaction(
                                               dbAssetTransaction,
                                               dbAsset));
            }

            return(bmAssetTransactionList);
        }
Exemple #2
0
 private int PerformDMLWithRawSQLWithinTransaction(String query, params Object[] parameters)
 {
     ContractUtility.Requires <ArgumentNullException>(!query.IsNullOrWhiteSpace(), "query instance cannot be null or empty");
     Transactions.TransactionScope scope = TransactionUtility.GetTransactionScope(_isoLevel, _scopeOption);
     using (scope)
     {
         int retValue = _context.Database.ExecuteSqlCommand(query, parameters);
         scope.Complete();
         return(retValue);
     }
 }
Exemple #3
0
        /// <summary>
        /// This method can run synchronous as well as asynchronous operations within a transaction
        /// in the order in which the operations are written in the consumer class.Here synchronous
        /// as well as asynchronous operations are hadnled since "Task" also inherently handles both
        /// synchronous and asynchronous scenarios.
        ///
        /// </summary>
        /// <param name="shouldCommitSynchronousOperationsFirst"></param>
        /// <param name="shouldAutomaticallyRollBackOnTransactionException"></param>
        /// <param name="shouldThrowOnException"></param>
        /// <returns></returns>
        public async Task CommitAsync(CancellationToken token = default(CancellationToken), bool shouldAutomaticallyRollBackOnTransactionException = true, bool shouldThrowOnException = true)
        {
            CheckForObjectAlreadyDisposedOrNot(typeof(UnitOfWork).FullName);
            ContractUtility.Requires <ArgumentOutOfRangeException>(_operationsQueue.Count > 0, "Atleast one operation must be there to be executed.");
            ContractUtility.Requires <NotSupportedException>(_operationsQueue.Any(x => x.AsyncOperation.IsNotNull()),
                                                             "If CommitAsync method is used,there needs to be atleast one async operation exceuted." +
                                                             "Please use Commit method(instead of CommitAsync) if there is not " +
                                                             "a single async operation.");

            await ExceptionHandlingUtility.HandleExceptionWithNullCheck(async x =>
            {
                _scope = TransactionUtility.GetTransactionScope(_isoLevel, _scopeOption, true);
                try
                {
                    while (_operationsQueue.Count > 0)
                    {
#if TEST
                        ThrowExceptionForRollbackCheck();
#endif
                        OperationData operationData = _operationsQueue.Dequeue();
                        if (operationData.Operation.IsNotNull())
                        {
                            operationData.Operation();
                        }
                        else if (operationData.AsyncOperation.IsNotNull())
                        {
                            await operationData.AsyncOperation(x);
                        }
                    }
                    CompleteScope(() =>
                    {
                        _scope.Complete(); // this just completes the transaction.Not yet committed here.
                        _scope.Dispose();  // After everthing runs successfully within the transaction
                                           // and after completion, this should be called to actually commit the data
                                           // within the transaction scope.
                    }, shouldAutomaticallyRollBackOnTransactionException, shouldThrowOnException);
                }
                catch (Exception ex)
                {
                    //Although ex is not exactly a commit exception but still passing it to reuse Rollback method.Using the Rollback
                    //method to reuse exception handling and dispose the transaction scope object(else it can cause issues for the
                    //future transactions).
                    Rollback(ex);
                }
            }, token, _exceptionHandler, null);//TODO - proper exception handling compensating handler needs to be here
        }
        public IActionResult UploadFiles(List <IFormFile> files)
        {
            if (!OfxFileValidator.Validate(files))
            {
                return(RedirectToAction("Index"));
            }

            List <TransactionModel> transactionList = TransactionUtility.GetDistinctTransactions(files);

            if (!transactionList.Any())
            {
                return(RedirectToAction("Index"));
            }

            this._transactionDataBaseConnector.SaveTransactions(transactionList);

            string queryKey = transactionList.FirstOrDefault().QueryKey;

            return(RedirectToAction("Index", new { queryKey }));
        }
Exemple #5
0
        /// <summary>
        /// Comits all the data within this unit of work instance in an atomic way i.e. all or none get transacted.
        /// Order of operations of different instances of same type or different types needs to be handled at
        /// the Business or Service Layer.
        /// </summary>
        /// <param name="shouldAutomaticallyRollBackOnTransactionException">when set to true(default value)
        /// the RollBack method need not be called from the consumer class</param>
        public void Commit(bool shouldAutomaticallyRollBackOnTransactionException = true, bool shouldThrowOnException = true)
        {
            ContractUtility.Requires <ArgumentOutOfRangeException>(_operationsQueue.IsNotNullOrEmpty(), "Atleast one operation must be there to be executed.");

            ContractUtility.Requires <NotSupportedException>(_operationsQueue.All(x => x.AsyncOperation.IsNull()),
                                                             "Async operations are not supported by Commit method.Use CommitAsync instead.");

            ExceptionHandlingUtility.HandleExceptionWithNullCheck(() =>
            {
                _scope = TransactionUtility.GetTransactionScope(_isoLevel, _scopeOption);
                try
                {
                    while (_operationsQueue.Count > 0)
                    {
#if TEST
                        ThrowExceptionForRollbackCheck();
#endif
                        OperationData operationData = _operationsQueue.Dequeue();
                        if (operationData.Operation.IsNotNull())
                        {
                            operationData.Operation();
                        }
                    }
                    CompleteScope(() =>
                    {
                        _scope.Complete(); // this just completes the transaction.Not yet committed here.
                        _scope.Dispose();  // After everthing runs successfully within the transaction
                                           // and after completion, this should be called to actually commit the data
                                           // within the transaction scope.
                    }, shouldAutomaticallyRollBackOnTransactionException, shouldThrowOnException);
                }
                catch (Exception ex)
                {
                    //Although ex is not exactly a commit exception but still passing it to reuse Rollback method.Using the Rollback
                    //method to reuse exception handling and dispose the transaction scope object(else it can cause issues for the
                    //future transactions).
                    Rollback(ex);
                }
            }, _exceptionHandler);//TODO - proper exception handling compensating handler needs to be here
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                var    httpClient = _httpClientFactory.CreateClient("IncreaseAPI");
                FileVm fileVm     = null;

                while (fileVm == null)
                {
                    try
                    {
                        fileVm = TransactionUtility
                                 .TransactionBatchSplitter(await httpClient.GetStringAsync("/file.txt"));
                    } catch (Exception e) {
                        Console.WriteLine(e.Message);
                    }
                }

                await FileToBd(fileVm);

                await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken);
            }
        }