Пример #1
0
        public ReviewResponseInfoDto SendReviewResponse(ReviewResponseCreateDto reviewResponseCreateDto)
        {
            ReviewRequest request = _context
                                    .ReviewRequests
                                    .Include(s => s.ProjectInfo)
                                    .ThenInclude(p => p.Skills)
                                    .Include(s => s.User)
                                    .FirstOrDefault(r => r.Id == reviewResponseCreateDto.ReviewRequestId);

            if (request == null)
            {
                throw RecademyException.ReviewRequestNotFound(reviewResponseCreateDto.ReviewRequestId);
            }

            if (request.State == ProjectState.Completed || request.State == ProjectState.Abandoned)
            {
                throw new RecademyException("Failed to send review. It is already closed.");
            }

            var newReview = new ReviewResponse
            {
                ReviewRequestId  = reviewResponseCreateDto.ReviewRequestId,
                Description      = reviewResponseCreateDto.ReviewText,
                ReviewerId       = reviewResponseCreateDto.UserId,
                CreationTime     = DateTime.UtcNow,
                ReviewConclusion = reviewResponseCreateDto.ReviewConclusion
            };

            request.State = ProjectState.Reviewed;
            _context.ReviewResponses.Add(newReview);
            _context.SaveChanges();

            newReview.ReviewRequest = request;
            return(new ReviewResponseInfoDto(newReview));
        }
Пример #2
0
        public void CreateReviewResponseUpvote(int reviewId, int userId)
        {
            ReviewResponse review = _context.ReviewResponses.Find(reviewId);

            if (review == null)
            {
                throw RecademyException.ReviewRequestNotFound(reviewId);
            }

            if (review.ReviewerId == userId)
            {
                throw new RecademyException("Try to upvote self review response");
            }

            _context.ReviewResponseUpvotes.Add(new ReviewResponseUpvote {
                ReviewResponseId = reviewId, UserId = userId
            });
            _context.SaveChanges();
        }
Пример #3
0
 public ReviewRequest Get(int id)
 {
     return(_context.ReviewRequests.Find(id) ?? throw RecademyException.ReviewRequestNotFound(id));
 }