public HttpResponseMessage Return_Employee(int id) { employees a = new employees() { FirstName = "Eduyar", LastName = "gggg", Salary = 554, Gender = "Male", Id = 7 }; try { Employee_bll employeeRepository = new Employee_bll(_connection); var reg = employeeRepository.RetornaEmployee(id); } catch (Exception ex) { a.Erro = ex.ToString(); } if (a != null) { return(Request.CreateResponse(HttpStatusCode.OK, a)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id " + id.ToString() + " not found!")); } }
// PUT api/values/5 public HttpResponseMessage Put(int id, [FromBody] employees employee) { try { Employee_bll employeeRepository = new Employee_bll(_connection); Exception ex = employeeRepository.UpdateEmployee(id, employee); var message = Request.CreateResponse(HttpStatusCode.OK, employee); message.Headers.Location = new Uri(Request.RequestUri + employee.Id.ToString()); return(message); } catch { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id " + id.ToString() + " not found!")); } }
// POST api/values public HttpResponseMessage Post([FromBody] employees employee) { try { Employee_bll employeeRepository = new Employee_bll(_connection); Exception ex = employeeRepository.SaveEmployee(employee); var message = Request.CreateResponse(HttpStatusCode.Created, employee); message.Headers.Location = new Uri(Request.RequestUri + employee.Id.ToString()); return(message); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
// DELETE api/values/5 public HttpResponseMessage Delete(int id) { Employee_bll employeeRepository = new Employee_bll(_connection); var reg = employeeRepository.RetornaEmployee(id); if (reg != null) { employeeRepository.DeleteEmployee(id); return(Request.CreateResponse(HttpStatusCode.OK, "Employee with id " + id.ToString() + " was deleted!")); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id " + id.ToString() + " not found!")); } }
public HttpResponseMessage Lista_Employees(string gender = "All") { Employee_bll employeeRepository = new Employee_bll(_connection); IEnumerable <employees> Lista = employeeRepository.ListaEmployee().ToList(); switch (gender.ToLower()) { case "all": return(Request.CreateResponse(HttpStatusCode.OK, Lista)); case "male": return(Request.CreateResponse(HttpStatusCode.OK, Lista.Where(c => c.Gender.ToLower() == "male"))); case "female": return(Request.CreateResponse(HttpStatusCode.OK, Lista.Where(c => c.Gender.ToLower() == "female"))); default: return(Request.CreateResponse(HttpStatusCode.BadRequest, "Value for gender must be All, Male or Female. " + gender + " is invalid.")); } }