Ejemplo n.º 1
0
        public async Task <IActionResult> Balance(string cardNumber)
        {
            Card card = await _context.Cards.FirstOrDefaultAsync(c => c.CardNumber == cardNumber);

            if (card != null)
            {
                Card cardInfo = new Card
                {
                    CardNumber = cardNumber,
                    Balance    = card.Balance,
                };

                Operation operation = new Operation
                {
                    CardNumber = cardNumber,
                    Type       = OperationType.BALANCE,
                    Timestamp  = DateTime.UtcNow,
                };

                _context.Operations.Add(operation);

                await _context.SaveChangesAsync();

                return(View(cardInfo));
            }

            return(RedirectToAction("ErrorRedirect", "Home", new { prevUrl = "Index", errMessage = " " }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Pin(string cardNumber, string pin)
        {
            if (String.IsNullOrEmpty(cardNumber) || String.IsNullOrEmpty(pin))
            {
                return(ErrorRedirect());
            }

            Card card = await _context.Cards.FirstAsync(c => c.CardNumber == cardNumber);

            if (pin == card.PIN && !card.Blocked)
            {
                return(RedirectToAction("Index", "Operation", new { cardNumber }));
            }

            if (pin != card.PIN && !card.Blocked)
            {
                card.FailedLogins++;

                if (card.FailedLogins > 3)
                {
                    card.Blocked = true;
                }

                await _context.SaveChangesAsync();
            }

            return(ErrorRedirect());
        }