public async Task <IActionResult> OnPostAsync() { var creditid = Credit.CreditId; var username = Credit.Username; Credit = creditdb.GetById(creditid); if (Credit == null) { if (creditid == null || username == null) { return(RedirectToPage(Url.Content("~/NotFound"))); } await Task.Run(() => { Credit = new CreditCard(); Credit.CreditId = creditid; Credit.Username = username; }); creditdb.Add(Credit); await creditdb.CommitAsync(); } else { creditdb.Delete(Credit); await creditdb.CommitAsync(); } StatusMessage = "Your payment method has been updated"; return(RedirectToPage()); }