public ActionResult DeleteConfirmed(int id) { cow cow = db.cow.Find(id); db.cow.Remove(cow); db.SaveChanges(); return(RedirectToAction("Index")); }
// // GET: /cow/Edit/5 public ActionResult Edit(int id = 0) { cow cow = db.cow.Find(id); if (cow == null) { return(HttpNotFound()); } return(View(cow)); }
public ActionResult Edit(cow cow) { if (ModelState.IsValid) { var item = db.cow.AsNoTracking().SingleOrDefault(g => g.cowId == cow.cowId); if (item != null && item.id != cow.id) { ViewBag.error = "奶牛编号重复,请修改"; return(View(cow)); } db.Entry(cow).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cow)); }