public void OneTimeSetUp() { GetInstance <GameList>().Games = GameList(); _viewModel = GetInstance <GameListViewModel>(); _viewModel.Initialise(); }
/** * Routes user to page that shows a list of all current, open games */ public ActionResult GameList() { ViewBag.Venue = new SelectList(_venueService.GetAllVenues(), "VenueId", "Name"); ViewBag.Sport = new SelectList(_gameService.GetAllSports(), "SportId", "SportName"); // Get games that are open and that have not already passed and order by games happening soonest List <Game> games = _gameService.GetAllCurrentOpenGames(); List <GameListViewModel> model = new List <GameListViewModel>(); foreach (var game in games) { var gameToAdd = new GameListViewModel(); gameToAdd.GameId = game.GameId; gameToAdd.Sport = _gameService.GetSportNameById(game.SportId); gameToAdd.Venue = _venueService.GetVenueNameById(game.VenueId); gameToAdd.StartDate = game.StartTime; gameToAdd.EndDate = game.EndTime; if (game.ContactId != null) { gameToAdd.ContactId = game.ContactId; gameToAdd.ContactName = _contactService.GetContactById(game.ContactId).Username; } model.Add(gameToAdd); } return(View(model)); }
public PartialViewResult SearchBySport(int sportId) { List <Game> gameList = _gameService.GetCurrentGamesBySportId(sportId); if (gameList.Count == 0) { ViewData.ModelState.AddModelError("GameSearch", "There are no games that matches your search"); } //List using ViewModel to format how I like List <GameListViewModel> model = new List <GameListViewModel>(); //Find right data for each variable foreach (var game in gameList) { var gameToAdd = new GameListViewModel { GameId = game.GameId, Sport = _gameService.GetSportNameById(game.SportId), Venue = _venueService.GetVenueNameById(game.VenueId), StartDate = game.StartTime, EndDate = game.EndTime }; if (game.ContactId != null) { gameToAdd.ContactId = game.ContactId; gameToAdd.ContactName = _contactService.GetContactById(game.ContactId).Username; } model.Add(gameToAdd); } return(PartialView("_GameSearch", model)); }
public IActionResult Index(int page = 1, int RateMin = 0, int RateMax = 0) { if (page < 1) { return(NotFound()); } int GamesCountOnPage = 5; List <GameViewModel> games = _gamesService.getViewModels(); if (RateMax != 0) { games = games.Where(g => (g.Rate <= RateMax) && (g.Rate >= RateMin)).ToList(); } var count = games.Count(); var items = games.Skip((page - 1) * GamesCountOnPage).Take(GamesCountOnPage).ToList(); PageViewModel pageViewModel = new PageViewModel(count, page, GamesCountOnPage); GameListViewModel viewModel = new GameListViewModel { PageViewModel = pageViewModel, Games = items, RateMin = RateMin, RateMax = RateMax }; return(View(viewModel)); }
public ViewResult List() { GameListViewModel gameListViewModel = new GameListViewModel(); gameListViewModel.Games = _GameRepository.AllGames; ViewBag.CurrenCategory = "Games"; return(View(gameListViewModel)); }
public PartialViewResult TimeFilter(string dateRange) { var dates = dateRange.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); var startDateTime = DateTime.Parse(dates[0], CultureInfo.InvariantCulture); var endDateTime = DateTime.Parse(dates[1], CultureInfo.CurrentCulture); List <GameListViewModel> model = new List <GameListViewModel>(); foreach (var game in _gameService.GetAllCurrentOpenGames()) { if (_gameService.IsSelectedTimeValid(startDateTime, endDateTime)) { if (game.StartTime >= startDateTime && game.EndTime <= endDateTime) { var gameToAdd = new GameListViewModel { GameId = game.GameId, Sport = _gameService.GetSportNameById(game.SportId), Venue = _venueService.GetVenueNameById(game.VenueId), StartDate = game.StartTime, EndDate = game.EndTime }; if (game.ContactId != null) { gameToAdd.ContactId = game.ContactId; gameToAdd.ContactName = _contactService.GetContactById(game.ContactId).Username; } model.Add(gameToAdd); } } else { var gameToAdd = new GameListViewModel { GameId = game.GameId, Sport = _gameService.GetSportNameById(game.SportId), Venue = _venueService.GetVenueNameById(game.VenueId), StartDate = game.StartTime, EndDate = game.EndTime }; if (game.ContactId != null) { gameToAdd.ContactId = game.ContactId; gameToAdd.ContactName = _contactService.GetContactById(game.ContactId).Username; } model.Add(gameToAdd); } } if (model.Count == 0) { ViewData.ModelState.AddModelError("GameSearch", "There are no games that matches your search"); } return(PartialView("_GameSearch", model)); }
public ViewResult List() { ViewBag.Title = "Страница с играми"; GameListViewModel gameListViewModel = new GameListViewModel(); gameListViewModel.allGames = _allGames.Games; gameListViewModel.gameCategory = "Игры"; return(View(gameListViewModel)); }
public ActionResult GetGamesUserJoined(int contactId, bool isPublicProfileView) { var model = new GameProfileViewModel(); model.IsPublicProfileView = isPublicProfileView; model.ContactId = contactId; var pickUpGames = _gameService.GetPickUpGamesByContactId(contactId); if (pickUpGames == null) { return(PartialView("../Game/_GamesUserJoined", model)); } model.Games = new List <GameListViewModel>(); foreach (var pickUpGame in pickUpGames) { var game = _gameService.GetGameById(pickUpGame.GameId); // Do not add game to list if time passed if (game.EndTime < DateTime.Today.AddDays(-1)) { continue; } // Do not add if user is the creator of game if (game.ContactId == contactId) { continue; } var gameToAdd = new GameListViewModel { EndDate = game.EndTime, GameId = game.GameId, GameStatus = ((GameStatusEnum)game.GameStatusId).ToString(), Sport = _gameService.GetSportNameById(game.SportId), StartDate = game.StartTime, Venue = _venueService.GetVenueNameById(game.VenueId), VenueId = game.VenueId }; if (game.ContactId != null) { gameToAdd.ContactId = game.ContactId; gameToAdd.ContactName = _contactService.GetContactById(game.ContactId).Username; } model.Games.Add(gameToAdd); } model.Games = model.Games.OrderBy(x => x.StartDate).ToList(); return(PartialView("../Game/_GamesUserJoined", model)); }
// dto has properties for the paging, sorting, and filtering route segments defined in the Startup.cs file public ViewResult List(GameGridDTO values) { // get grid builder, which loads route segment values and stores them in session var builder = new GameGridBuilder(HttpContext.Session, values, defaultSortField: nameof(Game.Name)); // create a GameQueryOptions object to build a query expression for a page of data var options = new GameQueryOptions { Includes = "Genre, Type, Format, Rating, Publisher", OrderByDirection = builder.CurrentRoute.SortDirection, PageNumber = builder.CurrentRoute.PageNumber, PageSize = builder.CurrentRoute.PageSize }; // call the SortFilter() method of the GameQueryOptions object and pass it the builder // object. It uses the route information and the properties of the builder object to // add sort and filter options to the query expression. options.SortFilter(builder); // create view model and add page of game data, data for drop-downs, // the current route, and the total number of pages. var vm = new GameListViewModel { Games = data.Games.List(options), Genres = data.Genres.List(new QueryOptions <Genre> { OrderBy = g => g.Name }), Types = data.Types.List(new QueryOptions <Type> { OrderBy = t => t.Name }), Formats = data.Formats.List(new QueryOptions <Format> { OrderBy = f => f.Name }), Ratings = data.Ratings.List(new QueryOptions <Rating> { OrderBy = r => r.Name }), Publishers = data.Publishers.List(new QueryOptions <Publisher> { OrderBy = p => p.Name }), CurrentRoute = builder.CurrentRoute, TotalPages = builder.GetTotalPages(data.Games.Count) }; // pass view model to view return(View(vm)); }
public async Task <ActionResult> Index() { var games = (await _gameAppService.GetAll(new PagedResultRequestDto { MaxResultCount = int.MaxValue })).Items; // Paging not implemented yet var model = new GameListViewModel { Games = games, }; return(View(model)); }
public void OneTimeSetUp() { GetInstance <GameList>().Games = GameList(); _gameListViewModel = GetInstance <GameListViewModel>(); _manufacturerViewModel = GetInstance <MultipleChoiceFilterViewModel>(); _categoryViewModel = GetInstance <MultipleChoiceFilterViewModel>(); _gameListViewModel.Initialise(); _categoryViewModel.Initialise(); _manufacturerViewModel.Initialise(); _manufacturerViewModel.FilterProperty = nameof(GameViewModel.Manufacturer); _categoryViewModel.FilterProperty = nameof(GameViewModel.Category); }
public ViewResult List(string category, int page = 1, int sort = 1) { GameListViewModel model; if (sort == 1) { model = new GameListViewModel { Games = context.Games.Include(nameof(Category)) .Where(p => category == null || p.Category.CategoryName == category) .OrderByDescending(Game => (Game.Price / 100 * (100 - Game.Discount))) .Skip((page - 1) * pageSize) .Take(pageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = category == null? context.Games.Count() : context.Games.Where(Game => Game.Category.CategoryName == category).Count() }, CurrentCategory = category, CurrentSort = sort }; } else { model = new GameListViewModel { Games = context.Games.Include(nameof(Category)) .Where(p => category == null || p.Category.CategoryName == category) .OrderBy(Game => (Game.Price / 100 * (100 - Game.Discount))) .Skip((page - 1) * pageSize) .Take(pageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = category == null? context.Games.Count() : context.Games.Where(Game => Game.Category.CategoryName == category).Count() }, CurrentCategory = category, CurrentSort = sort }; } return(View(model)); }
/// <summary> /// Starts the game window /// </summary> private void initializeGameList() { GameListViewModel gamesList = new GameListViewModel(); GameListWindows.Add(gamesList); gamesList.joinGame += joinSelectedGame; gamesList.wind.createChat += createChat; //Send the changes in games to the game list mgr.gamesChanged += gamesList.onGamesChanged; //Set the event to begin the game chat window mgr.joinedGameSuccess += joinGameSuccess; }
public IActionResult GameList(GameListViewModel model, int page = 1) { ViewBag.Publishers = new SelectList(_context.Games.Select(g => g.Publisher).Distinct()); ViewBag.Developers = new SelectList(_context.Games.Select(g => g.Developer).Distinct()); ViewBag.StartYears = new SelectList(Enumerable.Range(1900, DateTime.Now.Year - 1899)); ViewBag.EndYears = new SelectList(Enumerable.Range(1900, DateTime.Now.Year - 1899)); ViewBag.AgeRatings = new SelectList(_context.Games.Select(g => g.AgeRating).Distinct()); var pageSize = 30; var games = _context.GetFilteredGameList(model.Filter); var count = games.Count(); model.Games = games.Skip((page - 1) * pageSize).Take(pageSize).ToList(); model.PageViewModel = new PageViewModel(count, page, 30); return(View(model)); }
public ActionResult AdminList(int page) { var model = new GameListViewModel { Games = _context.Games .OrderBy(m => m.Id) .Skip((page - 1) * pageSize) .Take(pageSize), PagingInfo = new PageInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = _context.Games.Count() } }; return(View("AdminList", model)); }
public ViewResult Index(string category, int page) { var model = new GameListViewModel { Games = _context.Games.Where(p => category == null || p.Category == category) .OrderBy(m => m.Id) .Skip((page - 1) * pageSize) .Take(pageSize), PagingInfo = new PageInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = _context.Games.Count() }, CurrentCategory = category }; return(View("GameList", model)); }
public ViewResult List(string category, int page = 1) { GameListViewModel model = new GameListViewModel { Games = repository.Games .Where(p => category == null || p.Category == category) .OrderBy(game => game.GameId) .Skip((page - 1) * pageSize) .Take(pageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = category == null?repository.Games.Count() : repository.Games.Where(game => game.Category == category).Count() }, CurrentCategory = category }; return(View(model)); }
public ActionResult GetGamesStartedByUser(int contactId, bool isPublicProfileView) { var model = new GameProfileViewModel(); model.IsPublicProfileView = isPublicProfileView; model.ContactId = contactId; var games = _gameService.GetCurrentOrderedGamesByContactId(contactId); if (games == null) { return(PartialView("../Game/_GamesUserCreated", model)); } model.Games = new List <GameListViewModel>(); foreach (var game in games) { var gameToAdd = new GameListViewModel { EndDate = game.EndTime, GameId = game.GameId, GameStatus = ((GameStatusEnum)game.GameStatusId).ToString(), Sport = _gameService.GetSportNameById(game.SportId), StartDate = game.StartTime, Venue = _venueService.GetVenueNameById(game.VenueId), VenueId = game.VenueId }; if (game.ContactId != null) { gameToAdd.ContactId = game.ContactId; gameToAdd.ContactName = _contactService.GetContactById(game.ContactId).Username; } model.Games.Add(gameToAdd); } return(PartialView("../Game/_GamesUserCreated", model)); }
public void Can_Send_Pagination_View_Model() { // arrange Mock <IGameRepository> mock = new Mock <IGameRepository>(); mock.Setup(m => m.Games).Returns(new List <Game> { new Game { GameId = 1, Name = "Game_1" }, new Game { GameId = 2, Name = "Game_2" }, new Game { GameId = 3, Name = "Game_3" }, new Game { GameId = 4, Name = "Game_4" }, new Game { GameId = 5, Name = "Game_5" } }); GameController controller = new GameController(mock.Object); controller.pageSize = 3; // act GameListViewModel result = (GameListViewModel)controller.List(null, 2).Model; // Assers PagingInfo pagingInfo = result.PagingInfo; Assert.AreEqual(pagingInfo.CurrentPage, 2); Assert.AreEqual(pagingInfo.ItemsPerPage, 3); Assert.AreEqual(pagingInfo.TotalItems, 5); Assert.AreEqual(pagingInfo.TotalPages, 2); }
// GET: Home public async Task <ActionResult> Index() { var vm = new GameListViewModel(); var grain = GameListGrainFactory.GetGrain(0); foreach (var game in await grain.Unstarted()) { var gamevm = new GameListViewModel.GameViewModel { Name = await game.Name(), Players = new List <string>() }; var players = await game.Players(); foreach (var player in players) { gamevm.Players.Add(await player.Name()); } vm.Games.Add(gamevm); } return(View(vm)); }
public ActionResult ListGames() { using (var db = new BettingSystemDbContext()) { var games = new GameListViewModel { Games = db.Games.Select(g => new GameItem { Id = g.Id, HomeTeamId = g.HomeTeamId, HomeTeam = g.HomeTeam.Name, AwayTeamId = g.AwayTeamId, AwayTeam = g.AwayTeam.Name, HomeGoals = g.HomeGoals, AwayGoals = g.AwayGoals, Date = g.Date }).ToList() }; return(View(games)); } }
public PartialViewResult GetVenueGames(int venueId) { var model = new List <GameListViewModel>(); var games = _gameService.GetCurrentGamesByVenueId(venueId); if (games == null) { return(PartialView("_VenueGames", model)); } var openGames = games.Where(x => x.GameStatusId == (int)GameStatusEnum.Open).ToList(); if (openGames.Count < 1) { return(PartialView("_VenueGames", model)); } foreach (var game in games) { GameListViewModel gameToAdd = new GameListViewModel { GameId = game.GameId, Sport = _gameService.GetSportNameById(game.SportId), StartDate = game.StartTime, EndDate = game.EndTime }; if (game.ContactId != null) { gameToAdd.ContactId = game.ContactId; gameToAdd.ContactName = _contactService.GetContactById(game.ContactId).Username; } model.Add(gameToAdd); } model = new List <GameListViewModel>(model.OrderBy(x => x.StartDate)); return(PartialView("_VenueGames", model)); }
public void Can_Paginate() { // arrange Mock <IGameRepository> mock = new Mock <IGameRepository>(); mock.Setup(m => m.Games).Returns(new List <Game> { new Game { GameId = 1, Name = "Game_1" }, new Game { GameId = 2, Name = "Game_2" }, new Game { GameId = 3, Name = "Game_3" }, new Game { GameId = 4, Name = "Game_4" }, new Game { GameId = 5, Name = "Game_5" } }); GameController controller = new GameController(mock.Object); controller.pageSize = 3; // act GameListViewModel result = (GameListViewModel)controller.List(null, 2).Model; // assert List <Game> games = result.Games.ToList(); Assert.IsTrue(games.Count == 2); Assert.AreEqual(games[0].Name, "Game_4"); Assert.AreEqual(games[1].Name, "Game_5"); }
public async Task <IActionResult> Index( string searchString) { var currentUser = await GetCurrentUserAsync(); GameListViewModel viewModel = new GameListViewModel(); viewModel.CurrentUserRoleId = currentUser.RoleId; viewModel.GameList = await( from g in _context.Game join t in _context.Team on g.TeamAId equals t.Id into sub1 from subq1 in sub1.DefaultIfEmpty() join t in _context.Team on g.TeamBId equals t.Id into sub2 from subq2 in sub2.DefaultIfEmpty() select new GameDetailsViewModel { Game = new Game { Id = g.Id, Location = g.Location, GameTime = g.GameTime, TeamAId = g.TeamAId, TeamBId = g.TeamBId, TeamAScore = g.TeamAScore, TeamBScore = g.TeamBScore }, TeamAName = subq1.Name, TeamBName = subq2.Name }).ToListAsync(); if (!String.IsNullOrEmpty(searchString)) { viewModel.GameList = viewModel.GameList.Where(g => g.TeamAName.Contains(searchString) || g.TeamBName.Contains(searchString)).ToList(); } return(View(viewModel)); }
public IActionResult List(string id = "All") { List <Game> games; if (id == "All") { games = context.Games .OrderBy(g => g.GameID).ToList(); } else { games = context.Games .Where(g => g.Genre.Name == id) .OrderBy(g => g.GameID).ToList(); } var model = new GameListViewModel { Genres = genres, Games = games, SelectedGenre = id }; return(View(model)); }
public IActionResult GameList(int page = 1, string likeName = null) { ViewBag.Publishers = new SelectList(_context.Games.Select(g => g.Publisher).Distinct()); ViewBag.Developers = new SelectList(_context.Games.Select(g => g.Developer).Distinct()); ViewBag.StartYears = new SelectList(Enumerable.Range(1900, DateTime.Now.Year - 1899)); ViewBag.EndYears = new SelectList(Enumerable.Range(1900, DateTime.Now.Year - 1899)); ViewBag.AgeRatings = new SelectList(_context.Games.Select(g => g.AgeRating).Distinct()); var pageSize = 30; var gameListViewModel = new GameListViewModel(); gameListViewModel.Filter = new FilterPanel(); if (likeName != null) { gameListViewModel.Filter.Name = likeName; } var games = _context.GetFilteredGameList(likeName != null ? gameListViewModel.Filter : null); var count = games.Count(); gameListViewModel.Games = games.Skip((page - 1) * pageSize).Take(pageSize).ToList(); gameListViewModel.PageViewModel = new PageViewModel(count, page, 30); return(View(gameListViewModel)); }
public GlobalSelectionContentFilter(GameListViewModel gameList) => _gameList = gameList;
public MultipleChoiceFilterViewModel(GameListViewModel gameList) { _gameList = gameList; }