Beispiel #1
0
        private SetEntity ValidateAddGoalToSetCommand(AddGoalToSetCommand command)
        {
            if (command.GameId == Guid.Empty)
            {
                throw new Exception($"{nameof(command.GameId)} cannot be empty!");
            }

            if (command.SetId == Guid.Empty)
            {
                throw new Exception($"{nameof(command.SetId)} cannot be empty!");
            }

            var set = _dbContext.Sets.SingleOrDefault(s => s.Id == command.SetId && s.ParentId == command.GameId);

            if (set == null)
            {
                throw new Exception($"The set '{command.SetId}' for the game '{command.GameId}' was not found!");
            }

            if (set.FirstTeamResult == MaxGoals || set.SecondTeamResult == MaxGoals)
            {
                throw new Exception($"The set '{command.SetId}' for the game '{command.GameId}' has already been finished");
            }

            return(set);
        }
Beispiel #2
0
        public async Task Execute(AddGoalToSetCommand command)
        {
            var set = ValidateAddGoalToSetCommand(command);

            if (command.FirstTeam)
            {
                set.FirstTeamResult++;
            }

            if (command.SecondTeam)
            {
                set.SecondTeamResult++;
            }

            await _dbContext.SaveChangesAsync();
        }