public IHttpActionResult SearchEmployee(int id) { var employee = OfficeEmployee.GetEmployeeById(id); if (employee == null) { return(NotFound()); } else { return(Ok(employee)); } }
public void Put(int id, [FromBody] OfficeEmployee officeEmployee) { using (EmployeeServiceEntities entities = new EmployeeServiceEntities()) { var entity = entities.OfficeEmployees.FirstOrDefault(e => e.empid == id); entity.empfirstName = officeEmployee.empfirstName; entity.empLastName = officeEmployee.empLastName; entity.empSalary = officeEmployee.empSalary; entities.SaveChanges(); } }
// [ActionFilterDemo] public HttpResponseMessage Search(int id) { var employee = OfficeEmployee.GetEmployeeById(id); if (employee == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, new Exception("No Employee Available"))); } else { return(Request.CreateResponse(HttpStatusCode.OK, employee)); } }
public IHttpActionResult PutComplex(int id, OfficeEmployee officeEmployee) { var empResult = OfficeEmployee.GetEmployeeById(id); if (empResult == null) { return(NotFound()); } else { empResult.Name = officeEmployee.Name; empResult.Salary = officeEmployee.Salary; return(Ok(empResult)); } }
public HttpResponseMessage Post([FromBody] OfficeEmployee officeEmployee) { try { using (EmployeeServiceEntities entities = new EmployeeServiceEntities()) { entities.OfficeEmployees.Add(officeEmployee); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, officeEmployee); message.Headers.Location = new Uri(Request.RequestUri + officeEmployee.empid.ToString()); return(message); } }catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public OfficeEmployee FindEmployeeById(int id) { return(OfficeEmployee.GetEmployeeById(id)); }
public List <OfficeEmployee> GetAllEMployees() { var employees = OfficeEmployee.GetEmployeeDetails(); return(employees); }
public string Post(OfficeEmployee officeEmployee) { OfficeEmployee.AddEmployee(officeEmployee); return("Employee added sucessfully"); }
public IHttpActionResult Put(int id, string name) { OfficeEmployee.GetEmployeeById(id).Name = name; return(Ok(name)); }
public List <OfficeEmployee> GetAllEmployees() { return(OfficeEmployee.GetEmployeeDetails()); }
public EmployeeController() { OfficeEmployee.GetEmployeeDetails(); }