public async Task <IActionResult> DeleteConfirmed(int id) { PaymentDeleteVM modelVM = new PaymentDeleteVM(_context, id); if (modelVM.Order == null) { // No instance of this PaymentTypeId exists in Order table. OK to erase _context.PaymentType.Remove(modelVM.PaymentType); } else if (ModelState.IsValid) { try { modelVM.PaymentType.IsActive = false; _context.Update(modelVM.PaymentType); } catch (DbUpdateConcurrencyException) { if (!PaymentTypeExists(modelVM.PaymentType.PaymentTypeId)) { return(NotFound()); } else { throw; } } } await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteConfirmed(int id) { PaymentDeleteVM modelVM = new PaymentDeleteVM(_context, id); if (modelVM.Order == null) { // No instance of this PaymentTypeId exists in Order table. OK to erase _context.PaymentType.Remove(modelVM.PaymentType); } else { try { // ?Does modelVM.PaymentType have a User? Check once the ability to create orders is in place modelVM.PaymentType.IsActive = false; _context.Update(modelVM.PaymentType); } catch (DbUpdateConcurrencyException) { if (!PaymentTypeExists(modelVM.PaymentType.PaymentTypeID)) { return(NotFound()); } else { throw; } } } await _context.SaveChangesAsync(); return(RedirectToAction("PaymentTypes", "Manage")); }