public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } BankAccount = await _context.BankAccount.FindAsync(this.Transaction.BankAccountID); if (BankAccount == null) { return(NotFound()); } var transTo = await _context.BankAccount.FindAsync(this.TransferToAccount.BankAccountID); if (transTo == null) { return(NotFound()); } // validation if (this.BankAccount.Balance < this.Transaction.Amount) { return(Page()); } // source account this.Transaction.TransactionDate = DateTime.Now; this.Transaction.DebitType = DebitType.TransferOut; this.Transaction.PreviousBalance = this.BankAccount.Balance; this.Transaction.NewBalance = this.BankAccount.Balance - this.Transaction.Amount; // destination account Transaction destTrans = new Transaction(); destTrans.BankAccountID = transTo.BankAccountID; destTrans.TransactionDate = DateTime.Now; destTrans.CreditType = CreditType.TransferIn; destTrans.Amount = this.Transaction.Amount; destTrans.PreviousBalance = transTo.Balance; destTrans.NewBalance = transTo.Balance + this.Transaction.Amount; // Update Balance for bank account this.BankAccount.Balance = this.Transaction.NewBalance; transTo.Balance = destTrans.NewBalance; _context.Transaction.Add(Transaction); _context.Transaction.Add(destTrans); if (await TryUpdateModelAsync <BankAccount>(BankAccount)) { if (await TryUpdateModelAsync <BankAccount>(transTo)) { await _context.SaveChangesAsync(); } } return(RedirectToPage("/BankAccounts/Details", new { id = BankAccount.BankAccountID })); }
// To protect from overposting attacks, please 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")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } BankAccount = await _context.BankAccount.FindAsync(this.Transaction.BankAccountID); if (BankAccount == null) { return(NotFound()); } // Deposit this.Transaction.TransactionDate = DateTime.Now; this.Transaction.CreditType = CreditType.Deposit; this.Transaction.PreviousBalance = this.BankAccount.Balance; this.Transaction.NewBalance = this.BankAccount.Balance + this.Transaction.Amount; // Generate Fee transaction Transaction feeTrans = new Transaction(); feeTrans.BankAccountID = this.Transaction.BankAccountID; feeTrans.TransactionDate = DateTime.Now; feeTrans.DebitType = DebitType.Fee; feeTrans.Amount = this.Transaction.Amount * 0.001; feeTrans.PreviousBalance = this.Transaction.NewBalance; feeTrans.NewBalance = this.Transaction.NewBalance - feeTrans.Amount; // Update Balance for bank account this.BankAccount.Balance = feeTrans.NewBalance; if (await TryUpdateModelAsync <BankAccount>(BankAccount)) { _context.Transaction.Add(Transaction); await _context.SaveChangesAsync(); _context.Transaction.Add(feeTrans); await _context.SaveChangesAsync(); } return(RedirectToPage("/BankAccounts/Details", new { id = BankAccount.BankAccountID })); }
// To protect from overposting attacks, please 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")); }
// To protect from overposting attacks, please 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.BankAccount.Add(BankAccount); await _context.SaveChangesAsync(); return(RedirectToPage("/Users/Details", new { id = BankAccount.UserID })); }
public async Task <IActionResult> OnPostAsync(string id) { if (id == null) { return(NotFound()); } User = await _context.User.FindAsync(id); if (User != null) { _context.User.Remove(User); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string id) { if (id == null) { return(NotFound()); } BankAccount = await _context.BankAccount.FindAsync(id); if (BankAccount != null) { _context.BankAccount.Remove(BankAccount); await _context.SaveChangesAsync(); } return(RedirectToPage("/Users/Details", new { id = BankAccount.UserID })); }
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")); }