Exemplo n.º 1
0
        public async Task<IHttpActionResult> PutPerson(int id, Person person)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != person.Id)
            {
                return BadRequest();
            }

            db.Entry(person).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 2
0
 public Person PostPerson(Person person)
 {
     var newPerson = personRepository.AddPerson(person);
     if(newPerson != null)
     {
         return newPerson;
     }
     throw  new HttpResponseException(HttpStatusCode.InternalServerError);
 }
Exemplo n.º 3
0
 public Person Create(PersonAddOptions options)
 {
     var entity = new Person
     {
         Id = _nextId++,
         First = options.First,
         Last = options.Last
     };
     _people.Add(entity);
     JsonFileToList<Person>.Write(_filename, _people);
     return entity;
 }
Exemplo n.º 4
0
        public async Task<IHttpActionResult> PostPerson(Person person)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.People.Add(person);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = person.Id }, person);
        }