public IHttpActionResult AddReviewComment(AddCommentParameters commentParams) { if (ModelState.IsValid) { var productreview = _repository.Reviews.FirstOrDefault(r => r.ReviewId == commentParams.Id); if (productreview == null) { return(NotFound()); } try { var reviewComment = new ReviewComment { AuthorId = UserHelper.CustomerSession.CustomerId, AuthorLocation = commentParams.AuthorLocation, AuthorName = commentParams.AuthorName, Comment = commentParams.Comment, ReviewId = productreview.ReviewId, ReviewCommentId = Guid.NewGuid().ToString(), Status = (int)ReviewStatus.Pending }; productreview.ReviewComments.Add(reviewComment); _repository.Update(productreview); _repository.UnitOfWork.Commit(); return(Ok(new MReviewComment { Comment = reviewComment.Comment, CreatedDateTime = reviewComment.Created, Id = reviewComment.ReviewCommentId, Reviewer = new MReviewer { Address = reviewComment.AuthorLocation, Id = reviewComment.AuthorId, NickName = reviewComment.AuthorName } })); } catch { return(BadRequest("Error while saving data to database.".Localize())); } } return(BadRequest()); }
public async Task <ActionResult <GameViewModel> > Add([FromQuery] AddCommentParameters parameters, CancellationToken cancellationToken) { var result = await _commentService.AddComment(parameters.GameId, new Core.Entties.Game.Comment(Guid.NewGuid().ToString("N"), parameters.Content, User.GetUserName(), DateTime.UtcNow, parameters.Rating.Value), cancellationToken); return(Ok(GameViewModel.Create(result))); }