예제 #1
0
        private void FillGameIndexViewModel(GameIndexViewModel gameIndexViewModel)
        {
            gameIndexViewModel        = gameIndexViewModel ?? new GameIndexViewModel();
            gameIndexViewModel.Filter = gameIndexViewModel.Filter ?? new GamesFilterViewModel();

            var filterModel = Mapper.Map <GamesFilterModel>(gameIndexViewModel.Filter);

            gameIndexViewModel.Pagination = gameIndexViewModel.Pagination ?? new PaginationViewModel();

            var paginationModel = Mapper.Map <PaginationModel>(gameIndexViewModel.Pagination);

            GamesTransferModel transferModel = _gameService.GetGamesByFilter(filterModel, paginationModel);

            gameIndexViewModel.Games      = Mapper.Map <IEnumerable <GameViewModel> >(transferModel.Games);
            gameIndexViewModel.Pagination = Mapper.Map <PaginationViewModel>(transferModel.PaginationModel);

            gameIndexViewModel.Filter.AvailablePlatformTypes =
                Mapper.Map <IEnumerable <PlatformTypeFilterViewModel> >(_platformTypeService.GetAll());
            gameIndexViewModel.Filter.AvailableGenres =
                Mapper.Map <IEnumerable <GenreFilterViewModel> >(_genreService.GetAll());
            gameIndexViewModel.Filter.AvailablePublishers =
                Mapper.Map <IEnumerable <PublisherFilterViewModel> >(_publisherService.GetAll());

            gameIndexViewModel.Filter.Genres        = gameIndexViewModel.Filter.Genres ?? new List <int>();
            gameIndexViewModel.Filter.PlatformTypes = gameIndexViewModel.Filter.PlatformTypes ?? new List <int>();
            gameIndexViewModel.Filter.Publishers    = gameIndexViewModel.Filter.Publishers ?? new List <int>();

            gameIndexViewModel.Filter.SelectedGenres = gameIndexViewModel.Filter.AvailableGenres
                                                       .Where(x => gameIndexViewModel.Filter.Genres.Contains(x.GenreId));
            gameIndexViewModel.Filter.SelectedPlatformTypes = gameIndexViewModel.Filter.AvailablePlatformTypes
                                                              .Where(x => gameIndexViewModel.Filter.PlatformTypes.Contains(x.PlatformTypeId));
            gameIndexViewModel.Filter.SelectedPublishers = gameIndexViewModel.Filter.AvailablePublishers
                                                           .Where(x => gameIndexViewModel.Filter.Publishers.Contains(x.PublisherId));
        }
예제 #2
0
        // GET: Games
        public async Task <IActionResult> Index()
        {
            var model = new GameIndexViewModel();

            //get users
            ApplicationUser user = await GetCurrentUserAsync();

            model.User = user;

            //get post counts
            var PostsCount = await(
                from g in _context.Game
                from p in _context.Post.Where(co => g.GameId == co.GameId).DefaultIfEmpty()
                group new { g, p } by new { g.GameId, g.Name, g.ImageUrl } into grouped
                select new GamesWithPostCountViewModel
            {
                PostCount = grouped.Where(gr => gr.p != null).Count(),
                Game      = new Game
                {
                    GameId   = grouped.Key.GameId,
                    Name     = grouped.Key.Name,
                    ImageUrl = grouped.Key.ImageUrl,
                }
            }).ToListAsync();

            model.GamesWithPostCount = PostsCount;

            return(View(model));
        }
예제 #3
0
        // GET: Games
        public async Task <IActionResult> Index(DateTime?dayOf)
        {
            var viewModel = new GameIndexViewModel();

            if (dayOf != null)
            {
                viewModel.dayOf = dayOf;
            }
            else
            {
                viewModel.dayOf = DateTime.Today.Date;
            }

            viewModel.Games = await _gamesService.GetGamesByDateAsync(viewModel.dayOf.Value);

            int count = 0;

            foreach (var g in viewModel.Games)
            {
                List <PlayerGameStats> leaders = await _playerGameStatsService.GetGameLeadersAsync(g.GameID);

                if (leaders.Count() == 2)
                {
                    viewModel.Leaders[count++] = leaders[0];
                    viewModel.Leaders[count++] = leaders[1];
                }
            }
            return(View(viewModel));
        }
예제 #4
0
        public IActionResult Index(string searchString, string currentFilter, int id = 1)
        {
            var games = this.gamesService
                        .GetAll <GameViewModel>(GamesPerPage, (id - 1) * GamesPerPage, searchString);

            var viewModel = new GameIndexViewModel {
                Games = games
            };

            viewModel.CurrentPage = id;

            if (searchString != null)
            {
                viewModel.CurrentPage = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            this.ViewData["CurrentFilter"] = searchString;

            var count = this.gamesService.GetCount(searchString);

            viewModel.PagesCount = (int)Math.Ceiling((double)count / GamesPerPage);
            if (viewModel.PagesCount == 0)
            {
                viewModel.PagesCount = 1;
            }

            return(this.View(viewModel));
        }
예제 #5
0
        private GameIndexViewModel CreateGameIndexViewModel(IEnumerable <Game> games, int page, string pageSizeClient)
        {
            var pageSize = PageSize(pageSizeClient);

            var gamesPerPages = _gameService.Pagination(games, page, pageSize);

            var gamesPerPagesView = Mapper.Map <IEnumerable <Game>, List <GameViewModel> >(gamesPerPages);
            var sortingDictionary = new Dictionary <string, SortFilter>
            {
                { "Most popular", SortFilter.MostPopular },
                { "Most commented", SortFilter.MostCommented },
                { "Price ASC", SortFilter.PriceASC },
                { "Price DESC", SortFilter.PriceDESC },
                { "Sort by date added", SortFilter.SortByDateAdded }
            };

            var indexView = new GameIndexViewModel
            {
                PageInfo = new PageInfo {
                    PageNumber = page, PageSize = pageSize, TotalItems = games.Count()
                },
                GameViewModels = gamesPerPagesView,

                FilterModel = new FilterViewModel
                {
                    Genres           = new SelectList(_gameService.GetGenres(), "Name", "Name").ToList(),
                    PlatformTypes    = new SelectList(_gameService.GetPlatformTypes(), "Type", "Type").ToList(),
                    Publishers       = new SelectList(_gameService.GetPublishers(), "CompanyName", "CompanyName").ToList(),
                    PublicationTimes = CreateReleaseDateList(),
                    SortingTypesList = new SelectList(sortingDictionary, "value", "key").ToList(),
                }
            };

            return(indexView);
        }
예제 #6
0
        public ActionResult Game()
        {
            var GameIndexView = new GameIndexViewModel()
            {
                Games = _dbContext.Games.ToList()
            };

            return(View(GameIndexView.Games));
        }
예제 #7
0
        // GET: Game
        public async Task <ActionResult> Index()
        {
            var player = ApplicationUser.GetCurrentPlayer(this.HttpContext);
            var games  = await this.gameService.GetPlayerActiveGamesAsync(player);

            var model = new GameIndexViewModel(games);

            return(View(model));
        }
예제 #8
0
        public IActionResult Index()
        {
            var model = new GameIndexViewModel();

            model.Games = work.GameRepository.GetAllGamesForUser(CurrentUser.ID)
                          .Select(e => GameModel.GenerateGameModelFromDTO(e))
                          .ToList();
            return(View(model));
        }
예제 #9
0
        public IActionResult GameList()
        {
            var gameList = new GameIndexViewModel()
            {
                AvailableGames      = this.gameService.GetAvailableGames(this.User.Identity.GetUserId()),
                UserGamesInProgress = this.gameService.GetUserGamesInProgress(this.User.Identity.GetUserId()),
                UserJoinedGames     = this.gameService.GetUserJoinedGames(this.User.Identity.GetUserId())
            };

            return(this.PartialView("_GamesPartial", gameList));
        }
예제 #10
0
        public ActionResult Index()
        {
            var model = new GameIndexViewModel();

            model.Games = DbContext.Games
                          .Include("Publisher")
                          .Include("Categories")
                          .ToList();
            model.LayoutModel = this.BaseModel;
            return(View(model));
        }
예제 #11
0
        internal static GameIndexViewModel ToIndexViewModel(IEnumerable <Game> games)
        {
            var vm = new GameIndexViewModel();

            foreach (var g in games)
            {
                vm.Games.Add(ToIndexItemViewModel(g));
            }

            return(vm);
        }
예제 #12
0
        public async Task <IActionResult> Index()
        {
            var viewmodel = new GameIndexViewModel()
            {
                GameGenres    = await _db.GameGenreRepository.GetAllAsync(a => !a.IsDeleted),
                GamePlatforms = await _db.GamePlatformRepository.GetAllAsync(a => !a.IsDeleted),
                Games         = await _db.GameRepository.GetAllAsync(a => !a.IsDeleted)
            };

            return(View(viewmodel));
        }
예제 #13
0
        public HttpResponseMessage Get(GamesFilterViewModel filter, PaginationViewModel pagination)
        {
            var gameIndexViewModel = new GameIndexViewModel
            {
                Filter     = filter,
                Pagination = pagination,
            };

            FillGameIndexViewModel(gameIndexViewModel);

            return(Request.CreateResponse(HttpStatusCode.OK, gameIndexViewModel.Games));
        }
예제 #14
0
        public IActionResult Index()
        {
            var userId    = this.User.Identity.GetUserId();
            var viewModel = new GameIndexViewModel()
            {
                AvailableGames      = this.gameService.GetAvailableGames(userId),
                UserGamesInProgress = this.gameService.GetUserGamesInProgress(userId),
                UserJoinedGames     = this.gameService.GetUserJoinedGames(userId)
            };

            return(View(viewModel));
        }
예제 #15
0
        public IActionResult Index()
        {
            GameIndexViewModel viewModel = new GameIndexViewModel
            {
                Games      = gameService.GetAll(),
                Genres     = genreService.GetAll(),
                Developers = developerService.GetAll(),
                Publishers = publisherService.GetAll(),
                Platforms  = platformService.GetAll(),
                Reviews    = reviewService.GetAll()
            };

            return(View(viewModel));
        }
예제 #16
0
        public async Task <IActionResult> Index()
        {
            // Geriye döndüreceğimiz Model nesnesini örnekliyoruz.
            // İçinde tüm oyunları, çıkış tarihlerine ait bir listeyi ve toplam oyun sayısını döndürüyoruz.
            // Aslında Index.cshtml için gerekli olan temel verilerimizi içeren bir model tasarladık diyebiliriz.
            GameIndexViewModel data = new GameIndexViewModel();

            data.Games = await _db.Games.ToListAsync();

            data.Years = await _db.Games.Select(g => g.Year).Distinct().OrderBy(g => g).ToListAsync <short?>();

            // ViewData üstünden de View katmanına veri taşımamız mümkündür.
            // Örneğin toplam oyun sayısını View'a taşıyabiliriz.
            ViewData["TotalGamesCount"] = await _db.Games.CountAsync();

            return(View(data));
        }
        public async Task <ActionResult> Index()
        {
            if (User.Identity.IsAuthenticated)
            {
                List <Game> games = _db.Games.Where(game => game.Status != GameStatus.GAME_OVER).ToList();
                List <Team> teams = _db.Teams.ToList();
                for (int i = 0; i < games.Count; i++)
                {
                    games[i].Teams = teams.Where(team => team.GameId == games[i].GameId).ToList();
                }
                var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
                var currentUser = await _userManager.FindByIdAsync(userId);

                GameIndexViewModel model = new GameIndexViewModel()
                {
                    Games = games, User = currentUser
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
예제 #18
0
        public IActionResult Index(string titleFilter, int minFilter, int maxFilter, int playTimeFilter, string ownerFilter, string designerFilter, string sort)
        {
            var indexVM = new GameIndexViewModel(db, titleFilter, minFilter, maxFilter, playTimeFilter, ownerFilter, designerFilter, sort);

            return(View(indexVM));
        }
예제 #19
0
 public ActionResult GetGames(GameIndexViewModel gameIndexViewModel)
 {
     gameIndexViewModel = FillGameIndexViewModel(gameIndexViewModel);
     return(View(gameIndexViewModel));
 }
예제 #20
0
        public async Task <IActionResult> Index(string price, string category, string search)
        {
            // filter price
            if (!Enum.TryParse(price, out FilterPrice ePrice) && !string.IsNullOrWhiteSpace(price))
            {
                price = null;
                return(RedirectToAction(nameof(Index), new { price, category, search }));
            }

            // user
            User user = await _userManager.GetUserAsync(User);

            DateTime now = DateTime.Now;

            // query games
            IQueryable <Game> gamesQuery = _context.Games.Include(g => g.GameType);

            gamesQuery = FilterBySearch(gamesQuery, search);
            gamesQuery = FilterByPrice(gamesQuery, ePrice);
            gamesQuery = FilterByCategory(gamesQuery, category);

            var games = await gamesQuery
                        .Select(g => new GameItemViewModel
            {
                Game = g,

                Image = _context.GameImages
                        .FirstOrDefault(i => i.GameId == g.GameId && i.ImageType == ImageType.Banner),

                IsWishlisted = user != null && _context.UserGameWishlists
                               .Any(w => w.GameId == g.GameId && w.UserId == user.Id),

                IsInCart = user != null && _context.CartGames
                           .Any(c => c.GameId == g.GameId && c.CartUserId == user.Id && c.ReceivingUserId == user.Id),

                Discount = _context.GameDiscounts
                           .Where(d => d.GameId == g.GameId && d.DiscountPrice <g.RegularPrice && d.DiscountStart <= now && d.DiscountFinish> now)
                           .OrderBy(d => d.DiscountPrice)
                           .FirstOrDefault(),

                IsOwned = user != null && _context.OrderItems
                          .Any(o => o.GameId == g.GameId && o.OwnerUserId == user.Id && !o.PhysicallyOwned),
            })
                        .ToListAsync();

            // return view model
            var viewModel = new GameIndexViewModel
            {
                FilterPrice    = price,
                FilterCategory = category,
                FilterSearch   = search,

                FilterGroups = new List <FilterGroupViewModel>
                {
                    PopulateFilterPrice(ePrice),
                    await PopulateFilterCategoryAsync(category),
                },
                Games = games,
            };

            return(View(viewModel));
        }