Exemplo n.º 1
0
        public async Task <ActionResult <CheckingCard> > PutChangePinChecking()
        {
            string body;

            using (var stream = new StreamReader(HttpContext.Request.Body))
            {
                body = await stream.ReadToEndAsync();
            }
            var    myObject = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(body);
            string cardNum  = myObject["cardNum"];
            string oldPin   = myObject["oldPin"];
            string newPin   = myObject["newPin"];

            if (!IsAuthenticated(cardNum))
            {
                return(Unauthorized());
            }
            try
            {
                Card card = _context.Card.FirstOrDefault(c => c.CardNum == cardNum);
                if (card == null)
                {
                    return(new OkObjectResult(new { Ok = false, Allowed = false, Errors = new[] { "Card doesn't exist" } }));
                }
                else
                {
                    card.Pin = ComputeSha256Hash(newPin);
                    _context.SaveChanges();
                    return(new OkObjectResult(new { Ok = true, Allowed = true }));
                }
            }
            catch (ArgumentNullException)
            {
                return(Unauthorized());
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            _optionsBuilder = new DbContextOptionsBuilder <BankServerContext>();
            _optionsBuilder.UseSqlServer("Server=MICHAEL-PC\\SQLEXPRESS;Database=bankDB_6;Trusted_Connection=True;MultipleActiveResultSets=true");

            using (var context = new BankServerContext(_optionsBuilder.Options))
            {
                User user = GetUser(context);
                if (user == null)
                {
                    return;
                }

                Card card = GetCard(user, context);

                context.Card.Add(card);
                context.SaveChanges();
            }
        }