コード例 #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 = 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;
 }
コード例 #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;
 }