public JsonResult CreateEmployee(Employee employee) { try { if (!ModelState.IsValid) { return Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }); } var addedEmployee = db.Employees.Add(employee); addedEmployee.IsOnBench = true; db.SaveChanges(); return Json(new { Result = "OK", Record = addedEmployee }); } catch (Exception ex) { return Json(new { Result = "ERROR", Message = ex.Message }); } }
public JsonResult UpdateEmployee(Employee employee) { try { if (!ModelState.IsValid) { return Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }); } db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return Json(new { Result = "OK" }); } catch (Exception ex) { return Json(new { Result = "ERROR", Message = ex.Message }); } }