public ActionResult AddEmployee(SharedClasses.Person.Employee employee) { if (!Request.IsAjaxRequest()) { Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; return(Content("Sorry, this method can't be called only from AJAX.")); } try { if (ModelState.IsValid) { int result = SharedClasses.Person.Employee.AddEmployee(employee); if (result > 0) { return(Content("Record added successfully !")); } else { return(Content("Failed to add record !")); } } else { StringBuilder strB = new StringBuilder(500); foreach (ModelState modelState in ModelState.Values) { foreach (ModelError error in modelState.Errors) { strB.Append(error.ErrorMessage + "<br/>"); } } Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; return(Content(strB.ToString())); } } catch (Exception ee) { Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; return(Content("Sorry, an error occured." + ee.Message)); } }
public ActionResult EditEmployee(int id) { SharedClasses.Person.Employee emp = SharedClasses.Person.Employee.GetEmployees(id).First(); return(PartialView("_EditEmployee", emp)); }