Ejemplo n.º 1
0
        public static void Execute(CalculateGroupRequest request)
        {
            var turnamentId = Guid.Parse(request.TurnamentId);
            var command     = DbHelper.GetCommandForTurnament(turnamentId, false);

            if (command.Count < 6)
            {
                throw new ApplicationException("Ошибка: Минимальное колличество комманд для проведения турнира 6");
            }

            if (Math.Truncate(Convert.ToDecimal(command.Count / request.GroupCount)) < 3)
            {
                throw new ApplicationException("Ошибка: Невозможно разделить команды на заданное колличество групп");
            }

            for (int i = command.Count - 1; i >= 1; i--)
            {
                Random rand = new Random();
                int    j    = rand.Next(i + 1);
                var    temp = command[j];
                command[j] = command[i];
                command[i] = temp;
            }

            var g      = 0;
            var splits = from item in command
                         group item by g++ % request.GroupCount into part
                         select part.ToList();

            var groupCommand = splits.ToList();

            var groupsTurnament = DbHelper.CreateGroupForTurnament(turnamentId, groupCommand.Count);

            g = 0;
            groupCommand.ForEach(x => {
                DbHelper.CreatePositionCommand(x, groupsTurnament[g].id_group_for_turnament);
                CreateTour(groupsTurnament[g].id_group_for_turnament);
                g++;
            });
        }
 public void CalculateGroup(CalculateGroupRequest request) => CalculateGroupBLL.Execute(request);