public IHttpActionResult Post([FromBody] TenantAdd 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.TenantAdd(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 TenantBase TenantAdd(TenantAdd newItem) { if (newItem == null) { return(null); } var addedItem = ds.Tenants.Add(Mapper.Map <Tenant>(newItem)); ds.SaveChanges(); return((addedItem == null) ? null : Mapper.Map <TenantBase>(addedItem)); }