public HttpResponseMessage Create(Person person) { if (person == null) { return this.Request.CreateErrorResponse(HttpStatusCode.NoContent, "Invalid object!"); } using (var dbContext = new PersonContext()) { dbContext.Persons.Add(person); dbContext.SaveChanges(); } return this.Request.CreateResponse(HttpStatusCode.OK, person); }
public HttpResponseMessage Update(Person person) { if (person == null) { return this.Request.CreateErrorResponse(HttpStatusCode.NoContent, "requested person is invalid!"); } using (var dbContext = new PersonContext()) { var personToUpdate = dbContext.Persons.SingleOrDefault(p => p.Id == person.Id); if (personToUpdate == null) { return this.Request.CreateErrorResponse(HttpStatusCode.NotFound, "requested person not found!"); } Mapper.CreateMap<Person, Person>(); Mapper.Map(person, personToUpdate); dbContext.SaveChanges(); return this.Request.CreateResponse(HttpStatusCode.OK, personToUpdate); } }