Esempio n. 1
0
        public UserInfoDTO GetUserInfo(int userId)
        {
            var    userFavourites   = _favoriteRepository.GetAllFavouritesOfByUserId(userId);
            var    userReviews      = _reviewRepository.GetAllReviewsByUserId(userId);
            var    userReviewsCount = userReviews.Count();
            double meanValue        = 0;

            foreach (var item in userReviews)
            {
                meanValue += (item.ActorsRating + item.DirectingRating + item.PlotRating + item.SpectacleRating) / 4;
            }
            var meanValueInt = (int)meanValue / userReviewsCount;

            return(new UserInfoDTO {
                countOfFavourites = userFavourites.Count, meanMark = meanValueInt
            });
        }
Esempio n. 2
0
        public int?getReviewPage(int UserId, int PageNumber, int PageSize, ReviewSortState sortState, string titleName)
        {
            if (titleName == null)
            {
                return(null);
            }
            var reviewsList = _mapper.Map <IEnumerable <Review>, IEnumerable <ReviewDTO> >(_reviewsRepository.GetAllReviewsByUserId(UserId));

            reviewsList = sortQuery(reviewsList, sortState);
            var foundElement = reviewsList.FirstOrDefault(s => s.ReviewTitle.Contains(titleName));

            if (foundElement == null)
            {
                return(null);
            }
            int index = reviewsList.IndexOf(foundElement) + 1;

            if (index <= PageSize)
            {
                return(1);
            }
            var remaining = ((double)index / (double)PageSize);

            return((int)Math.Round(remaining, 0, MidpointRounding.AwayFromZero));
        }