public async Task<IActionResult> DeletePackage(int id) { try { var toDel = new TelecomPackage { ID = id }; DbContext.TelePackages.Attach(toDel); DbContext.TelePackages.Remove(toDel); await DbContext.SaveChangesAsync(); return RedirectToAction(nameof(HomeController.Index), "Home"); } catch { // 416 - 无效的请求值 return new HttpStatusCodeResult(416); } }
public async Task<IActionResult> EditPackage(TelecomPackage model) { if (ModelState.IsValid) { try { DbContext.TelePackages.Update(model); await DbContext.SaveChangesAsync(); return RedirectToAction(nameof(HomeController.Index), "Home"); } catch { // 416 - 无效的请求值 return new HttpStatusCodeResult(416); } } return View(model); }