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); }
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}"); } }
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!"); } }
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()); }
public async Task <ActionResult <ReviewDTO> > GetReview(Guid id) { var review = await _bll.Reviews.FirstOrDefaultAsync(id); return(Ok(_mapper.Map(review))); }