public IActionResult RequestAnticipation(RequestedTransactionsDTO dto)
        {
            List <Transaction> transactions = new List <Transaction>();
            decimal            transactionsAnticipationValue = 0;
            decimal            totalTransactionValue         = 0;

            bool ongoingAnticipations = _transactionAnticipationRepository
                                        .OnGoingTransactionAnticipationForShopKeeper(dto.ShopKeeperID).Any();

            if (ongoingAnticipations)
            {
                return(BadRequest("There are on going transaction anticipations for shop keeper"));
            }

            foreach (var transactionID in dto.TransactionIDs)
            {
                var transaction = _transactionRepository.ObtainAnticipatableTransactions()
                                  .FirstOrDefault(x => x.TransactionID == transactionID);

                if (transaction != null && transaction.AcquirerApproval)
                {
                    decimal instalmentValue = transaction.TransactionValue / transaction.InstalmentQuantity;
                    totalTransactionValue         += transaction.TransactionValue;
                    transactionsAnticipationValue += ((instalmentValue * (decimal)3.8) / 100) * transaction.InstalmentQuantity;
                    transactions.Add(transaction);
                }
            }

            if (!transactions.Any())
            {
                return(BadRequest("No anticipable transactions"));
            }

            TransactionAnticipation transactionAnticipation = new TransactionAnticipation()
            {
                AnticipationResult    = null,
                Status                = (int)Auxiliary.TransactionStatuses.WaitingForAnalysis,
                SolicitationDate      = DateTime.Now,
                TotalPassThroughValue = totalTransactionValue - transactionsAnticipationValue,
                TotalTransactionValue = totalTransactionValue,
                AnalysisDate          = null,
                Transactions          = transactions
            };

            _transactionAnticipationRepository.Insert(transactionAnticipation);
            int result = _transactionAnticipationRepository.SaveChanges();

            if (result == 0)
            {
                return(StatusCode((int)HttpStatusCode.NotModified));
            }

            return(CreatedAtAction("GetAnticipationRequest",
                                   new { transactionAnticipationID = transactionAnticipation.TransactionAnticipationID }, transactionAnticipation));
        }
        public IActionResult GetTransactionAnticipationRequest(int transactionAnticipationID)
        {
            TransactionAnticipation transactionAnticipation = _transactionAnticipationRepository
                                                              .ObtainById(transactionAnticipationID);

            if (transactionAnticipation == null)
            {
                return(StatusCode((int)HttpStatusCode.NoContent));
            }

            var dto = _mapper.Map <TransactionAnticipation, TransactionAnticipationDTO>(transactionAnticipation);

            return(Ok(dto));
        }