public async Task <ReviewViewModel> GetReviewViewModelAsync(Guid reviewId, VacancyUser user)
        {
            var review = await _vacancyClient.GetVacancyReviewAsync(reviewId);

            if (review == null)
            {
                throw new NotFoundException($"Unable to find review with id: {reviewId}");
            }

            ValidateReviewStateForViewing(review);

            if (_vacancyClient.VacancyReviewCanBeAssigned(review))
            {
                await _vacancyClient.AssignVacancyReviewAsync(user, review.Id);

                review = await _vacancyClient.GetVacancyReviewAsync(reviewId);
            }

            await EnsureUserIsAssignedAsync(review, user.UserId);

            var vm = await _mapper.Map(review);

            return(vm);
        }
示例#2
0
 public void UpdateReview(ReviewDto review)
 {
     if (_repository.AllEntities().Any(x => x.Id == review.ReviewId))
     {
         if (review.Rating < 0)
         {
             review.Rating = 0;
         }
         if (review.Rating > 10)
         {
             review.Rating = 10;
         }
         _repository.Update(ReviewMapper.Map(review));
         _unitOfWork.SaveChanges();
     }
     else
     {
         throw new Exception($"There is no review with the id {review.ReviewId}");
     }
 }
示例#3
0
 public void AddNewReview(ReviewDto review)
 {
     if (!_repository.AllEntities().Any(x => x.UserId == review.UserId && x.ProductId == review.ProductId))
     {
         if (review.Rating < 0)
         {
             review.Rating = 0;
         }
         if (review.Rating > 10)
         {
             review.Rating = 10;
         }
         _repository.Add(ReviewMapper.Map(review));
         _unitOfWork.SaveChanges();
     }
     else
     {
         throw new Exception("User already reviewed the product!");
     }
 }
示例#4
0
        public async Task <IList <Review> > QueryReview(ReviewFilter filter)
        {
            var requestIDs = new DataTable();

            requestIDs.Columns.Add("Val");

            if (filter.RequestIDs?.Any() ?? false)
            {
                foreach (var id in filter.RequestIDs)
                {
                    requestIDs.Rows.Add(id);
                }
            }

            var param = new DynamicParameters();

            param.Add("RequestIDs", requestIDs.AsTableValuedParameter("dbo.BigIntType"));

            var mapper = new ReviewMapper();

            return((await SqlMapper.QueryAsync(_unitOfWork.Connection,
                                               "QueryReview",
                                               new[]
            {
                typeof(Review),
                typeof(ReviewLineItem)
            },
                                               obj =>
            {
                var review = obj[0] as Review;
                var lineItem = obj[1] as ReviewLineItem;

                return mapper.Map(review, lineItem);
            },
                                               param,
                                               splitOn: "ID,LineItemID",
                                               commandType: CommandType.StoredProcedure,
                                               transaction: _unitOfWork.Transaction)).Distinct().ToList());
        }
示例#5
0
        public async Task <ActionResult <ReviewDTO> > GetReview(Guid id)
        {
            var review = await _bll.Reviews.FirstOrDefaultAsync(id);

            return(Ok(_mapper.Map(review)));
        }