Beispiel #1
0
        /// <summary>
        /// Edits a <see cref="Game"/> entity in the data store.
        /// </summary>
        /// <param name="newGame">The <see cref="Game"/> entity containing data to add to the data store.</param>
        /// <param name="oldGame">The <see cref="Game"/> entity containing data to remove from the data store.</param>
        public void EditGame(Game newGame, Game oldGame)
        {
            Guard.ThrowIfNull(newGame, $"{GetType()}.{nameof(EditGame)}: {nameof(newGame)}");
            Guard.ThrowIfNull(oldGame, $"{GetType()}.{nameof(EditGame)}: {nameof(oldGame)}");

            var selectedGame = _gameRepository.GetGame(oldGame.ID);

            if (selectedGame is null)
            {
                throw new EntityNotFoundException(
                          $"{GetType()}.{nameof(EditGame)}: The selected Game entity could not be found.");
            }

            var newGameDecorator = new GameDecorator(newGame);

            newGameDecorator.DecideWinnerAndLoser();

            var selectedGameDecorator = new GameDecorator(selectedGame);

            selectedGameDecorator.Edit(newGameDecorator);

            _gameRepository.Update(selectedGame);

            var oldGameDecorator = new GameDecorator(oldGame);

            EditTeams(Direction.Down, oldGameDecorator);
            EditTeams(Direction.Up, newGameDecorator);

            _sharedRepository.SaveChanges();
        }
Beispiel #2
0
        /// <summary>
        /// Adds a <see cref="Game"/> entity to the data store asynchronously.
        /// </summary>
        /// <param name="newGame">The <see cref="Game"/> entity to add to the data store.</param>
        public async Task AddGameAsync(Game newGame)
        {
            Guard.ThrowIfNull(newGame, $"{GetType()}.{nameof(AddGameAsync)}: {nameof(newGame)}");

            var newGameDecorator = new GameDecorator(newGame);

            newGameDecorator.DecideWinnerAndLoser();

            await _gameRepository.AddAsync(newGame);

            await EditTeamsAsync(Direction.Up, newGameDecorator);

            await _sharedRepository.SaveChangesAsync();
        }
Beispiel #3
0
        /// <summary>
        /// Adds a <see cref="Game"/> entity to the data store.
        /// </summary>
        /// <param name="newGame">The <see cref="Game"/> entity to add to the data store.</param>
        public void AddGame(Game newGame)
        {
            Guard.ThrowIfNull(newGame, $"{GetType()}.{nameof(AddGame)}: {nameof(newGame)}");

            var newGameDecorator = new GameDecorator(newGame);

            newGameDecorator.DecideWinnerAndLoser();

            _gameRepository.Add(newGame);

            EditTeams(Direction.Up, newGameDecorator);

            _sharedRepository.SaveChanges();
        }