public void EditComment(int commentId, CommentBm bindComment) { Comment comment = this.Context.Comments.Find(commentId); comment.Content = bindComment.Content; this.Context.SaveChanges(); }
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(); }
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)); }
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)); }