public HttpResponseMessage AddEmployee(Employee employee) { empContext.Employees.Add(employee); empContext.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, employee, System.Net.Http.Formatting.JsonMediaTypeFormatter.DefaultMediaType); }
public HttpResponseMessage UpdateEmployee( Employee emp) { if(emp==null) { throw new ArgumentNullException("No emp item"); } empContext.Entry(emp).State = EntityState.Modified; empContext.SaveChanges(); //var dbemp = empContext.Employees.ToList(); //int index = dbemp.FindIndex(p => p.EmployeeID == emp.EmployeeID); //if (index == -1) //{ // return Request.CreateResponse(HttpStatusCode.BadRequest, "No emp item"); //} //dbemp.RemoveAt(index); //dbemp.Add(emp); //empContext.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, emp); }