Beispiel #1
0
        public ResultMessage GetById(int id, string currentUserId)
        {
            try
            {
                var itemReview = _unitOfWork.ItemsReviewsRepository.GetById(id);
                // itemReview.Reviews.ToList();
                if (itemReview != null)
                {
                    var result = itemReview.Adapt <ItemReviewDto>();
                    result.Reviews = _ratingManager.GetItemRatings(itemReview.Id, RatingEntityTypesEnum.ItemsForReview);

                    if (!string.IsNullOrEmpty(currentUserId))
                    {
                        result.Reviews.ForEach(c =>
                        {
                            c.isCurrent = c.CreatedBy == currentUserId;
                        });
                    }

                    return(new ResultMessage()
                    {
                        Data = result,
                        Status = HttpStatusCode.OK
                    });
                }

                else
                {
                    return new ResultMessage()
                           {
                               Status    = HttpStatusCode.NotFound,
                               ErrorCode = (int)ItemsReviewsErrorsCodeEnum.ItemsNotFoundError
                           }
                };
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage()
                {
                    ErrorCode = (int)ItemsReviewsErrorsCodeEnum.ItemsGetByIdError,
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }