Exemplo 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
            });
        }
Exemplo n.º 2
0
        public WebAPI.DTO.IPagedResponse <FavoriteDTO> GetFavorites(int userId, int page, SortState sortOrder, bool isPagedRequestNeeded)
        {
            int pageSize       = 8;
            var favorites      = favoriteRepository.GetAllFavouritesOfByUserId(userId);
            var count          = favorites.Count();
            var pageNumber     = (int)Math.Ceiling(count / (double)pageSize);
            var favoriteSerial = mapper.Map <IEnumerable <FavoriteDTO> >(favorites.Where(s => s.ContentType == ContentType.Serial).Select(i => (_serialRepository.GetSerialById(i.ContentId))));
            var favoriteMovie  = mapper.Map <IEnumerable <FavoriteDTO> >(favorites.Where(s => s.ContentType == ContentType.Movie).Select(i => (_movieRepository.GetMovieById(i.ContentId))));

            foreach (var item in favoriteMovie)
            {
                item.ContentType = ContentType.Movie;
            }
            IEnumerable <FavoriteDTO> union = favoriteSerial.Union(favoriteMovie);

            union = sortOrder switch
            {
                SortState.NameDesc => union.OrderByDescending(s => s.Name),
                SortState.RatingAsc => union.OrderBy(s => s.Rating),
                SortState.RatingDesc => union.OrderByDescending(s => s.Rating),
                SortState.YearAsc => union.OrderBy(s => s.Year),
                SortState.YearDesc => union.OrderByDescending(s => s.Year),
                _ => union.OrderBy(s => s.Name),
            };
            List <FavoriteDTO> items;

            if (isPagedRequestNeeded)
            {
                items = union.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            }
            else
            {
                items = union.ToList();
            }

            WebAPI.DTO.IPagedResponse <FavoriteDTO> pagedResponse = new WebAPI.DTO.IPagedResponse <FavoriteDTO>
            {
                PageNumber = pageNumber,
                PageSize   = pageSize,
                TotalCount = count,
                Data       = items
            };
            return(pagedResponse);
        }