// DELETE: api/Comments/5 public async Task <string> Delete(int id) { var success = await CommentGenericFacade.DeleteAsync(id); if (!success) { throw new HttpResponseException(HttpStatusCode.NotFound); } return($"Deleted Comment with id: {id}"); }
// GET: api/Comments/2 public async Task <CommentDto> Get(int id) { var comment = await CommentGenericFacade.GetAsync(id); if (comment == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(comment); }
// PUT: api/Comments/5 public async Task <string> Put(int id, CommentDto entity) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } await CommentGenericFacade.UpdateAsync(entity); return($"Updated Comment with id: {id}"); }
public async Task <IEnumerable <CommentDto> > GetPostComments(int postId) { var post = await PostGenericFacade.GetAsync(postId); if (post == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var comments = await CommentGenericFacade.GetPostCommentsAsync(postId); return(comments); }
// POST: api/Comments public async Task <string> Post(CommentDto entity) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var commentId = await CommentGenericFacade.CreateAsync(entity); if (commentId.Equals(0)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } return($"Created Comment with id: {commentId}"); }
public async Task <ActionResult> AddComment(PostListModel model) { try { var newComment = new CommentDto() { Text = model.NewCommentText, PostedAt = DateTime.Now.ToUniversalTime(), StayAnonymous = model.StayAnonymous, UserId = model.AuthenticatedUser.Id, PostId = model.PostId }; await CommentGenericFacade.CreateAsync(newComment); return(RedirectToAction("Index")); } catch { return(RedirectToAction("Index")); } }