示例#1
0
        protected virtual bool CheckTransaction(TransactionDBModel transaction)
        {
            if (transaction.Amount < 0)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(transaction.SenderId) || string.IsNullOrEmpty(transaction.ReceiverId))
            {
                return(false);
            }

            double accountBalance = _transactionDAO.GetAccountbalance(transaction.SenderId);

            if (accountBalance < 0)
            {
                return(false);
            }

            if (accountBalance < transaction.Amount)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,SenderId,ReceiverId,TransactionDateTime,Reason,Amount,Reference")] TransactionDBModel transactionTable)
        {
            if (id != transactionTable.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(transactionTable);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TransactionTableExists(transactionTable.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(transactionTable));
        }
示例#3
0
        private void AddTransactions(List <string> userNames, int numberOfTransactions = 30)
        {
            if (_context.Transactions.Any())
            {
                return;   // DB has been seeded
            }

            Random random = new Random();

            for (int i = 0; i < numberOfTransactions; i++)
            {
                TransactionDBModel transactionTable = new TransactionDBModel
                {
                    Amount = random.NextDouble() * random.Next(10, 1000),
                    TransactionDateTime = DateTime.UtcNow.AddSeconds(random.Next(0, 4320000) * -1),
                    Reason     = StringUtils.GetRandomFriendlyString(5),
                    ReceiverId = userNames[random.Next(0, userNames.Count)],
                    SenderId   = userNames[random.Next(0, userNames.Count)]
                };

                _context.Transactions.Add(transactionTable);
            }

            _context.SaveChanges();
        }
        public override TransactionDBModel Details(int?id)
        {
            TransactionDBModel transaction = base.Details(id);

            if (transaction == null)
            {
                return(null);
            }

            string userName = _httpContextAccessor.HttpContext.GetUserName();
            string role     = _httpContextAccessor.HttpContext.GetRole();

            if (transaction.SenderId != userName && transaction.ReceiverId != userName && role != CookieConstants.ADMIN_ROLE_STRING)
            {
                if (_ctfOptions.CtfChallengeOptions.Enumeration)
                {
                    CtfChallangeModel enumerationChallange = _ctfOptions.CtfChallanges
                                                             .Where(x => x.Type == CtfChallengeTypes.Enumeration)
                                                             .Single();

                    _httpContextAccessor.HttpContext.Response.Headers.Add(enumerationChallange.FlagKey, enumerationChallange.Flag);
                }
                else
                {
                    return(null);
                }
            }

            return(transaction);
        }
示例#5
0
        public bool Add(TransactionDBModel transaction)
        {
            _customerContext.Transactions.Add(transaction);

            int changes = _customerContext.SaveChanges();

            return(changes > 0);
        }
示例#6
0
        public IActionResult Get([FromRoute] int id)
        {
            TransactionDBModel transaction = _transactionBL.Details(id);

            if (transaction == null)
            {
                return(NotFound());
            }

            return(Ok(transaction));
        }
示例#7
0
        // GET: Transaction/Details/5
        public IActionResult Details(int?id)
        {
            TransactionDBModel transaction = _transactionBL.Details(id);

            if (transaction == null)
            {
                return(NotFound());
            }

            return(View(transaction));
        }
示例#8
0
        public virtual bool Create(TransactionDBModel transaction)
        {
            bool result = CheckTransaction(transaction);

            if (!result)
            {
                return(false);
            }

            return(_transactionDAO.Add(transaction));
        }
示例#9
0
        public virtual TransactionDBModel Details(int?id)
        {
            if (!id.HasValue)
            {
                return(null);
            }

            TransactionDBModel transaction = _transactionDAO.Get(id.Value);

            return(transaction);
        }
示例#10
0
        public override bool Create(TransactionDBModel transactionTable)
        {
            string userName = _httpContextAccessor.HttpContext.GetUserName();

            if (transactionTable.SenderId != userName)
            {
                CtfChallangeModel invalidModelChallenge = _ctfOptions.CtfChallanges
                                                          .Where(x => x.Type == CtfChallengeTypes.InvalidModel)
                                                          .Single();

                _httpContextAccessor.HttpContext.Response.Cookies.Append(invalidModelChallenge.FlagKey, invalidModelChallenge.Flag);
            }

            return(base.Create(transactionTable));
        }
示例#11
0
        public IActionResult Create([FromBody] TransactionDBModel transaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool createResult = _transactionBL.Create(transaction);

            if (!createResult)
            {
                return(BadRequest());
            }

            return(Ok(new EmptyResult()));
        }
示例#12
0
        public virtual bool Pay(DepositRequest request)
        {
            TransactionDBModel transaction = new TransactionDBModel
            {
                SenderId            = request.SenderId,
                ReceiverId          = "store",
                Amount              = request.Amount,
                Reason              = request.Reason,
                TransactionDateTime = DateTime.UtcNow
            };

            _customerContext.Transactions.Add(transaction);

            int changes = _customerContext.SaveChanges();

            return(changes > 0);
        }
示例#13
0
        public IActionResult Create([Bind("Id,SenderId,ReceiverId,TransactionDateTime,Reason,Amount,Reference")] TransactionDBModel transaction)
        {
            if (!ModelState.IsValid)
            {
                return(View(transaction));
            }

            bool createResult = _transactionBL.Create(transaction);

            if (!createResult)
            {
                ModelState.AddModelError(string.Empty, "Error");
                return(View(transaction));
            }

            return(RedirectToAction(nameof(Index)));
        }
示例#14
0
        protected override bool CheckTransaction(TransactionDBModel transaction)
        {
            if (_ctfOptions.CtfChallengeOptions.FreeCredit)
            {
                if (transaction.ReceiverId == SecureBankConstants.CREDIT_USERNAME)
                {
                    CtfChallangeModel freeCredit = _ctfOptions.CtfChallanges
                                                   .Where(x => x.Type == CtfChallengeTypes.FreeCredit)
                                                   .SingleOrDefault();

                    _httpContextAccessor.HttpContext.Response.Cookies.Append(freeCredit.FlagKey, freeCredit.Flag);

                    return(true);
                }
            }

            return(base.CheckTransaction(transaction));
        }
示例#15
0
        public void GiveMoney(List <string> userNames, double amount = 10000)
        {
            List <TransactionDBModel> transactions = new List <TransactionDBModel>();

            foreach (var user in userNames)
            {
                TransactionDBModel transactionDBModel = new TransactionDBModel
                {
                    Amount = amount,
                    TransactionDateTime = DateTime.UtcNow,
                    Reason     = "top up",
                    ReceiverId = user,
                    SenderId   = "SecureBank"
                };

                transactions.Add(transactionDBModel);
            }

            _context.Transactions.AddRange(transactions);

            _context.SaveChanges();
        }
示例#16
0
        public virtual int MakeRandomTransactions(string toUserId)
        {
            Random rand      = new Random();
            int    randTrans = rand.Next(1, 15);

            List <UserDBModel> users = _customerContext.UserData.ToList();

            for (int i = 0; i < randTrans; i++)
            {
                TransactionDBModel transactionTable = new TransactionDBModel
                {
                    Amount = rand.NextDouble() * rand.Next(10, 1000),
                    TransactionDateTime = DateTime.UtcNow.AddSeconds(rand.Next(0, 4320000) * -1),
                    Reason     = StringUtils.GetRandomFriendlyString(5),
                    ReceiverId = i % 2 == 0 ? toUserId : users[new Random().Next(0, users.Count)].UserName,
                    SenderId   = i % 2 == 0 ? users[new Random().Next(0, users.Count)].UserName : toUserId
                };
                _customerContext.Transactions.Add(transactionTable);
            }

            return(_customerContext.SaveChanges());
        }
示例#17
0
        public override bool Create(TransactionDBModel transactionTable)
        {
            string userName = _httpContextAccessor.HttpContext.GetUserName();

            if (transactionTable.SenderId != userName)
            {
                if (!_ctfOptions.CtfChallengeOptions.InvalidModelTransaction)
                {
                    return(false);
                }

                CtfChallangeModel invalidModelChallenge = _ctfOptions.CtfChallanges
                                                          .Where(x => x.Type == CtfChallengeTypes.InvalidModel)
                                                          .Single();

                _httpContextAccessor.HttpContext.Response.Cookies.Append(invalidModelChallenge.FlagKey, invalidModelChallenge.Flag);
            }

            if (_ctfOptions.CtfChallengeOptions.FreeCredit)
            {
                if (transactionTable.Amount < 0)
                {
                    if (transactionTable.ReceiverId == SecureBankConstants.CREDIT_USERNAME)
                    {
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (transactionTable.Amount < 0)
                {
                    return(false);
                }
            }

            if (_ctfOptions.CtfChallengeOptions.ExceptionHandlingTransactionCreate)
            {
                if (transactionTable.Id != 0)
                {
                    TransactionDBModel transaction = _transactionDAO.Get(transactionTable.Id);
                    if (transaction != null)
                    {
                        try
                        {
                            base.Create(transactionTable);
                        }
                        catch (Exception ex)
                        {
                            CtfChallangeModel exceptionHandlingChallange = _ctfOptions.CtfChallanges
                                                                           .Where(x => x.Type == CtfChallengeTypes.ExceptionHandling)
                                                                           .Single();

                            throw new Exception(exceptionHandlingChallange.Flag, ex);
                        }
                    }
                    else
                    {
                        transactionTable.Id = 0;
                    }
                }
            }

            return(base.Create(transactionTable));
        }
示例#18
0
 public virtual bool Create(TransactionDBModel transaction)
 {
     return(_transactionDAO.Add(transaction));
 }