예제 #1
0
        public bool PutPerson(Person person)
        {
            if (!databasePlaceholder.Update(person))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return true;
        }
예제 #2
0
 public HttpResponseMessage PostPerson(Person person)
 {
     person = databasePlaceholder.Add(person);
     string apiName = 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;
 }
예제 #3
0
 public Person Add(Person person)
 {
     if (person == null)
     {
         throw new ArgumentNullException("person");
     }
     person.Id = _fakeDatabaseID++;
     _people.Add(person);
     return person;
 }
예제 #4
0
 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;
 }