示例#1
0
        public static void SetGameTeamList(Game game)
        {
            GetGameTeamListFilter filter = new GetGameTeamListFilter {
                GameId = game.Id, PageIndex = 1, PageSize = 10
            };
            var teamListResult = GameHelper.GetGameTeamList(filter);

            if (teamListResult.Entities.IsNotNullOrEmpty())
            {
                game.GameTeamList = teamListResult.Entities.ToList <EntityBase, GameTeam>();
            }
        }
示例#2
0
        /// <summary>
        /// 获取比赛报名队列表(包含排名,积分,轮次)
        /// </summary>
        /// <param name="currentUser">忽略</param>
        /// <param name="request">Request.GetGameTeamListFilter.Filter</param>
        /// <returns>Response.GameTeam</returns>
        public Response Execute(string request)
        {
            var req = JsonConvert.DeserializeObject <Request <GetGameTeamListFilter> >(request);

            //var cmd = CommandHelper.CreateProcedure<GameTeam>(text: "sp_GetGameTeamList1");
            //cmd.Params.Add(CommandHelper.CreateParam("@GameId", req.Filter.GameId));
            //cmd.Params.Add(CommandHelper.CreateParam("@teamName", req.Filter.TeamName));

            //var result = DbContext.GetInstance().Execute(cmd);
            //return result;

            return(GameHelper.GetGameTeamList(req.Filter));
        }
示例#3
0
        /// <summary>
        /// 定义首轮,并自动创建剩下轮次,可以形成拓扑图(小组赛不创建,创建淘汰赛轮次的所有比赛,附加赛)
        /// </summary>
        /// <param name="request">Request.GameOrder.Entities</param>
        /// <returns>Response.EmptyEntity</returns>
        public Response Execute(User currentUser, string request)
        {
            var req = JsonConvert.DeserializeObject <Request <GameOrder> >(request);

            var firstOrder = req.FirstEntity();

            if (firstOrder.RowState == RowState.Added)
            {
                firstOrder.SetNewId();
                firstOrder.SetCreateDate();
                firstOrder.State = GameOrderState.NOTSTART.Id;
            }
            var entities = new List <EntityBase> {
                firstOrder
            };

            var game = GameHelper.GetGame(firstOrder.GameId);

            //设置第一轮KnockoutOption
            firstOrder.IsTeam         = game.IsTeam;
            firstOrder.KnockoutOption = game.KnockoutOption == KnockoutOption.ROUND_KNOCKOUT.Id ? KnockoutOption.ROUND.Id : game.KnockoutOption;

            if (game.KnockoutOption == KnockoutOption.ROUND.Id)
            {
                //单循环赛
                var filter = new GetGameTeamListFilter {
                    GameId = game.Id, PageIndex = 1, PageSize = 10000
                };
                var teamList = GameHelper.GetGameTeamList(filter).Entities.ToList <EntityBase, GameTeam>();
                if (teamList.Count < 2)
                {
                    return(ResultHelper.Fail("至少2支参赛队才能建立单循环赛!"));
                }
                CreateSingleRound(firstOrder, entities, game, teamList);
            }
            else
            {
                //单淘汰赛,先循环后淘汰赛

                //设置AB模式选项
                firstOrder.SetKnockOutAB(game.IsKnockOutAB);

                //验证数据
                var valResult = Validate(game, firstOrder);
                if (!valResult.IsSuccess)
                {
                    return(ResultHelper.Fail(valResult.Message));
                }

                //设置第一轮数据
                int orderNo = 1;//大轮次序号,从1开始
                firstOrder.OrderNo = orderNo;
                firstOrder.Name    = string.Format(firstOrder.KnockoutOption == KnockoutOption.ROUND.Id ? "小组赛" : "1/{1}决赛", firstOrder.OrderNo, firstOrder.GroupCount);

                //创建轮次,正常比赛,附加赛,合并数据
                var loopEntities  = new List <EntityBase>();
                var groupEntities = new List <EntityBase>();
                var extraEntities = new List <EntityBase>();
                CreateMoreOrderAndLoop(req, entities, firstOrder, game, orderNo, loopEntities, groupEntities);

                //初始化轮次计分模式
                entities.ForEach(p => (p as GameOrder).TeamScoreMode = TeamScoreMode.STANDARD.Id);

                if (firstOrder.TopNumber > 0)
                {
                    //决出名次验证
                    if (entities.Count < Math.Log(firstOrder.TopNumber, 2))
                    {
                        return(ResultHelper.Fail("决出名次大于轮次可决出名次。"));
                    }
                    CreateExtraGame(game, entities, firstOrder.TopNumber, extraEntities);
                }
                MergeData(entities, loopEntities, groupEntities, extraEntities);
            }
            //创建保存命令,并加入删除之前数据命令
            var cmdDelete = CommandHelper.CreateProcedure(FetchType.Execute, "sp_DeleteGameAllDetail");

            cmdDelete.Params.Add("@gameId", firstOrder.GameId);

            var cmdSave = CommandHelper.CreateSave(entities);

            cmdSave.PreCommands.Add(cmdDelete);

            return(DbContext.GetInstance().Execute(cmdSave));
        }