public IActionResult AddComment([FromHeader(Name = "CommunicationKey")] string key, CommentCreateDto commentDto, [FromQuery] int userID) { if (productRepository.GetProductByID(commentDto.ProductID) == null) { return(StatusCode(StatusCodes.Status400BadRequest, "Product with given ID does not exist")); } var comment = mapper.Map <Comments>(commentDto); var product = productRepository.GetProductByID(comment.ProductID); var sellerID = product.SellerID; if (!commentRepository.CheckDoIFollowSeller(userID, sellerID)) { return(StatusCode(StatusCodes.Status400BadRequest, String.Format("You are not following user with id {0} and you can not comment his products", sellerID))); } comment.UserID = userID; comment.CommentDate = DateTime.Today; try { commentRepository.AddComment(comment); commentRepository.SaveChanges(); logger.Log(LogLevel.Information, contextAccessor.HttpContext.TraceIdentifier, "", String.Format("Successfully created new comment with ID {0} in database", comment.CommentID), null); return(StatusCode(StatusCodes.Status201Created, "Comment is successfully created!")); } catch (Exception ex) { logger.Log(LogLevel.Error, contextAccessor.HttpContext.TraceIdentifier, "", String.Format("Comment with ID {0} not created, message: {1}", comment.CommentID, ex.Message), null); return(StatusCode(StatusCodes.Status500InternalServerError, "Create error " + ex.Message)); } }