예제 #1
0
        public void RequestAnticipationTest()
        {
            ShopKeeper shopKeeper = new ShopKeeper()
            {
                Name = "Mario"
            };

            _shopKeeperRepository.Insert(shopKeeper);
            _shopKeeperRepository.SaveChanges();

            Transaction transaction = new Transaction()
            {
                AcquirerApproval   = true,
                TransactionDate    = DateTime.Now,
                PassThroughValue   = 0,
                PassThroughDate    = DateTime.Now,
                TransactionValue   = 1000,
                InstalmentQuantity = 2
            };

            Transaction transaction2 = new Transaction()
            {
                AcquirerApproval   = true,
                TransactionDate    = DateTime.Now,
                PassThroughValue   = 0,
                PassThroughDate    = DateTime.Now,
                TransactionValue   = 600,
                InstalmentQuantity = 4
            };


            Transaction transaction3 = new Transaction()
            {
                AcquirerApproval   = true,
                TransactionDate    = DateTime.Now,
                PassThroughValue   = 0,
                PassThroughDate    = DateTime.Now,
                TransactionValue   = 600,
                InstalmentQuantity = 4
            };

            _context.Transactions.Add(transaction);
            _context.Transactions.Add(transaction2);
            _context.Transactions.Add(transaction3);
            _context.SaveChanges();

            RequestedTransactionsDTO dto = new RequestedTransactionsDTO()
            {
                ShopKeeperID   = shopKeeper.ShopKeeperID,
                TransactionIDs = new List <int>()
                {
                    transaction.TransactionID, transaction2.TransactionID
                }
            };

            var result = _controller.RequestAnticipation(dto) as CreatedAtActionResult;

            Assert.NotNull(result);
        }
        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));
        }
예제 #3
0
        public void GetAnticipationRequestTest()
        {
            Transaction transaction = new Transaction()
            {
                AcquirerApproval   = true,
                TransactionDate    = DateTime.Now,
                PassThroughValue   = 0,
                PassThroughDate    = DateTime.Now,
                TransactionValue   = 1000,
                InstalmentQuantity = 2
            };

            Transaction transaction2 = new Transaction()
            {
                AcquirerApproval   = true,
                TransactionDate    = DateTime.Now,
                PassThroughValue   = 0,
                PassThroughDate    = DateTime.Now,
                TransactionValue   = 600,
                InstalmentQuantity = 4
            };


            Transaction transaction3 = new Transaction()
            {
                AcquirerApproval   = true,
                TransactionDate    = DateTime.Now,
                PassThroughValue   = 0,
                PassThroughDate    = DateTime.Now,
                TransactionValue   = 600,
                InstalmentQuantity = 4
            };

            _context.Transactions.Add(transaction);
            _context.Transactions.Add(transaction2);
            _context.Transactions.Add(transaction3);
            _context.SaveChanges();

            RequestedTransactionsDTO dto = new RequestedTransactionsDTO()
            {
                TransactionIDs = new List <int>()
                {
                    transaction.TransactionID, transaction2.TransactionID
                }
            };

            var result = _controller.RequestAnticipation(dto) as CreatedAtActionResult;

            var result2 = _controller.GetTransactionAnticipationRequest(1) as OkObjectResult;

            Assert.NotNull(result2);
        }