Example #1
0
        public async System.Threading.Tasks.Task <bool> setWinner(SetWinnerReq swq)
        {
            HttpResponseMessage response = await client.PostAsJsonAsync("api/setWinner", swq);

            await adminreflashGameListAsync();

            return(response.IsSuccessStatusCode);
        }
Example #2
0
        public async System.Threading.Tasks.Task <bool> DeleteLtopic(int id)
        {
            SetWinnerReq swq = new SetWinnerReq();

            swq.topicSn = id;
            HttpResponseMessage response = await client.PostAsJsonAsync("api/DeleteLive/", swq);

            await adminreflashGameListAsync();

            return(response.IsSuccessStatusCode);
        }
        public IHttpActionResult DeleteLive(SetWinnerReq swq)
        {
            bool isOK = new GameRepository().DeleteLtopic(swq.topicSn);

            if (!isOK)
            {
                return(NotFound());
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult setWinner(SetWinnerReq swq)
        {
            user u = db.users.Where(p => p.userID == swq.UserID && p.comSn == swq.comSn).FirstOrDefault();

            if (u == null)
            {
                return(BadRequest("UserID不存在"));
            }
            GameRepository gr = new GameRepository();

            gr.setWinner(swq.choiceList);
            gr.setGameCloseStatus(swq.gameSn, 4);
            return(Ok());
        }
Example #5
0
        public async System.Threading.Tasks.Task <gameDto> EditLive(int id, gameDto game)
        {
            game.comSn = 1;
            SetWinnerReq swq = new SetWinnerReq();

            swq.gameSn = id;
            swq.game   = game;
            HttpResponseMessage response = await client.PostAsJsonAsync("api/PutgameLive/", swq);

            await adminreflashGameListAsync();

            game = await reLiveGameListAsync(game.sn);

            return(game);
        }
Example #6
0
        /*public async System.Threading.Tasks.Task<gameDto> GetGameLiveDetail(int id)
         * {
         *  gameDto game = null;
         *  HttpResponseMessage response = await client.GetAsync("api/gamesLive/" + id);
         *  if (response.IsSuccessStatusCode)
         *  {
         *      game = await response.Content.ReadAsAsync<gameDto>();
         *  }
         *  //game = (await GetGameList()).Where(p => p.sn == id).FirstOrDefault();
         *  return game;
         * }*/

        public async System.Threading.Tasks.Task <gameDto> GetGamePayDetail(int id)
        {
            gameDto      game = null;
            SetWinnerReq swq  = new SetWinnerReq();

            swq.gameSn = id;
            HttpResponseMessage response = await client.PostAsJsonAsync("api/gamesPay/", swq);

            var result = await response.Content.ReadAsStringAsync();

            JavaScriptSerializer json_serializer = new JavaScriptSerializer();

            game = json_serializer.Deserialize <gameDto>(result);
            response.EnsureSuccessStatusCode();

            //await reflashGameListAsync();

            return(game);
        }
        public IHttpActionResult PutgameLive(SetWinnerReq swq)
        {
            /* if (!ModelState.IsValid)
             * {
             *   return BadRequest(ModelState);
             * }*/

            if (swq.game.sn != swq.gameSn)
            {
                return(BadRequest());
            }
            bool isOK = new GameRepository().SetGameLive(swq.gameSn, swq.game);

            if (!isOK)
            {
                return(NotFound());
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #8
0
        public async System.Threading.Tasks.Task <aJaxDto> setWinnerPay(SetWinnerReq swq)
        {
            aJaxDto             ajd      = new aJaxDto();
            HttpResponseMessage response = await client.PostAsJsonAsync("api/setLiveWinnerPay", swq);

            if (response.IsSuccessStatusCode)
            {
                List <payoutDto> payoutList = await response.Content.ReadAsAsync <List <payoutDto> >();

                new AssetsRepository().AddLiveAssetsByPay(payoutList);
                ajd.isTrue = true;
                await reflashGameListAsync();
            }
            else
            {
                ajd.isTrue    = false;
                ajd.ErrorCode = 500;
                ajd.ErrorMsg  = response.ReasonPhrase;
            }
            // await reflashGameListAsync();
            return(ajd);
        }
        public IHttpActionResult setLiveWinnerPay(SetWinnerReq swq)
        {
            user u = db.users.Where(p => p.userID == swq.UserID && p.comSn == swq.comSn).FirstOrDefault();

            if (u == null)
            {
                return(BadRequest("UserID不存在"));
            }
            GameRepository gr = new GameRepository();

            gr.setLiveWinner(swq.choiceList);

            byte?gameclosestatus = gr.getGameCloseStatus(swq.gameSn);

            gr.ChangeGameValid(swq.topicSn);
            List <payoutDto> payoutList = gr.livepays(swq.gameSn);

            return(Ok(payoutList));

            //gr.setGameCloseStatus(swq.gameSn, 4);
            // return Ok();
        }
        public async System.Threading.Tasks.Task <string> CSGOSetAnswer(int gpid, List <CSGOGame.RootObject> cslist, CSGOMatches.RootObject csgetm)
        {
            try
            {
                GamePosts gamepost = new GamePostsRepository().get(gpid);
                gameDto   game     = null;
                game = await new GamesRepository().GetGameDetail(gamepost.GameSn);

                GamePostViewModel gpvm = new GamePostViewModel(gpid, encryptedKey, game);
                gpvm.gamepost = gamepost;

                // game = await new GamesRepository().GetGameDetail(gamepost.GameSn);


                gameDto         gd     = null;
                GamesRepository _games = new GamesRepository();
                gd = await _games.GetGameDetail(gpvm.game.sn);



                if (1 == 1)
                {
                    List <choiceDto> choice = new List <choiceDto>();
                    foreach (topicDto t in gpvm.game.topicList)
                    {
                        foreach (var c in t.choiceList)
                        {
                            //1:哪隊會獲得勝利 2:總地圖數奇/偶 3:第一個地圖勝利隊伍 4:第二個地圖勝利隊伍 5:總地圖數會高於還是低於x.5 6:第一個地圖總回合數奇/偶 7:第二個地圖總回合數奇/偶
                            switch (t.autotype)
                            {
                            case 1:
                                if (csgetm.winner == null)
                                {
                                    if (c.cNumberType == 3)
                                    {
                                        c.isTrue = 1;
                                    }
                                    else
                                    {
                                        c.isTrue = 0;
                                    }
                                }
                                else
                                {
                                    if (csgetm.winner.name == c.choiceStr)
                                    {
                                        c.isTrue = 1;
                                    }
                                    else
                                    {
                                        c.isTrue = 0;
                                    }
                                }


                                break;

                            case 2:
                                if (cslist.Count() % 2 == 0 && c.cNumberType == 1)
                                {
                                    c.isTrue = 1;
                                }
                                else if (cslist.Count() % 2 != 0 && c.cNumberType == 0)
                                {
                                    c.isTrue = 1;
                                }
                                else
                                {
                                    c.isTrue = 0;
                                }
                                break;

                            case 3:
                                CSGOTeam.RootObject wteam = await new CSGORepository().GetCSGOTeam((int)csgetm.games[0].winner.id);
                                if (wteam.name == c.choiceStr)
                                {
                                    c.isTrue = 1;
                                }
                                else
                                {
                                    c.isTrue = 0;
                                }
                                break;

                            case 4:
                                wteam = await new CSGORepository().GetCSGOTeam((int)csgetm.games[1].winner.id);
                                if (wteam.name == c.choiceStr)
                                {
                                    c.isTrue = 1;
                                }
                                else
                                {
                                    c.isTrue = 0;
                                }
                                break;

                            case 5:
                                if (cslist.Count() < t.numberType && c.cNumberType == 1)
                                {
                                    c.isTrue = 1;
                                }
                                else if (cslist.Count() > t.numberType && c.cNumberType == 0)
                                {
                                    c.isTrue = 1;
                                }
                                else
                                {
                                    c.isTrue = 0;
                                }
                                break;

                            case 6:
                                if (cslist[0].rounds.Count() % 2 == 0 && c.cNumberType == 1)
                                {
                                    c.isTrue = 1;
                                }
                                else if (cslist[0].rounds.Count() % 2 != 0 && c.cNumberType == 0)
                                {
                                    c.isTrue = 1;
                                }
                                else
                                {
                                    c.isTrue = 0;
                                }
                                break;

                            case 7:
                                if (cslist[1].rounds.Count() % 2 == 0 && c.cNumberType == 1)
                                {
                                    c.isTrue = 1;
                                }
                                else if (cslist[1].rounds.Count() % 2 != 0 && c.cNumberType == 0)
                                {
                                    c.isTrue = 1;
                                }
                                else
                                {
                                    c.isTrue = 0;
                                }
                                break;

                            default:
                                Console.WriteLine("error");
                                break;
                            }
                        }

                        if (t.choiceList.Where(x => x.isTrue == 1).Count() == 0)
                        {
                            gpvm.game.gameStatus = 2;
                            gpvm.gamepost.pay    = 5;
                            await new gameController().AutoEdit(gpvm);
                            rebearpage(gpvm.game.sn);
                            throw new Exception("error");
                        }
                        else
                        {
                            choice.AddRange(t.choiceList);
                        }
                    }



                    bool haveTrue  = false;
                    bool allReturn = true;
                    foreach (choiceDto cho in choice)
                    {
                        if (cho.isTrue.HasValue && cho.isTrue == 1)
                        {
                            haveTrue = true;
                        }
                        if (cho.isTrue != 2)
                        {
                            allReturn = false;
                        }
                    }
                    if (haveTrue || allReturn)
                    {
                        SetWinnerReq swq = new SetWinnerReq();
                        swq.UserID     = new AccountRepository().getUserEmail("*****@*****.**").Id;
                        swq.comSn      = 1;
                        swq.choiceList = choice;
                        swq.gameSn     = gpvm.game.sn;
                        bool issuccess = await _games.setWinner(swq);

                        if (!issuccess)
                        {
                            return("系統設定出錯");
                        }
                        new SignalRHelper().UpdateTopic(gpvm.game, encryptedKey, gpvm.game.md5GameSn);

                        rebearpage(gpvm.game.sn);
                    }
                    else
                    {
                        return("未設定設定結果");
                    }
                }
                // Return the URI of the created resource.


                return("1");
            }
            catch
            {
                return("0");
            }
        }
        public async System.Threading.Tasks.Task <JsonResult> SetWinnerPay(GamePostViewModel gp, int topicSn)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            aJaxDto ajd = new aJaxDto();

            try
            {
                gameDto         gd     = null;
                GamesRepository _games = new GamesRepository();

                gameDto game = null;
                gd = await _games.GetGameDetail(gp.game.sn);

                gp.gamepost.edate   = gd.edate;
                gp.gamepost.sdate   = DateTime.Now;
                gp.gamepost.inpdate = DateTime.Now;
                gp.game.sdate       = DateTime.Now;
                gp.game.edate       = gd.gamedate;
                gp.game.gamedate    = gd.gamedate;

                for (int i = 0; i < gd.topicList.Count; i++)
                {
                    gp.game.topicList[i].sdate = gd.topicList[i].sdate;
                    gp.game.topicList[i].edate = gd.topicList[i].edate;
                }



                List <choiceDto> choice = new List <choiceDto>();
                foreach (topicDto t in gp.game.topicList)
                {
                    choice.AddRange(t.choiceList);
                }

                /*bool haveTrue = false;
                 * bool allReturn = true;
                 * foreach (choiceDto cho in choice)
                 * {
                 *  if (cho.isTrue.HasValue && cho.isTrue == 1)
                 *      haveTrue = true;
                 *  if (cho.isTrue != 2)
                 *      allReturn = false;
                 *
                 * }*/

                SetWinnerReq swq = new SetWinnerReq();
                swq.UserID     = gp.game.userId;
                swq.comSn      = 1;
                swq.choiceList = choice;
                swq.gameSn     = gp.game.sn;
                swq.topicSn    = topicSn;
                //ajd = await _games.pays(sbr, game.betModel);
                ajd = await _games.setWinnerPay(swq);

                new SignalRHelper().UpdateTopic(gp.game, encryptedKey, gp.game.md5GameSn);

                // Return the URI of the created resource.
            }
            catch
            {
                ajd.isTrue    = false;
                ajd.ErrorCode = 500;
            }

            return(Json(ajd, JsonRequestBehavior.AllowGet));
        }
        /* public async System.Threading.Tasks.Task<ActionResult> pyatest()
         * {
         *   var csgo = new GameAutoPayRepository().getCsgoList();
         *   foreach (var c in csgo)
         *   {
         *       CSGOMatches.RootObject getm = await new CSGORepository().GetCSGOMatches((int)c.AutoSn);
         *       var allgame = new List<CSGOGame.RootObject>();
         *       foreach (var m in getm.games)
         *       {
         *
         *           CSGOGame.RootObject getg = await new CSGORepository().GetCSGOGame(m.id);
         *           allgame.Add(getg);
         *       }
         *       await this.CSGOSetAnswer(c.sn, allgame, getm);
         *
         *
         *
         *
         *   }
         *
         *   return View();
         * }*/


        public async System.Threading.Tasks.Task <string> CSGOSetAnswer(int gpid, List <CSGOGame.RootObject> cslist, CSGOMatches.RootObject csgetm)
        {
            try
            {
                GamePosts gamepost = new GamePostsRepository().get(gpid);
                gameDto   game     = null;
                game = await new GamesRepository().GetGameDetail(gamepost.GameSn);

                GamePostViewModel gpvm = new GamePostViewModel(gpid, encryptedKey, game);
                gpvm.gamepost = gamepost;

                // game = await new GamesRepository().GetGameDetail(gamepost.GameSn);


                gameDto         gd     = null;
                GamesRepository _games = new GamesRepository();
                gd = await _games.GetGameDetail(gpvm.game.sn);



                if (1 == 1)
                {
                    List <choiceDto> choice = new List <choiceDto>();
                    foreach (topicDto t in gpvm.game.topicList)
                    {
                        /* foreach(var c in t.choiceList)
                         * {
                         *   //1:哪隊會獲得勝利 2:總地圖數奇/偶 3:第一個地圖勝利隊伍 4:第二個地圖勝利隊伍 5:總地圖數會高於還是低於x.5 6:第一個地圖總回合數奇/偶 7:第二個地圖總回合數奇/偶
                         *   switch (t.autotype)
                         *   {
                         *       case 1:
                         *           if (csgetm.winner.name == c.choiceStr)
                         *           {
                         *               c.isTrue = 1;
                         *           }
                         *           else
                         *           {
                         *               c.isTrue = 0;
                         *           }
                         *           break;
                         *       case 2:
                         *           if (cslist.Count() / 2 == 0 && c.cNumberType == 1)
                         *           {
                         *               c.isTrue = 1;
                         *           }
                         *           else if (cslist.Count() / 2 != 0 && c.cNumberType == 0)
                         *           {
                         *
                         *               c.isTrue = 1;
                         *           }
                         *           else
                         *           {
                         *               c.isTrue = 0;
                         *           }
                         *           break;
                         *       case 3:
                         *           CSGOTeam.RootObject wteam = await new CSGORepository().GetCSGOTeam(csgetm.games[0].winner.id);
                         *           if (wteam.name == c.choiceStr)
                         *           {
                         *               c.isTrue = 1;
                         *           }
                         *           else
                         *           {
                         *               c.isTrue = 0;
                         *           }
                         *           break;
                         *       case 4:
                         *           wteam = await new CSGORepository().GetCSGOTeam(csgetm.games[1].winner.id);
                         *           if (wteam.name == c.choiceStr)
                         *           {
                         *               c.isTrue = 1;
                         *           }
                         *           else
                         *           {
                         *               c.isTrue = 0;
                         *           }
                         *           break;
                         *       case 5:
                         *           if (cslist.Count() < t.numberType && c.cNumberType == 1)
                         *           {
                         *               c.isTrue = 1;
                         *           }
                         *           else if (cslist.Count() > t.numberType && c.cNumberType == 0)
                         *           {
                         *               c.isTrue = 1;
                         *           }
                         *           else
                         *           {
                         *               c.isTrue = 0;
                         *           }
                         *           break;
                         *       case 6:
                         *           if (cslist[0].rounds.Count() / 2 == 0 && c.cNumberType == 1)
                         *           {
                         *               c.isTrue = 1;
                         *           }
                         *           else if (cslist.Count() / 2 != 0 && c.cNumberType == 0)
                         *           {
                         *
                         *               c.isTrue = 1;
                         *           }
                         *           else
                         *           {
                         *               c.isTrue = 0;
                         *           }
                         *           break;
                         *       case 7:
                         *           if (cslist[1].rounds.Count() / 2 == 0 && c.cNumberType == 1)
                         *           {
                         *               c.isTrue = 1;
                         *           }
                         *           else if (cslist.Count() / 2 != 0 && c.cNumberType == 0)
                         *           {
                         *
                         *               c.isTrue = 1;
                         *           }
                         *           else
                         *           {
                         *               c.isTrue = 0;
                         *           }
                         *           break;
                         *       default:
                         *           Console.WriteLine("error");
                         *           break;
                         *
                         *
                         *
                         *
                         *   }
                         *
                         *
                         * }*/

                        choice.AddRange(t.choiceList);
                    }

                    bool haveTrue  = false;
                    bool allReturn = true;
                    foreach (choiceDto cho in choice)
                    {
                        if (cho.isTrue.HasValue && cho.isTrue == 1)
                        {
                            haveTrue = true;
                        }
                        if (cho.isTrue != 2)
                        {
                            allReturn = false;
                        }
                    }
                    if (haveTrue || allReturn)
                    {
                        SetWinnerReq swq = new SetWinnerReq();
                        swq.UserID     = UserManager.FindByEmail("*****@*****.**").Id;
                        swq.comSn      = 1;
                        swq.choiceList = choice;
                        swq.gameSn     = gpvm.game.sn;
                        bool issuccess = await _games.setWinner(swq);

                        if (!issuccess)
                        {
                            return("系統設定出錯");
                        }
                        new SignalRHelper().UpdateTopic(gpvm.game, encryptedKey, gpvm.game.md5GameSn);
                    }
                    else
                    {
                        return("未設定設定結果");
                    }
                }
                // Return the URI of the created resource.


                return("1");
            }
            catch
            {
                return("0");
            }
        }
 public gameDto gamesLive(SetWinnerReq swq)
 {
     return(new GameRepository().GetLiveGameList(swq.gameSn).FirstOrDefault());
     //return new GameRepository().GetGameAdminList();
 }