public ActionResult Add(department dpt) { using (DepartmentEntity db = new DepartmentEntity()) { if (dpt.departmentID == 0) { db.departments.Add(dpt); db.SaveChanges(); return(Json(new { success = true, message = "Department added successfully" }, JsonRequestBehavior.AllowGet)); } else { db.Entry(dpt).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Department updated successfully" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult Delete(int id) { using (DepartmentEntity db = new DepartmentEntity()) { department emp = db.departments.Where(x => x.departmentID == id).FirstOrDefault <department>(); db.departments.Remove(emp); db.SaveChanges(); return(Json(new { success = true, message = "Department deleted successfully" }, JsonRequestBehavior.AllowGet)); } }