public async Task <IActionResult> RetractAmount(CustomerVoucher customerVoucher) { var model = await _context.CustomerVouchers.Include(x => x.Customer) .Include(x => x.MerchantVoucher) .FirstOrDefaultAsync(m => m.Id == customerVoucher.Id); if (ModelState.IsValid) { var currentVoucher = _context.CustomerVouchers.FirstOrDefault(x => customerVoucher.Id == x.Id); if (customerVoucher != null && currentVoucher != null) { if (currentVoucher.Price < customerVoucher.Price || customerVoucher.Price < 0) { ModelState.AddModelError(String.Empty, "Bedrag kan niet hoger zijn dan huidige waarde."); return(View("Details", model)); } var newPrice = currentVoucher.Price - customerVoucher.Price; _voucherService.UpdatePrice(customerVoucher.Id, newPrice); return(RedirectToAction("Details", "CustomerVoucher", new { id = customerVoucher.Id })); } } return(View("Details", model)); }