コード例 #1
0
        public IHttpActionResult Post(PostCommentOnPost comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateCommentService();

            if (!service.CommentOnPost(comment))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
コード例 #2
0
        public bool MakeComment(PostCommentOnPost model)
        {
            var entity =
                new Comment()
            {
                UserId    = _userId,
                CommentId = model.CommentId,
                Text      = model.Text,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Comments.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #3
0
        public bool CommentOnPost(PostCommentOnPost model)
        {
            var commentToCreate = new Comment()
            {
                CommentId = model.CommentId,
                Text      = model.Text,
                Author    = model.Author,
                PostId    = model.PostId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Comments.Add(commentToCreate);
                return(ctx.SaveChanges() == 1);
            }
        }