// Create Resource With HTTP Post public HttpResponseMessage Post(int id, Team team) { var maxId = _teams.Max(t => t.Id); team.Id = maxId + 1; _teams.Add(team); // Prepare the Response to Return var response = Request.CreateResponse(HttpStatusCode.Created, team); var uri = Url.Link("DefaultApi", new { id = team.Id }); response.Headers.Location = new System.Uri(uri); return response; }
public HttpResponseMessage Put(int id, Team team) { var index = _teams.ToList().FindIndex(t=>t.Id == id); if (index >= 0) { // overwrite the existing resource _teams[index] = team; // Prepare the Response to return return Request.CreateResponse(HttpStatusCode.NoContent); } else { _teams.Add(team); // Prepare the Response to Return var response = Request.CreateResponse(HttpStatusCode.Created, team); var uri = Url.Link("DefaultApi", new { id = team.Id}); response.Headers.Location = new System.Uri (uri); return response; } }