public bool PutPerson(Person person) { if (!databasePlaceholder.Update(person)) { throw new HttpResponseException(HttpStatusCode.NotFound); } return true; }
public HttpResponseMessage PostPerson(Person person) { person = databasePlaceholder.Add(person); string apiName = App_Start.WebApiConfig.DEFAULT_ROUTE_NAME; var response = this.Request.CreateResponse<Person>(HttpStatusCode.Created, person); string uri = Url.Link(apiName, new { id = person.Id }); response.Headers.Location = new Uri(uri); return response; }
public Person Add(Person person) { if (person == null) { throw new ArgumentNullException("person"); } person.Id = _fakeDatabaseID++; _people.Add(person); return person; }
public bool Update(Person person) { if (person == null) { throw new ArgumentNullException("person"); } int index = _people.FindIndex(p => p.Id == person.Id); if (index == -1) { return false; } _people.RemoveAt(index); _people.Add(person); return true; }