示例#1
0
        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));
        }
示例#2
0
        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));
        }