public IHttpActionResult Post([FromBody] AnnouncementAdd 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.AnnouncementAdd(newItem); if (addedItem == null) { return(BadRequest("Cannot add the object")); } var uri = Url.Link("DefaultApi", new { id = addedItem.Id }); return(Created(uri, addedItem)); }
public AnnouncementBase AnnouncementAdd(AnnouncementAdd newItem) { if (newItem == null) { return(null); } var addedItem = ds.Announcements.Add(Mapper.Map <Announcement>(newItem)); ds.SaveChanges(); return((addedItem == null) ? null : Mapper.Map <AnnouncementBase>(addedItem)); }