Example #1
0
 public JsonResult Delete(int id)
 {
     using (LearningDBEntities db = new LearningDBEntities())
     {
         Employee employee = db.Employees.Find(id);
         if (employee == null)
         {
             return(Json(new { success = false }));
         }
         db.Employees.Remove(employee);
         db.SaveChanges();
         return(Json(new { success = true }));
     }
 }
Example #2
0
 public JsonResult Insert(Employee employee)
 {
     if (employee != null)
     {
         using (LearningDBEntities db = new LearningDBEntities())
         {
             db.Employees.Add(employee);
             db.SaveChanges();
             return(Json(new { success = true }));
         }
     }
     else
     {
         return(Json(new { success = false }));
     }
 }
Example #3
0
 public JsonResult Update(Employee updatedEmployee)
 {
     using (LearningDBEntities db = new LearningDBEntities())
     {
         Employee existingEmployee = db.Employees.Find(updatedEmployee.EmpID);
         if (existingEmployee == null)
         {
             return(Json(new { success = false }));
         }
         else
         {
             existingEmployee.EmpName     = updatedEmployee.EmpName;
             existingEmployee.DeptName    = updatedEmployee.DeptName;
             existingEmployee.Email       = updatedEmployee.Email;
             existingEmployee.Designation = updatedEmployee.Designation;
             db.SaveChanges();
             return(Json(new { success = true }));
         }
     }
 }
Example #4
0
 public void save()
 {
     _db.SaveChanges();
 }