示例#1
0
        public IHttpActionResult UpdateReply([FromUri] int id, [FromBody] ReplyUpdate reply)
        {
            var service = CreateReplyService();

            if (service.UpdateReply(id, reply))
            {
                return(Ok("Reply Updated"));
            }
            return(InternalServerError());
        }
        public bool UpdateReply(ReplyUpdate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Replies.Single(e => e.Id == model.Id);

                entity.Text = model.Text;

                return(ctx.SaveChanges() == 1);
            }
        }
示例#3
0
        public IHttpActionResult Put(ReplyUpdate reply)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateReplyService();

            if (!service.UpdateReply(reply))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
示例#4
0
        // Put -- Update Reply by Id
        public bool UpdateReply(int id, ReplyUpdate reply)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Replies.Single(e => e.Id == id);

                //Make sure only original commenter can update comment
                if (entity.CommenterId != _userId)
                {
                    return(false);
                }

                entity.Text = reply.CommentText;

                return(ctx.SaveChanges() == 1);
            }
        }