public IHttpActionResult Post([FromBody] InventoryAdd newItem) { if (Request.GetRouteData().Values["id"] != null) { return(BadRequest("Invalid request URI")); } if (newItem == null) { return(BadRequest("Must send an entity body with the request")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var addedItem = m.InventoryAdd(newItem); if (addedItem == null) { return(BadRequest("Cannot add the object")); } // HTTP 201 var uri = Url.Link("DefaultApi", new { id = addedItem.Id }); return(Created(uri, addedItem)); }
public InventoryBase InventoryAdd(InventoryAdd newItem) { if (newItem == null) { return(null); } var addedItem = ds.Inventory.Add(Mapper.Map <Inventory>(newItem)); ds.SaveChanges(); return((addedItem == null) ? null : Mapper.Map <InventoryBase>(addedItem)); }