// PUT: api/PersonService/5 public async Task<HttpResponseMessage> Put(string id, Person person) { Guid key = Guid.Parse(id); if (!ModelState.IsValid) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } if (key != person.Id) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } person.ObjectState = ObjectState.Modified; _personBukService.Update(person); try { await _unitOfWorkAsync.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(key)) { return new HttpResponseMessage(HttpStatusCode.NotFound); } throw; } return new HttpResponseMessage(HttpStatusCode.OK); }
// POST: api/PersonService public async Task<HttpResponseMessage> Post(Person person) { if (!ModelState.IsValid) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } person.ObjectState = ObjectState.Added; _personBukService.Insert(person); try { await _unitOfWorkAsync.SaveChangesAsync(); } catch (DbUpdateException) { if (PersonExists(person.Id)) { return new HttpResponseMessage(HttpStatusCode.Conflict); } throw; } return new HttpResponseMessage(HttpStatusCode.Created); }