public ActionResult <CommentViewModel> Post([FromBody] Comment comment) { try { bool success = _commentsService.Create(comment); if (success) { return(CreatedAtAction("Get", new Comment { Id = comment.Id }, new CommentViewModel(comment))); } else { return(NotFound()); } } // TODO: Better exception handling, for instance when there is an id conflict return a `Conflict` catch (Exception e) { return(BadRequest(new { status = HttpStatusCode.BadRequest, message = $"{e.Message}: {e.InnerException?.Message}" })); } }
public BroadcastResult Handle(AddCommentCommand command) { _commentsService.Create(command.CreateDto); UpdateCache(command.TargetType, command.TargetId); return(BroadcastResult.Success); }
public BroadcastResult Handle(AddCommentCommand command) { var commentsTarget = command.Context.GetCommentsTarget(); _commentsService.Create(command.CreateDto); UpdateCache(commentsTarget.Type, commentsTarget.EntityId.Value); return(BroadcastResult.Success); }
public HttpResponseMessage CreateComment(string blogId, string postId, HttpRequestMessage request) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); try { ICommentsService commentsService = ObjectFactory.GetInstance <ICommentsService>(); XmlReader reader = XmlReader.Create(request.Content.ReadAsStreamAsync().Result); SyndicationFeed feed = SyndicationFeed.Load(reader); if (feed != null) { SyndicationItem item = feed.Items.FirstOrDefault(); if (item != null) { Comment newComment = new Comment { content = ((TextSyndicationContent)item.Content).Text, published = item.PublishDate, updated = item.LastUpdatedTime }; var author = item.Authors.FirstOrDefault(); if (author != null) { newComment.author = author.Name; newComment.postId = String.Format("posts/{0}", postId); commentsService.Create(newComment); response.StatusCode = HttpStatusCode.Created; response.Headers.Add("Location", String.Format("{0}/blogs/{1}/posts/{2}/{3}", this.serviceURI, blogId, postId, newComment.Id)); } else { response.StatusCode = HttpStatusCode.BadRequest; } } else { response.StatusCode = HttpStatusCode.BadRequest; } } else { response.StatusCode = HttpStatusCode.BadRequest; } } catch (Exception) { response.StatusCode = HttpStatusCode.InternalServerError; } return(response); }
public async Task <IActionResult> Create(string postId, CommentForCreateDto commentForCreateDto) { Comment commentToCreate = _mapper.Map <Comment>(commentForCreateDto); commentToCreate.PostId = postId; commentToCreate.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; commentToCreate.Username = User.FindFirst(ClaimTypes.Name).Value; await _commentsService.Create(commentToCreate); return(Ok()); }
public IActionResult Create([FromBody] Comment comment) { try { _commentsService.Create(comment); } catch (Exception e) { Console.WriteLine(e); return(BadRequest()); } return(Ok(comment)); }
public async Task <IActionResult> Create(CommentView commentView) { try { commentView.UserId = HttpContext.User.Identity.Name; await _commentsService.Create(commentView); return(Ok()); } catch (ArgumentException ex) { return(BadRequest(new { message = ex.Message })); } }
public IActionResult PostComments([FromForm] CommentsDto comments) { try { var result = _commentsService.Create(comments); if (result) { return(RedirectToAction("GetPost")); } return(Ok(new { Message = "Error" })); } catch (DbUpdateConcurrencyException) { return(Ok(new { Message = "Error" })); } }
public JsonResult AddComment(AddCommentViewModel model) { if (ModelState.IsValid) { var commentDto = new UserCommentDto { MovieID = model.MovieID, UserComment = model.UserComment, UserID = HttpContext.User.Identity.GetUserId(), UserName = HttpContext.User.Identity.GetUserName(), CommentRating = 0 }; commentsService.Create(commentDto); return(Json(new { success = true, responseText = "Comment was added." })); } return(Json(new { success = false, responseText = "Error during comment adding." })); }
public Task <CommentItem> Create(CommentCreateContract contract) { return(_service.Create(contract)); }
public void Post([FromBody] CommentPostDTO comment) { User addedBy = usersService.GetCurrentUser(HttpContext); commentsService.Create(comment, addedBy); }
public async Task <ActionResult <Comment> > Create([FromBody] Comment comment) { return(Ok(await _commentsService.Create(comment))); }
public IHttpActionResult PostComment(Comment comment) { var newComment = CommentService.Create(comment, User.Identity); return(Results(newComment)); }