Пример #1
0
        /// <summary>
        /// Creates the ViewModel for the game detail page
        /// </summary>
        /// <param name="id">ID of the game</param>
        /// <param name="userId">User ID for checking if the user is following this game (default null if not authenticated)</param>
        /// <returns>The GameDetailViewModel</returns>
        public async Task <GameDetailViewModel> Detail(int id, string userId = null)
        {
            Game game = await _gameRepository.AddIfNotExist(id);

            //Check when the user is authenticated if he/she is following this game
            bool currentUserIsFollowing = game.GameUsers != null && game.GameUsers.Any(x => x.UserId == userId && x.Following);

            return(new GameDetailViewModel()
            {
                Id = game.Id,
                Name = game.Name,
                Cover = ImageHelper.GetImageUrl(game.Cover.Id, ImageSize.CoverBig),
                FirstReleaseDate = game.FirstReleaseDate.ToShortDateString(),
                Rating = game.Rating,
                Genres = game.Genres.Select(g => g.Name),
                Platforms = game.GamePlatforms,
                Developers = game.GameCompanies.Where(c => c.Role == CompanyRole.Developer).Select(c => c.Company.Name),
                Publishers = game.GameCompanies.Where(c => c.Role == CompanyRole.Publisher).Select(c => c.Company.Name),
                Screenshots = game.Screenshots.Select(s => ImageHelper.GetImageUrl(s.Id)),
                Summary = game.Summary,
                CurrentUserIsFollowing = currentUserIsFollowing
            });
        }