public async Task <IActionResult> OnPostDebitAsync(Guid id) { try { GiftCard = await _repository.FindGiftCardAsync(id) ?? throw new InvalidOperationException("Gift card not found"); GiftCard.Debit(Amount); await _repository.SaveGiftCardAsync(GiftCard); } catch (InvalidOperationException ex) { Error = ex.Message; } return(RedirectToPage(new { id })); }
public async Task <IActionResult> OnPostDebitAsync(Guid id) { GiftCard = await _repository.FindGiftCardAsync(id) ?? throw new InvalidOperationException("Gift card not found"); if (!ModelState.IsValid) { return(Page()); } try { GiftCard.Debit(Amount); await _repository.SaveGiftCardAsync(GiftCard); return(RedirectToPage(new { id })); } catch (InvalidOperationException ex) { ModelState.AddModelError("", ex.Message); return(Page()); } }