Exemple #1
0
 public HttpResponseMessage PostPerson(Person person)
 {
     person = databasePlaceholder.Add(person);
     string apiName = WebApiConfig.DEFAULT_ROUTE_NAME;
     //this.Request.SetConfiguration(new HttpConfiguration());
     var response =
         this.Request.CreateResponse<Person>(HttpStatusCode.Created, person);
     string uri = Url.Link(apiName, new { id = person.id, controller = "person" });
     response.Headers.Location = new Uri(uri);
     return response;
 }
Exemple #2
0
        public bool PutPerson(Person person)
        {
            if (!databasePlaceholder.Update(person))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return true;
        }
 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;
 }