public static List <SearchGame> GetSearchGamesForUser(this ApplicationDbContext _context, string UserID) { IEnumerable <GameAccess> accesses = _context.GetGameAccessForUser(UserID); return((SearchGame.GenerateMany(_context, accesses.Select(g => g.game.ID).ToArray())).ToList()); }
public async Task <SearchGame> StartSearchGame(InSearchGame inSearchGame, int userId, int providerId) { var lastSearcGame = await context.SearchGames.FirstOrDefaultAsync(x => x.UserId == userId); if (lastSearcGame != null) { throw ExceptionFactory.SoftException(ExceptionEnum.GameAlreadySearch, "GameAlreadySearch"); } var game = await context.Games.FirstOrDefaultAsync(x => x.IsEnd == false); if (game != null) { throw ExceptionFactory.SoftException(ExceptionEnum.LastGameNotEnd, "LastGameNotEnd"); } var newSearchGame = new SearchGame { GameTypeId = inSearchGame.GameTypeId, CategoryId = inSearchGame.CategoryId, ProviderId = providerId, UserId = userId }; await context.SearchGames.AddAsync(newSearchGame); await context.SaveChangesAsync(); return(newSearchGame); }
// GET: Games/Join public async Task <IActionResult> Join(string id) { SearchGame sgame = await SearchGame.Generate(_context, id); if (sgame == null) { return(RedirectToAction(nameof(Index))); } return(View(JoinGame.FromSearchGame(sgame, User.GetUserId()))); }
public async Task <IActionResult> Index(string q = null, byte?searchLimit = 20, int?pageNumber = 0) { bool loggedIn = User.IsLoggedIn(); ViewData["LoggedIn"] = (bool?)loggedIn; if (loggedIn) { ViewData["MyGames"] = (await _context.GetSearchGamesForUserAsync(User.GetUserId())); } else { ViewData["MyGames"] = null; } ViewData["query"] = q; List <SearchGame> ret; if (!String.IsNullOrWhiteSpace(q)) { List <int> results = (await _context.SearchGames(q)); ret = (SearchGame.GenerateMany(_context, results.ToArray())).ToList(); } else { Game[] results = (await _context.Games .Include(g => g.Accesses) .OrderBy(g => g.Accesses.Count) .Skip(pageNumber.Value * searchLimit.Value) .Take(searchLimit.Value) .ToArrayAsync()); ret = (SearchGame.GenerateMany(_context, results)).ToList(); } return(View(ret)); }