Esempio n. 1
0
        public async Task <IActionResult> Put(Transactions model)
        {
            if (ModelState.IsValid)
            {
                Account account = await _context.Accounts.FirstOrDefaultAsync(
                    a => a.User.Email == User.Identity.Name);

                account.Balance      = account.Balance + model.Sum;
                account.Transactions = new List <Models.Transaction>()
                {
                    new Transaction
                    {
                        Sum = model.Sum,
                        ReceiverAccountId = account.BalanceName,
                        SenderAccountId   = "Terminal",
                        Accounts          = account
                    }
                };
                _context.Update(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _context.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                _context.Users.Add(new User
                {
                    Email     = model.Email,
                    Firstname = model.Firstname,
                    Lastname  = model.Lastname,
                    Password  = model.Password,
                    Accounts  = new List <Account>()
                    {
                        new Account
                        {
                            BalanceName   = model.BalanceName,
                            BalanceNumber = RandomString(),
                            Balance       = 0,
                        }
                    }
                });
                await _context.SaveChangesAsync();
                await Authenticate(model.Email);

                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }