public HttpResponseMessage Post(int objectId, ViewModels.DatabaseObjectProperty viewModelObjectProperty) { try { var objectProperty = Mapper.Map <ObjectProperty>(viewModelObjectProperty); _graph.AddProperty(objectId, objectProperty); // Return HTTP 201 Created with Location http://localhost:3500/api/object/4 and object in the body var item = Get(objectId); var response = Request.CreateResponse <ViewModels.DatabaseObject>(HttpStatusCode.Created, item); string uri = Url.Link("GetObjectById", new { objectId = objectId }); response.Headers.Location = new Uri(uri); return(response); } catch (ArgumentException) { // .. or HTTP 409 if dup var resp = new HttpResponseMessage(HttpStatusCode.Conflict) { Content = new StringContent($"Property {viewModelObjectProperty.PropertyType} already exists."), ReasonPhrase = "Duplicate property" }; throw new HttpResponseException(resp); } }
// Return DatabaseObject to make easier for UI to show updated state public ViewModels.DatabaseObject Delete(int objectId, DatabaseObjectPropertyType propertyType) { var viewModelPropertyType = new ViewModels.DatabaseObjectProperty { PropertyType = propertyType }; // Don't care about the value var domainProperty = Mapper.Map <ObjectProperty>(viewModelPropertyType); _graph.RemoveProperty(objectId, domainProperty); return(Get(objectId)); }