Esempio n. 1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Transaction).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TransactionExists(Transaction.TransactionId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // DATE OF BIRTH VALIDATION
            var birthYear         = AccountHolder.DateOfBirth.Year;
            var latestAllowedYear = DateTime.Now.Year - 18;

            if (birthYear > latestAllowedYear)
            {
                ModelState.AddModelError("AccountHolder.DateOfBirth", "Account holder must be 18 years or older");
            }

            // SSN VALIDATION
            var  ssn = AccountHolder.SocialSecurityNumber;
            bool ssnAlreadyExists = await _context.AccountHolder.AnyAsync(x => x.SocialSecurityNumber == ssn);

            if (ssnAlreadyExists)
            {
                ModelState.AddModelError("AccountHolder.SocialSecurityNumber", "Account holder with this SSN already exists");
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.AccountHolder.Add(AccountHolder);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            // CHECK BUILT-IN VALIDATION RULES AND RETURN PAGE IF ERRORS FOUND
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // DATE OF BIRTH VALIDATION
            var birthYear         = AccountHolder.DateOfBirth.Year;
            var latestAllowedYear = DateTime.Now.Year - 18;

            if (birthYear > latestAllowedYear)
            {
                ModelState.AddModelError("AccountHolder.DateOfBirth", "Account holder must be 18 years or older");
            }

            // SSN VALIDATION
            var  ssn              = AccountHolder.SocialSecurityNumber;
            var  currentId        = AccountHolder.AccountHolderId;
            bool ssnAlreadyExists = await _context.AccountHolder.AnyAsync(x => x.SocialSecurityNumber == ssn && x.AccountHolderId != currentId);

            if (ssnAlreadyExists)
            {
                ModelState.AddModelError("AccountHolder.SocialSecurityNumber", "Account holder with this SSN already exists");
            }

            // CHECK AGAIN AFTER CUSTOM VALIDATION RULES AND RETURN PAGE IF ERRORS FOUND
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(AccountHolder).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountHolderExists(AccountHolder.AccountHolderId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Transaction.Add(Transaction);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 5
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            // REPOPULATE DROPDOWN IF VALIDATION ERROR OCCURS
            ViewData["AccountHolderId"] = new SelectList(_context.AccountHolder, "AccountHolderId", "FullName");

            // RETURN IF BUILT-IN VALIDATION FAILS
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.BankAccount.Add(BankAccount);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BankAccount = await _context.BankAccount.FindAsync(id);

            if (BankAccount != null)
            {
                _context.BankAccount.Remove(BankAccount);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 7
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AccountHolder = await _context.AccountHolder.FindAsync(id);

            if (AccountHolder != null)
            {
                _context.AccountHolder.Remove(AccountHolder);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 8
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Transaction = await _context.Transaction.FindAsync(id);

            if (Transaction != null)
            {
                _context.Transaction.Remove(Transaction);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 9
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            var account = await _context.AccountHolder.FindAsync(AccountHolder.AccountHolderId);

            account.PlatinumMember = true;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountHolderExists(AccountHolder.AccountHolderId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }