private async Task <IHttpActionResult> Save(RelationshipFieldDTO relationshipFieldDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var isNew = relationshipFieldDTO.RelationshipFieldId == Guid.Empty; RelationshipField relationshipField; if (isNew) { relationshipField = new RelationshipField(); DbContext.Entry(relationshipField).State = EntityState.Added; } else { relationshipField = await DbContext.RelationshipFields.SingleOrDefaultAsync(o => o.RelationshipFieldId == relationshipFieldDTO.RelationshipFieldId); if (relationshipField == null) { return(NotFound()); } DbContext.Entry(relationshipField).State = EntityState.Modified; } ModelFactory.Hydrate(relationshipField, relationshipFieldDTO); await DbContext.SaveChangesAsync(); return(await Get(relationshipField.RelationshipFieldId)); }
public async Task <IHttpActionResult> Update(Guid relationshipFieldId, [FromBody] RelationshipFieldDTO relationshipFieldDTO) { if (relationshipFieldDTO.RelationshipFieldId != relationshipFieldId) { return(BadRequest("Id mismatch")); } return(await Save(relationshipFieldDTO)); }
public async Task <IHttpActionResult> Insert([FromBody] RelationshipFieldDTO relationshipFieldDTO) { if (relationshipFieldDTO.RelationshipFieldId != Guid.Empty) { return(BadRequest("Invalid RelationshipFieldId")); } return(await Save(relationshipFieldDTO)); }