Esempio n. 1
0
        public IHttpActionResult PutComment(int id, CommentModel comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.commentID)
            {
                return(BadRequest());
            }

            db.Entry(comment.ConvertToComment()).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public IHttpActionResult PostComment(CommentModel comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Comment newComment = db.Comments.Add(comment.ConvertToComment());

            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = newComment.CommentID }, newComment));
        }