예제 #1
0
        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);
            }
        }
예제 #2
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)));
        }
예제 #3
0
        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)));
        }
예제 #4
0
        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)));
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }