Ejemplo n.º 1
0
        public static GetMixedTurnamentResponse Execute(ElementRequest request)
        {
            var turnamentId          = Guid.Parse(request.Txt);
            var turnament            = DbHelper.GetTurnament(turnamentId);
            var commands             = DbHelper.GetCommandForTurnament(turnamentId, true);
            var commandsForTurnament = new List <CommandForTurnament>();

            foreach (var command in commands)
            {
                var commandForTurnament = new CommandForTurnament
                {
                    Id     = command.Id,
                    Name   = command.Name,
                    Status = command.Status
                };

                commandsForTurnament.Add(commandForTurnament);
            }

            var turnamentGroups = turnament.step > 1 ? GetTurnamentGroupsBLL.Execute(turnamentId, true) : new List <TurnamentGroups>();
            var tuple           = GetPositionPlayOffBLL.Execute(turnamentId, true);

            var item = new MixedTurnamentAdmin
            {
                Id                     = turnament.id_turnament.ToString(),
                Name                   = turnament.name,
                DateStart              = turnament.date_start,
                DateEnd                = turnament.date_end,
                Type                   = turnament.type,
                StateCode              = turnament.state_code,
                Step                   = turnament.step,
                Description            = turnament.description,
                ContributionGame       = turnament.сontribution_game,
                ContributionTournament = turnament.сontribution_tournament,
                Commands               = commandsForTurnament,
                TurnamentGroups        = turnamentGroups,
                TurnamentPlayOff       = tuple.Item1,
                PositionPlayOff        = tuple.Item2
            };

            return(new GetMixedTurnamentResponse {
                Turnament = item
            });
        }
        public static GetTurnamentsForUserResponse Execute(string accountId)
        {
            var turnaments = DbHelper.GetTurnamentsForUser(Guid.Parse(accountId));

            var response = new GetTurnamentsForUserResponse {
                Turnaments = new List <Turnament>()
            };

            foreach (var item in turnaments)
            {
                var positionCommands = item.type == 1 ? GetPositionCommandBLL.Execute(item.id_turnament) : new List <PositionCommand>();
                var groupTourNumber  = item.type == 1 ? GetGroupTourNumberBLL.Execute(item.id_turnament, false) : new List <GroupTourNumber>();
                var turnamentGroups  = item.type == 2 ? GetTurnamentGroupsBLL.Execute(item.id_turnament, false) : new List <TurnamentGroups>();
                var turnamentPlayOff = new List <TurnamentPlayOff>();
                var positionPlayOff  = new List <List <PositionCommand> >();

                if (item.type == 2)
                {
                    var tuple = GetPositionPlayOffBLL.Execute(item.id_turnament, false);
                    turnamentPlayOff = tuple.Item1;
                    positionPlayOff  = tuple.Item2;
                }

                var commands             = DbHelper.GetCommandForTurnament(item.id_turnament, true);
                var commandsForTurnament = new List <CommandForTurnament>();

                foreach (var command in commands)
                {
                    var commandForTurnament = new CommandForTurnament
                    {
                        Name   = command.Name,
                        Status = command.Status
                    };

                    commandsForTurnament.Add(commandForTurnament);
                }

                groupTourNumber.Sort((a, b) => a.NumberTour <= b.NumberTour ? -1 : 1);

                var turnament = new Turnament
                {
                    Id = item.id_turnament.ToString(),
                    ContributionGame       = item.сontribution_game,
                    ContributionTournament = item.сontribution_tournament,
                    DateEnd          = item.date_end == null ? null : item.date_end.Value.ToShortDateString(),
                    DateStart        = item.date_start == null ? null : item.date_start.Value.ToShortDateString(),
                    Description      = item.description,
                    Name             = item.name,
                    Commands         = commandsForTurnament,
                    Type             = item.type,
                    PositionCommand  = positionCommands,
                    GroupTourNumber  = groupTourNumber,
                    TurnamentGroups  = turnamentGroups,
                    TurnamentPlayOff = turnamentPlayOff,
                    PositionPlayOff  = positionPlayOff
                };

                response.Turnaments.Add(turnament);
            }
            ;

            return(response);
        }