public async Task <IHttpActionResult> PutPerson(int id, PersonDetailDTO 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)); }
public override object BuildDetail(EntityDTO dto) { PersonDetailDTO detail = new PersonDetailDTO(); detail.Title = dto.Name; detail.Email = dto.RenderHTML(GlobalStringResource.Email, RenderOption.Break); detail.Contact = dto.RenderHTML(GlobalStringResource.Contact, RenderOption.Break); return(detail); }
public static async Task <IHttpActionResult> Put(PersonDetailDTO person) { try { await client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, person.Id), person); return(new OkResult(new HttpRequestMessage())); } catch (Exception) { return(new NotFoundResult(new HttpRequestMessage())); } }
//For person public static async Task <IHttpActionResult> Post(PersonDetailDTO person) { try { await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, person.Id)); return(new BadRequestResult(new HttpRequestMessage())); } catch (DocumentClientException de) { if (de.StatusCode == HttpStatusCode.NotFound) { await client.CreateDocumentAsync( UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId), person); return(new OkResult(new HttpRequestMessage())); } throw; } }