Ejemplo n.º 1
0
        public void EditComment(int commentId, CommentBm bindComment)
        {
            Comment comment = this.Context.Comments.Find(commentId);

            comment.Content = bindComment.Content;
            this.Context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void CreateComment(int articleId, CommentBm bindComment)
        {
            Comment comment = Mapper.Instance.Map <CommentBm, Comment>(bindComment);

            comment.Date      = DateTime.Now;
            comment.ArticleId = articleId;
            this.Context.Comments.Add(comment);
            this.Context.SaveChanges();
        }
Ejemplo n.º 3
0
        public IHttpActionResult Post(int id, [FromBody] CommentBm bindComment)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }
            bindComment.AuthorId = this.User.Identity.GetUserId();
            this.service.CreateComment(id, bindComment);

            return(this.StatusCode(HttpStatusCode.Created));
        }
Ejemplo n.º 4
0
        public IHttpActionResult Put(int id, int CommentId, [FromBody] CommentBm bindComment)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }
            if (!this.service.containsComment(CommentId))
            {
                return(this.StatusCode(HttpStatusCode.NotFound));
            }

            string currentAuthorId = this.User.Identity.GetUserId();

            if (!this.service.IsAuthor(id, currentAuthorId, CommentId))
            {
                return(this.StatusCode(HttpStatusCode.Unauthorized));
            }

            this.service.EditComment(CommentId, bindComment);

            return(this.StatusCode(HttpStatusCode.Accepted));
        }