Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            cow cow = db.cow.Find(id);

            db.cow.Remove(cow);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        //
        // GET: /cow/Edit/5

        public ActionResult Edit(int id = 0)
        {
            cow cow = db.cow.Find(id);

            if (cow == null)
            {
                return(HttpNotFound());
            }
            return(View(cow));
        }
Exemplo n.º 3
0
 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));
 }