Hi
I have below code. when i type in Url - http://localhost:40991/api/Employees/DeleteEmployee?id=1
It is going in public HttpResponseMessage GetEmployee(int id) . Why so
- public class EmployeesController : ApiController
- {
- private PMDbEntities db = new PMDbEntities();
-
- public IHttpActionResult GetEmployees()
- {
- try
- {
- var results = (from d in db.Employees
- join f in db.Departments
- on d.DepartmentId equals f.ID
- select new
- {
- Id = d.ID,
- Name = d.Name,
- Department = f.Description
- }).ToList();
- if (results == null)
- {
- return NotFound();
- }
- return Ok(results);
- }
- catch (Exception)
- {
- return BadRequest();
- }
- }
- [ResponseType(typeof(Employee))]
- public HttpResponseMessage GetEmployee(int id)
- {
- Employee employee = db.Employees.Find(id);
- if (employee == null)
- {
- return Request.CreateErrorResponse(HttpStatusCode.NotFound,"Employee Code : " + id + "not found");
- }
-
- return Request.CreateResponse(HttpStatusCode.OK);
- }
-
-
- public IHttpActionResult DeleteEmployee(int id)
- {
- try
- {
- Employee employee = db.Employees.Find(id);
- if (employee == null)
- {
- return Content(HttpStatusCode.NotFound, "Employee not found");
- }
- else
- {
- db.Employees.Remove(employee);
- db.SaveChanges();
- return Ok();
-
- }
- }
- catch (Exception ex)
- {
- return BadRequest("Error Encountered : " + ex);
- }
- }
- }
Thanks