コード例 #1
0
 public ActionResult AddOrEdit(Employee emp)
 {
     using (MvcCRUDDBContext db = new MvcCRUDDBContext())
     {
         if (emp.EmployeeId == 0)
         {
             db.Employee.Add(emp);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }));
         }
         else
         {
             db.Entry(emp).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }));
         }
     }
 }
コード例 #2
0
 public ActionResult Delete(int id)
 {
     using (MvcCRUDDBContext db = new MvcCRUDDBContext())
     {
         Employee emp = db.Employee.Where(x => x.EmployeeId == id).FirstOrDefault <Employee>();
         db.Employee.Remove(emp);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }));
     }
 }