Exemplo n.º 1
0
        public Response Execute(string request)
        {
            string updateSql = @"UPDATE GameTeamLoopTemplet SET IsEnable=@isEnable WHERE Id=@templetId";
            var    req       = JsonConvert.DeserializeObject <Request <GameTeamLoopTemplet> >(request);
            var    templet   = req.Entities[0] as GameTeamLoopTemplet;
            var    cmd       = CommandHelper.CreateText(FetchType.Execute, updateSql);

            cmd.Params.Add("@templetId", templet.Id);
            cmd.Params.Add("@isEnable", templet.IsEnable);
            var res = DbContext.GetInstance().Execute(cmd);

            if (res.IsSuccess && !templet.IsEnable)
            {
                res.Tag = GameLoopTempletHelper.IsUseTemplet(templet.Id);//停用模板,假如被赛事使用过,则返回true
                ///res.Message = "可删除此模板,需要删除吗?";
            }
            else
            {
                res.Tag = false;
            }

            return(res);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取某个团体对阵模板及规则详情
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public static Response GetTempletDetail(GameTeamLoopTempletFilter filter)
        {
            string  sqlStr = @"SELECT a.*,CASE WHEN ISNULL(b.PetName, '')='' THEN b.CardName ELSE b.PetName END AS SharePerson,
                             CAST(CASE WHEN a.UseCount >=5 THEN 1 ELSE 0 END AS BIT) AS IsEnableShare 
                             FROM GameTeamLoopTemplet AS a LEFT JOIN UserAccount AS b ON a.SharePersonId=b.Id
                             WHERE a.Id=@templetId";
            Command cmd    = CommandHelper.CreateText <GameTeamLoopTemplet>(FetchType.Fetch, sqlStr);

            cmd.Params.Add("@templetId", filter.TempletId);
            Response res = DbContext.GetInstance().Execute(cmd);

            if (res.Entities.Count > 0)
            {
                var temp = res.Entities[0] as GameTeamLoopTemplet;
                if (temp.UseCount > 0)
                {
                    temp.UseDes = "已被" + temp.UseCount + "场比赛使用";
                }
                else
                {
                    temp.UseDes = "还未正式被比赛使用过";
                }
                temp.IsUse = GameLoopTempletHelper.IsUseTemplet(filter.TempletId);                //模板是否使用
                sqlStr     = @"SELECT * FROM GameTeamLoopTempletDetail WHERE TempletId=@templetId ORDER BY OrderNo ";
                if (!string.IsNullOrEmpty(filter.GameId) && !string.IsNullOrEmpty(filter.LoopId)) //进入团体对阵页面时,获取规则对员对阵详情
                {
                    sqlStr = @"SELECT a.*,b.User1Name,b.User1Id,b.User2Name,b.User2Id FROM GameTeamLoopTempletDetail AS a LEFT JOIN GameLoopMap AS b ON a.OrderNo=b.OrderNo AND b.LoopId=@loopId
                               WHERE a.TempletId=@templetId ORDER BY a.OrderNo";
                }
                cmd = CommandHelper.CreateText <GameTeamLoopTempletDetail>(FetchType.Fetch, sqlStr);
                cmd.Params.Add("@templetId", filter.TempletId);
                if (!string.IsNullOrEmpty(filter.GameId) && !string.IsNullOrEmpty(filter.LoopId))
                {
                    cmd.Params.Add("@loopId", filter.LoopId);
                }
                Response res1 = DbContext.GetInstance().Execute(cmd);
                temp.Detail = res1.Entities.ToList <EntityBase, GameTeamLoopTempletDetail>();
                if (!string.IsNullOrEmpty(filter.GameId) && !string.IsNullOrEmpty(filter.LoopId))//进入团体对阵页面时,获取规则编码与队员映射关系
                {
                    sqlStr = @"SELECT a.Id,a.TempletId,a.GameId,a.LoopId,a.TeamId,a.Code,a.CodeUserId,a.CodeUserName,a.CreateDate,b.TeamName  
                              FROM GameTeamLoopTempletMap as a LEFT JOIN GameTeam as b ON a.TeamId=b.Id 
                              WHERE a.TempletId=@templetId AND a.GameId=@gameId AND a.LoopId=@loopId ORDER BY TeamId,a.Code";
                    cmd    = CommandHelper.CreateText <GameTeamLoopTempletMap>(FetchType.Fetch, sqlStr);
                    cmd.Params.Add("@templetId", filter.TempletId);
                    cmd.Params.Add("@gameId", filter.GameId);
                    cmd.Params.Add("@loopId", filter.LoopId);
                    res1            = DbContext.GetInstance().Execute(cmd);
                    temp.Map        = res1.Entities.ToList <EntityBase, GameTeamLoopTempletMap>();//规则编码与队员映射关系
                    temp.Team1Codes = GameLoopTempletHelper.GetRuleCodes(temp.PersonCount, true, false);
                    if (temp.IsGuest)
                    {
                        temp.Team2Codes = GameLoopTempletHelper.GetRuleCodes(temp.PersonCount, false, false);
                    }
                    else
                    {
                        temp.Team2Codes = GameLoopTempletHelper.GetRuleCodes(temp.PersonCount, true, false);
                    }
                }
            }
            return(res);
        }
Exemplo n.º 3
0
        public Response Execute(User currentUser, string request)
        {
            var req = JsonConvert.DeserializeObject <Request <GameTeamLoopTemplet> >(request);
            GameTeamLoopTemplet templet = req.FirstEntity();
            Response            res     = null;
            Command             cmd     = null;

            if (templet.RowState == RowState.Added || templet.RowState == RowState.Modified)
            {
                if (templet.PersonCount <= 0 || templet.PersonCount > 9)
                {
                    return(ResultHelper.Fail("上场人数不超过9人"));
                }
                if (templet.LoopCount <= 0 || templet.LoopCount > 9)
                {
                    return(ResultHelper.Fail("总对阵场数不超过9场"));
                }
            }

            if (templet.RowState == RowState.Added)//新增,
            {
                //假如上传基于模板ID,判断是否基于已有模板创建,不检查同名
                if (string.IsNullOrEmpty(templet.Id))
                {
                    if (GameLoopTempletHelper.IsExistTemplet(templet.Name, false))
                    {
                        return(ResultHelper.Fail("对阵模板重名"));
                    }
                }
                else
                {
                    templet.Name = GameLoopTempletHelper.GetNewTempletName(templet.Name);//模板名称基于上个模板递增序号
                }

                if (templet.Detail.Count <= 0)
                {
                    return(ResultHelper.Fail("缺少模板规则"));
                }
                templet.SetNewEntity();
                res     = AddTemplet(templet, currentUser, true);
                res.Tag = false;
                res.Entities.Add(templet);
                return(res);
            }
            else
            {
                GameTeamLoopTemplet temp = GameLoopTempletHelper.GetTemplet(templet.Id);//获取对阵模板对象
                if (temp.CreatorId != currentUser.Id)
                {
                    return(ResultHelper.Fail("不能修改或删除非自己创建的模板"));
                }

                if (templet.RowState == RowState.Modified)              //修改
                {
                    if (GameLoopTempletHelper.IsUseTemplet(templet.Id)) //模板在使用中,直接按内容新建模板
                    {
                        templet.SetNewEntity();
                        templet.RowState = RowState.Added;
                        templet.Name     = GameLoopTempletHelper.GetNewTempletName(templet.Name);
                        res = AddTemplet(templet, currentUser, true);
                        if (res.IsSuccess)
                        {
                            res.Message = "模板在使用中,已保存为新的模板【" + templet.Name + "】";
                            res.Tag     = true;//修改正在使用的模板保存,些值为true
                        }


                        return(res);
                    }
                    ///先删除对应模板ID所有的规则详情
                    string delSql = @"DELETE FROM GameTeamLoopTempletDetail WHERE TempletId=@templetId";
                    cmd = CommandHelper.CreateText(FetchType.Execute, delSql);
                    cmd.Params.Add("@templetId", templet.Id);
                    DbContext.GetInstance().Execute(cmd);

                    ////////////////////////////////////////////////////////////
                    var entities = GameLoopTempletHelper.GetTemplets(templet.Name);//通过新名称检查模板
                    if (entities.Count > 0)
                    {
                        var temp1 = entities[0] as GameTeamLoopTemplet;
                        if (temp1.Id != templet.Id)//假如有同名但是模板id与修改的模板ID不同
                        {
                            return(ResultHelper.Fail("已存在相同名称对阵模板"));
                        }
                    }
                    templet.SetCreateDate();
                    res     = AddTemplet(templet, currentUser, false);
                    res.Tag = false;
                }
                else if (templet.RowState == RowState.Deleted)//删除
                {
                    if (GameLoopTempletHelper.IsUseTemplet(templet.Id))
                    {
                        res     = ResultHelper.Fail("模板已被使用,不能删除");
                        res.Tag = false;
                        return(res);
                    }
                    string delSql = @"DELETE FROM GameTeamLoopTemplet WHERE Id=@templetId  DELETE FROM GameTeamLoopTempletDetail WHERE TempletId=@templetId";
                    cmd = CommandHelper.CreateText(FetchType.Execute, delSql);
                    cmd.Params.Add("@templetId", templet.Id);
                    res     = DbContext.GetInstance().Execute(cmd);
                    res.Tag = false;
                }
            }

            return(res);
        }