public virtual ActionResult Edit([Bind(Include = "Id,Name,Active,GamingGroupId")] Player player, ApplicationUser currentUser) { if (ModelState.IsValid) { player.Name = player.Name.Trim(); var requestedPlayer = new UpdatePlayerRequest { PlayerId = player.Id, Active = player.Active, Name = player.Name, }; try { playerSaver.UpdatePlayer(requestedPlayer, currentUser); return(new RedirectResult(Url.Action(MVC.GamingGroup.ActionNames.Index, MVC.GamingGroup.Name) + "#" + GamingGroupController.SECTION_ANCHOR_PLAYERS)); } catch (PlayerAlreadyExistsException) { ModelState.AddModelError(string.Empty, $@"A Player with name '{requestedPlayer.Name}' already exists in this Gaming Group. Choose another."); } } var playerEditViewModel = playerEditViewModelBuilder.Build(player); return(View(MVC.Player.Views.Edit, playerEditViewModel)); }
public UpdatePlayerResponse UpdatePlayer(UpdatePlayerRequest request) { if (request == null) { AddNotification("UpdatePlayerRequest", Message.X0_IS_REQUIRED.ToFormat("UpdatePlayerRequest")); } Player player = _playerRepository.FindPlayerById(request.Id); if (player == null) { AddNotification("Id", "data not found"); return(null); } var name = new Name(request.FirstName, request.LastName); var email = new Email(request.Email); player.UpdatePlayer(name, email); AddNotifications(player); if (IsInvalid()) { return(null); } _playerRepository.UpdatePlayer(player); return((UpdatePlayerResponse)player); }
public async Task <IActionResult> PutPlayer([FromRoute] Guid id, [FromBody] UpdatePlayerRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Find our player. PlayerDataModel player = await _context.Players.FindAsync(id); if (player == null) { return(NotFound()); } // Update properties. player.Name = request.Name; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { // If we hit a concurrency exception and the player no longer exists, // It must have been deleted while we were working. if (!_context.Players.Any(e => e.Id == id)) { return(NotFound()); } throw; } return(NoContent()); }
public virtual void UpdatePlayer(UpdatePlayerRequest updatePlayerRequest, ApplicationUser applicationUser) { var player = _dataContext.FindById <Player>(updatePlayerRequest.PlayerId); var somethingChanged = false; if (updatePlayerRequest.Active.HasValue) { player.Active = updatePlayerRequest.Active.Value; somethingChanged = true; } if (!string.IsNullOrWhiteSpace(updatePlayerRequest.Name)) { player.Name = updatePlayerRequest.Name.Trim(); somethingChanged = true; } if (somethingChanged) { Save(player, applicationUser); } }
public WaitingRoomPlayersResponse UpdatePlayer(UpdatePlayerRequest request) { WaitingRoom waitingRoom = WaitingRoom.GetWaitingRoom(); waitingRoom.UpdatePlayer(request); waitingRoom.SaveWaitingRoom(); return(new WaitingRoomPlayersResponse() { Players = waitingRoom.Players }); }
public async Task <bool> UpdatePlayerAsync(int id, UpdatePlayerRequest playerRequest) { var playerToUpdate = await _dbContext.Players.FindAsync(id); if (default == playerToUpdate) { return(false); } playerToUpdate.NickName = playerRequest.NickName; _dbContext.Update(playerToUpdate); return(await _dbContext.SaveChangesAsync() > 0); }
public void ItUpdatesThePlayerName() { var updatePlayerRequest = new UpdatePlayerRequest { Name = "a new name", PlayerId = PLAYER_ID }; autoMocker.ClassUnderTest.UpdatePlayer(updatePlayerRequest, currentUser); autoMocker.ClassUnderTest.AssertWasCalled( mock => mock.Save(Arg <Player> .Matches(p => p.Name == updatePlayerRequest.Name), Arg <ApplicationUser> .Is.Same(currentUser))); }
public void ItUpdatesTheActiveFlag() { var updatePlayerRequest = new UpdatePlayerRequest { Active = true, PlayerId = PLAYER_ID }; autoMocker.ClassUnderTest.UpdatePlayer(updatePlayerRequest, currentUser); autoMocker.ClassUnderTest.AssertWasCalled( mock => mock.Save(Arg <Player> .Matches(p => p.Active == updatePlayerRequest.Active.Value), Arg <ApplicationUser> .Is.Same(currentUser))); }
public void ItDoesntBotherUpdatingIfNothingChanged() { var updatePlayerRequest = new UpdatePlayerRequest { Active = _player.Active, Name = _player.Name, PlayerId = PLAYER_ID }; _autoMocker.ClassUnderTest.UpdatePlayer(updatePlayerRequest, _currentUser); _autoMocker.ClassUnderTest.AssertWasNotCalled( mock => mock.Save(Arg <Player> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); }
public IActionResult Update(int id, [FromBody] UpdatePlayerRequest request) { if (!IsPlayerNameValid(ModelState, nameof(request.PlayerName), request.PlayerName)) { return(BadRequest(ModelState)); } var playerToUpdate = Mapper.Map <Player>(request); playerToUpdate.Id = id; _playerService.Update(playerToUpdate); return(Ok( )); }
public async Task <IActionResult> PutPlayerAsync(int id, [FromBody] UpdatePlayerRequest playerRequest) { if (!ModelState.IsValid) { return(BadRequest()); } var isUpdated = await _playerService.UpdatePlayerAsync(id, playerRequest); if (!isUpdated) { return(NotFound($"PlayerId { id } not found.")); } return(Ok("Record has been updated successfully.")); }
public void ItDoesntBotherUpdatingIfNothingWasRequestedToBeUpdated() { var updatePlayerRequest = new UpdatePlayerRequest { Name = null, PlayerId = PLAYER_ID, Active = null }; autoMocker.ClassUnderTest.UpdatePlayer(updatePlayerRequest, currentUser); autoMocker.ClassUnderTest.AssertWasNotCalled( mock => mock.Save(Arg <Player> .Is.Anything, Arg <ApplicationUser> .Is.Same(currentUser))); }
public void UpdatePlayer(UpdatePlayerRequest request) { PlayerDetails player = Players.FirstOrDefault(o => o.SocketId == request.SocketId); if (player != null) { PlayerDetails dbPlayer = PlayerRepository.GetPlayer(request.Name); if (dbPlayer.DisplayName == "Not Found") { throw new Exception("Player not found in database"); } player.DisplayName = dbPlayer.DisplayName; player.FirstName = dbPlayer.FirstName; player.Id = dbPlayer.Id; player.LastName = dbPlayer.LastName; } }
public virtual HttpResponseMessage UpdatePlayer([FromBody] UpdatePlayerMessage updatePlayerMessage, [FromUri] int playerId, [FromUri] int gamingGroupId) { if (updatePlayerMessage == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "You must pass at least one valid parameter.")); } var requestedPlayer = new UpdatePlayerRequest { PlayerId = playerId, Active = updatePlayerMessage.Active, Name = updatePlayerMessage.PlayerName }; _playerSaver.UpdatePlayer(requestedPlayer, CurrentUser); return(Request.CreateResponse(HttpStatusCode.NoContent)); }
public async Task <Player> Update(string username, UpdatePlayerRequest updateInfo) { var found = await _repository.GetByUsername(username); if (VerifyHashedPassword(updateInfo.currentPassword, found.passwordHash, found.passwordSalt)) { if (found == null) { throw new EntityNotFoundException(); } if (!string.IsNullOrWhiteSpace(updateInfo.firstName)) { found.firstName = updateInfo.firstName; } if (!string.IsNullOrWhiteSpace(updateInfo.lastName)) { found.lastName = updateInfo.lastName; } if (!string.IsNullOrWhiteSpace(updateInfo.email)) { found.email = updateInfo.email; } if (!string.IsNullOrWhiteSpace(updateInfo.newPassword)) { byte[] newHash; byte[] newSalt; HashPassword(updateInfo.newPassword, out newHash, out newSalt); found.passwordSalt = newSalt; found.passwordHash = newHash; } return(await _repository.Update(found)); } else { throw new PasswordsDontMatch(); } }
public async Task <ActionResult <PlayerDTO> > UpdateProfile([FromBody] UpdatePlayerRequest updateInfo) { try { Player player = (Player)HttpContext.Items["SessionPlayer"]; return(Ok(_mapper.Map <PlayerDTO>(await this._service.Update(player.username, updateInfo)))); } catch (EntityNotFoundException) { return(NotFound(new Error("UserNotFound", "User Not Found."))); } catch (PasswordsDontMatch e) { return(BadRequest(new Error("PasswordsDontMatch", e.Message)));; } catch (Exception e) { this._logger.LogError(e, e.Message); return(StatusCode(500)); } }
public virtual ActionResult Edit([Bind(Include = "Id,Name,Active,GamingGroupId")] Player player, ApplicationUser currentUser) { if (ModelState.IsValid) { player.Name = player.Name.Trim(); var requestedPlayer = new UpdatePlayerRequest { PlayerId = player.Id, Active = player.Active, Name = player.Name, }; playerSaver.UpdatePlayer(requestedPlayer, currentUser); return(new RedirectResult(Url.Action(MVC.GamingGroup.ActionNames.Index, MVC.GamingGroup.Name) + "#" + GamingGroupController.SECTION_ANCHOR_PLAYERS)); } var playerEditViewModel = playerEditViewModelBuilder.Build(player); return(View(MVC.Player.Views.Edit, playerEditViewModel)); }
public async Task <MatchModel> CreateMatch(CreateMatchCommand command) { Player winner = await playersApiClient.GetPlayer(command.WinnerId); Player loser = await playersApiClient.GetPlayer(command.LoserId); PlayersRatings ratings = await ratingApiClient.CalculatePlayersRatings(RatingMapper.Map(winner, loser)); UpdatePlayerRequest updateWinnerRequest = new UpdatePlayerRequest(winner.Id, winner.Name, ratings.WinnerRating.Rating, ratings.WinnerRating.Deviation, ratings.WinnerRating.Volatility); winner = await playersApiClient.UpdatePlayer(updateWinnerRequest); UpdatePlayerRequest updateLoserRequest = new UpdatePlayerRequest(loser.Id, loser.Name, ratings.LoserRating.Rating, ratings.LoserRating.Deviation, ratings.LoserRating.Volatility); loser = await playersApiClient.UpdatePlayer(updateLoserRequest); CreateMatchRequest createMatchRequest = new CreateMatchRequest(winner.Id, loser.Id, command.Score); Match match = await matchesApiClient.CreateMatch(createMatchRequest); return(MatchMapper.Map(match, new List <Player> { winner, loser })); }
public async Task <ActionResult> UpdatePlayer(UpdatePlayerRequest request) { if (!await this.IsAPITokenValid(request.ApiToken)) { return(new BadRequestObjectResult("UnAuthorized")); } string leagueId = await this.GetLeagueId(request.LeagueKey); if (leagueId == null) { return(new BadRequestObjectResult("League Not Found")); } if (await this.TeamRepository.GetAsync(request.TeamId) == null) { return(new BadRequestObjectResult("Team Not Found")); } var player = await this.PlayerRepository.GetAsync(request.PlayerId); if (player == null) { return(new BadRequestObjectResult("Player Not Found")); } player.PlayerNum = request.PlayerNum; player.Position = request.Position; player.FirstName = request.FirstName; player.LastName = request.LastName; player.Picture = String.IsNullOrEmpty(request.Picture) ? Configuration.GetValue <string>("DefaultPlayerLogo") : request.Picture; player.TeamId = request.TeamId; var updatedPlayer = await this.PlayerRepository.UpdateAsync(player); return(new OkObjectResult(updatedPlayer)); }
public Task <IActionResult> UpdateMyInstrument([FromBody] UpdatePlayerRequest request, int playerId) { request.playerId = playerId; return(this.HandleRequest <UpdatePlayerRequest, UpdatePlayerResponse>(request)); }
public async Task <ActionResult <CreatePlayerResponse> > UpdatePlayer([FromRoute] int playerId, [FromBody] UpdatePlayerRequest createPlayerRequest, CancellationToken cancellationToken) { var player = await _playersRepository.GetByIdAsync(playerId, cancellationToken); if (player != null) { player.Name = createPlayerRequest.Name; player.Surname = createPlayerRequest.Surname; player.Role = PlayerRole.GetByAcronym(createPlayerRequest.RoleAcronym); await _playersRepository.UpdateAsync(player, cancellationToken); var response = new CreatePlayerResponse { Player = _mapper.Map <PlayerDto>(player) }; return(Ok(response)); } else { return(NotFound()); } }