public async Task <Dto.Game?> AddNew(int gameId) { var userId = _sessionService.GetCurrentUserId(); User user = await _userService.GetUserById(userId) ?? throw new IllegalStateException(nameof(User)); var game = await _gameRepository.AddNewGame(gameId, user); if (game is null) { return(null); } _sessionService.SetCurrentGameId(game.Id); return(_mapper.Map <Game, Dto.Game>(game)); }
public IActionResult JoinGame(string opponentId) { //Add the game var user = _signInManager.UserManager.Users.Where(u => u.Id == opponentId).FirstOrDefault(); if (!user.IsInLobby) { return(Redirect("/Home/Index")); } string newGameId = _GameRepo.AddNewGame(_signInManager.UserManager.GetUserId(User), opponentId); //Remove the user looking for a game from the lobby _GameRepo.LeaveLobby(opponentId); //Send the joining user to the game return(RedirectToAction("Index", "Game", new { gameId = newGameId })); }
public async Task <IActionResult> Create(GameCreateViewModel model) { if (ModelState.IsValid) { var photoUrl = await uploadImage.UploadImage(model.Photo); var game = new Game { Name = model.Name, Description = model.Description, Genres = model.Genres, PhotoUrl = photoUrl, Rating = model.Rating, RelaseDate = model.RelaseDate }; gameRepository.AddNewGame(game); return(RedirectToAction("details", new { id = game.Id })); } return(View()); }
public IActionResult NewGame([FromBody] UserIdDTO id) { var userId = _signInManager.UserManager.GetUserId(User); var opponentId = id.UserID; bool tooManyGames = _GameRepo.GetAllGames(userId).Where(p => p.OpponentName.Equals(_GameRepo.GetUserNameFromId(opponentId))).Count() >= 3; if (tooManyGames) { return(Json(new GameRefreshData { GameID = "" })); } var newGameID = _GameRepo.AddNewGame(_signInManager.UserManager.GetUserId(User), id.UserID); var data = new GameRefreshData { GameID = newGameID }; return(Json(data)); }
public async Task <IActionResult> ManagePendingGames(int[] gameId) { if (ModelState.IsValid) { foreach (var pg in gameId.ToList()) { var ApprovedGame = pendingGameRepository.GetById(pg); if (ApprovedGame == null) { ModelState.AddModelError(string.Empty, "The game Id is not valid"); return(View()); } { var game = new Game() { Description = ApprovedGame.Description, Name = ApprovedGame.Name, Genres = ApprovedGame.Genres, Rating = ApprovedGame.Rating, RelaseDate = ApprovedGame.RelaseDate, PhotoUrl = ApprovedGame.PhotoUrl }; gameRepository.AddNewGame(game); //Sends a notification via email to notify the user that his/her game has been approved var user = await userManager.FindByIdAsync(ApprovedGame.UserId); var callback = Url.Action("details", "home", new { id = game.Id }, Request.Scheme); var message = new Message(new string[] { user.Email }, "Your game has been approved, check the attached link:", callback); await emailSender.SendEmailAsync(message); //Deletes the approved game pendingGameRepository.Delete(ApprovedGame.Id); TempData["Approved"] = "The selected games have been added to the Game List"; } } return(RedirectToAction("ManagePendingGames", "Administration")); } return(RedirectToAction("Games", "home")); }