public async System.Threading.Tasks.Task <JsonResult> ReLiveData(GamePostViewModel gpvm)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            gpvm.game = await new GamesRepository().reLiveGameListAsync(gpvm.gamepost.GameSn);


            return(Json(gpvm, JsonRequestBehavior.AllowGet));
        }
        public ActionResult _bonusEdit(gameDto model, int?index)
        {
            ViewBag.Index = index;
            GamePostViewModel gpvm = new GamePostViewModel {
                game = model, vedio = new VedioRecord()
            };

            return(View(gpvm));
        }
        public ActionResult _DPchoiceEdit(gameDto model, int topicIndex, int index)
        {
            ViewBag.Index      = index;
            ViewBag.topicIndex = topicIndex;
            GamePostViewModel gpvm = new GamePostViewModel {
                game = model, vedio = new VedioRecord()
            };

            return(View(gpvm));
        }
        public ActionResult _DPtopicEdit(gameDto model, int index)
        {
            //ViewBag.Index = index;

            //index = index ?? 0;
            ViewBag.Index = index;
            GamePostViewModel gpvm = new GamePostViewModel {
                game = model, vedio = new VedioRecord()
            };

            return(View(gpvm));
        }
        public async System.Threading.Tasks.Task <ActionResult> _Live()
        {
            string[,] gp = new string[30, 4] {
                { "(官方頻道分享) T1", "https://www.twitch.tv/team/sktt1", "sktt1", "英雄聯盟" },
                { "(官方頻道分享) Riot", "https://www.twitch.tv/riotgames", "riotgames", "英雄聯盟" },
                { "(官方頻道分享) Garena", "https://www.twitch.tv/garenatw", "garenatw", "英雄聯盟" },
                { "(官方頻道分享) LCK", "https://www.twitch.tv/lck_korea", "lck_korea", "英雄聯盟" },
                { "(官方頻道分享) Ahq", "https://www.twitch.tv/ahqesportsclub/", "ahqesportsclub", "英雄聯盟" },
                { "(官方頻道分享) Team Liquid", "https://www.twitch.tv/team/teamliquid", "teamliquid", "英雄聯盟" },
                { "(頻道分享) T1 Faker", "https://www.twitch.tv/faker/", "faker", "英雄聯盟" },
                { "(頻道分享) T1 Effort", "https://www.twitch.tv/effort", "effort", "英雄聯盟" },
                { "(頻道分享) T1 Khan", "https://www.twitch.tv/lol_khan", "lol_khan", "英雄聯盟" },
                { "(頻道分享) T1 Clid", "https://www.twitch.tv/clid", "clid", "英雄聯盟" },
                { "(頻道分享) T1 kkOma", "https://www.twitch.tv/kkoma", "kkoma", "英雄聯盟" },
                { "(頻道分享) T1 Haru", "https://www.twitch.tv/t1_haru/", "t1_harua", "英雄聯盟" },
                { "(頻道分享) T1 Teddy", "https://www.twitch.tv/t1_teddy", "t1_teddy", "英雄聯盟" },
                { "(頻道分享) T1 Leo", "https://www.twitch.tv/t1_leo", "t1_leo", "英雄聯盟" },
                { "(頻道分享) T1 Mata", "https://www.twitch.tv/mata", "mata", "英雄聯盟" },
                { "(頻道分享) AHQ Ziv", "https://www.twitch.tv/ziv_lol", "ziv_lol", "英雄聯盟" },
                { "(頻道分享) JT FOFO", "https://www.twitch.tv/fofo0108", "fofo0108", "英雄聯盟" },
                { "(頻道分享) TL Doublelift", "https://www.twitch.tv/doublelift/", "doublelift", "英雄聯盟" },
                { "(頻道分享) TL CoreJJ", "https://www.twitch.tv/corejj", "corejj", "英雄聯盟" },
                { "(頻道分享) TL Jensen", "https://www.twitch.tv/jensen/", "jensen", "英雄聯盟" },
                { "(頻道分享) TL Impact", "https://www.twitch.tv/tlimpact/", "tlimpact", "英雄聯盟" },
                { "(頻道分享) FNC Rekkles", "https://www.twitch.tv/rekkles", "rekkles", "英雄聯盟" },
                { "(頻道分享) FNC Broxah", "https://www.twitch.tv/broxah", "broxah", "英雄聯盟" },
                { "(頻道分享) G2 Jankos", "https://www.twitch.tv/jankos/", "jankos", "英雄聯盟" },
                { "(頻道分享) G2 Caps", "https://www.twitch.tv/caps/", "caps", "英雄聯盟" },
                { "(頻道分享) G2 Wunder", "https://www.twitch.tv/wunderlol", "wunderlol", "英雄聯盟" },
                { "(頻道分享) CG Huni", "https://www.twitch.tv/huni", "huni", "英雄聯盟" },
                { "(頻道分享) C9 Sneaky", "https://www.twitch.tv/c9sneaky", "c9sneaky", "英雄聯盟" },
                { "(頻道分享) SUP Wolf", "https://www.twitch.tv/lol_woolf/", "lol_woolf", "英雄聯盟" },
                { "(頻道分享) MaRin", "https://www.twitch.tv/marin000", "marin000", "英雄聯盟" },
            };
            List <GamePostViewModel> gpvmList = new List <GamePostViewModel>();

            for (int i = 0; i < 30; i++)
            {
                GamePostViewModel gpvm = new GamePostViewModel();
                //gpvm.vedio = vrlist.Where(p => p.sn == gp.VedioRecordSn).FirstOrDefault();
                gpvm.shorttitle         = gp[i, 0];
                gpvm.PlayGame.shortName = gp[i, 3];
                gpvm.vedio_url          = "https://player.twitch.tv/?channel=" + gp[i, 2];
                gpvm.href = gp[i, 1];
                gpvmList.Add(gpvm);
            }



            return(View(gpvmList));
        }
        public ActionResult _choiceStrEdit(gameDto model, int?index)
        {
            ViewBag.Index = index;
            GamePostViewModel gpvm = new GamePostViewModel {
                game = model, vedio = new VedioRecord()
            };

            // choiceOddsViewModel cov = new choiceOddsViewModel();
            // cov.unitSn = model.topicList[topicIndex].choiceList[choiceIndex].betMoney[index].unitSn;
            //cov.Odds = model.topicList[topicIndex].choiceList[choiceIndex].betMoney[index].Odds;
            //ViewBag.choiceOddsViewModel = cov;

            return(View(gpvm));
        }
        public async System.Threading.Tasks.Task <ActionResult> DPEdit(int id)
        {
            GamePosts gamepost = new GamePostsRepository().get(id);
            gameDto   game     = null;
            string    UserID   = User.Identity.GetUserId();

            game = await new GamesRepository().GetGameDetail(gamepost.GameSn);
            //if (game.userId != UserID)
            //    return View("Details", game);

            GamePostViewModel gpvm = new GamePostViewModel(id, encryptedKey, game);



            return(View(gpvm));
        }
        public async System.Threading.Tasks.Task <JsonResult> GetEdit(int id)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            GamePosts gamepost = new GamePostsRepository().get(id);
            gameDto   game     = null;
            string    UserID   = User.Identity.GetUserId();

            game = await new GamesRepository().reLiveGameListAsync(gamepost.GameSn);
            //if (game.userId != UserID)
            //    return View("Details", game);

            GamePostViewModel gpvm = new GamePostViewModel(id, encryptedKey, game);



            return(Json(gpvm, JsonRequestBehavior.AllowGet));
        }
        public async System.Threading.Tasks.Task <ActionResult> EditTopic(GamePostViewModel gpvm)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            //try
            //{
            int       iGamePostSn = gpvm.getGamePostSn(encryptedKey);
            GamePosts gp          = new GamePostsRepository().get(iGamePostSn);

            if (!string.IsNullOrEmpty(gpvm.vedio.vediourl))
            {
                gpvm.vedio.title   = (string.IsNullOrEmpty(gpvm.vedio.title) ? "" : gpvm.vedio.title);
                gpvm.vedio.comment = (string.IsNullOrEmpty(gpvm.vedio.comment) ? "" : gpvm.vedio.comment);
                gpvm.vedio.valid   = 1;
                gpvm.vedio.inpdate = DateTime.Now;
                List <cfgVedio> cvList = new cfgVedioRepository().getAll();
                gpvm.vedio.cfgVedioSn = 4;
                foreach (cfgVedio cv in cvList)
                {
                    Regex defaultRegex = new Regex(cv.RegularStr);
                    if (defaultRegex.Match(gpvm.vedio.vediourl).Success)
                    {
                        gpvm.vedio.cfgVedioSn = cv.sn;
                    }

                    /*
                     * List<string> includestr = cv.includeURL.Split(',').ToList();
                     * foreach (string str in includestr)
                     * {
                     *  if (includestr.Contains(str))
                     *  {
                     *      gpvm.vedio.cfgVedioSn = cv.sn;
                     *  }
                     * }
                     */
                }
            }
            VedioRecordRepository vrr = new VedioRecordRepository();

            if (gp.VedioRecordSn.HasValue)
            {
                VedioRecord vr = new VedioRecordRepository().get(gp.VedioRecordSn.Value);
                vr.cfgVedioSn = gpvm.vedio.cfgVedioSn;
                vr.vediourl   = gpvm.vedio.vediourl;
                vrr.update(vr);
                gpvm.vedio = vr;
            }
            else
            {
                if (!string.IsNullOrEmpty(gpvm.vedio.vediourl))
                {
                    vrr.add(gpvm.vedio);
                }
            }



            gameDto game = gpvm.game;

            var regame = await new GamesRepository().reLiveGameListAsync(gpvm.gamepost.GameSn);

            for (int i = 0; i < regame.topicList.Count; i++)
            {
                game.topicList[i].sdate = regame.topicList[i].sdate;
                game.topicList[i].edate = regame.topicList[i].edate;
            }
            game.comSn      = 1;
            game.sdate      = DateTime.Now;
            game.edate      = DateTime.Now.AddYears(100);
            game.gamedate   = DateTime.Now.AddYears(100);
            game.gameStatus = 0;
            game            = await new GamesRepository().EditLive(game.sn, game);


            if (gpvm.vedio != null && gpvm.vedio.sn != 0)
            {
                gp.VedioRecordSn = gpvm.vedio.sn;
            }

            gp.TeamASn    = gpvm.gamepost.TeamASn;
            gp.TeamBSn    = gpvm.gamepost.TeamBSn;
            gp.sdate      = DateTime.Now;
            gp.edate      = DateTime.Now.AddYears(100);
            gp.PlayGameSn = gpvm.gamepost.PlayGameSn;
            new GamePostsRepository().update(gp);

            gpvm.game = game;

            ///把新的topic推播到前端
            new SignalRHelper().UpdateTopic(game, encryptedKey, gpvm.md5GameSn);
            return(Json(gpvm, JsonRequestBehavior.AllowGet));
            //}
            //catch (Exception ex)
            //{
            //    return View(gpvm);
            //}
        }
        public async System.Threading.Tasks.Task <JsonResult> Edit(GamePostViewModel gpvm)
        {
            //try
            //{
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            int       iGamePostSn = gpvm.getGamePostSn(encryptedKey);
            GamePosts gp          = new GamePostsRepository().get(iGamePostSn);
            var       vedio       = new VedioRecord();

            if (gpvm.vedio == null)
            {
                gpvm.vedio = vedio;
            }

            if (gpvm.livename == "1")
            {
                gpvm.vedio.vediourl   = "https://www.twitch.tv/" + gpvm.live;
                gpvm.vedio.cfgVedioSn = 4;
            }
            else if (gpvm.livename == "2")
            {
                gpvm.vedio.vediourl   = gpvm.live;
                gpvm.vedio.cfgVedioSn = 5;
            }
            else
            {
                gpvm.vedio = vedio;
            }
            if (gpvm.vedio != null)
            {
                gpvm.vedio.title   = (string.IsNullOrEmpty(gpvm.vedio.title) ? "" : gpvm.vedio.title);
                gpvm.vedio.comment = (string.IsNullOrEmpty(gpvm.vedio.comment) ? "" : gpvm.vedio.comment);
                gpvm.vedio.valid   = 1;
                gpvm.vedio.inpdate = DateTime.Now;
            }
            VedioRecordRepository vrr = new VedioRecordRepository();

            if (gp.VedioRecordSn.HasValue)
            {
                VedioRecord vr = new VedioRecordRepository().get(gp.VedioRecordSn.Value);
                vr.cfgVedioSn = gpvm.vedio.cfgVedioSn;
                vr.vediourl   = gpvm.vedio.vediourl;
                vr.live       = gpvm.live;
                vrr.update(vr);
                gpvm.vedio = vr;
            }
            else
            {
                if (gpvm.vedio != null)
                {
                    vrr.add(gpvm.vedio);
                }
            }



            gameDto game   = gpvm.game;
            var     regame = await new GamesRepository().reLiveGameListAsync(gpvm.gamepost.GameSn);

            for (int i = 0; i < regame.topicList.Count; i++)
            {
                game.topicList[i].sdate = regame.topicList[i].sdate;
                game.topicList[i].edate = regame.topicList[i].edate;
            }
            game.comSn    = 1;
            game.sdate    = DateTime.Now;
            game.edate    = DateTime.Now.AddYears(100);
            game.gamedate = DateTime.Now.AddYears(100);
            game          = await new GamesRepository().EditLive(game.sn, game);


            if (gpvm.vedio != null && gpvm.vedio.sn != 0)
            {
                gp.VedioRecordSn = gpvm.vedio.sn;
            }

            gp.TeamASn = gpvm.gamepost.TeamASn;
            gp.TeamBSn = gpvm.gamepost.TeamBSn;
            gp.sdate   = DateTime.Now;
            gp.edate   = DateTime.Now.AddYears(100);
            var  cfpgame = new cfgPlayGameRepository().getAllLive();
            bool cf      = false;

            foreach (var cg in cfpgame)
            {
                if (cg.shortName == gpvm.PlayGame.shortName)
                {
                    cf            = true;
                    gp.PlayGameSn = cg.sn;
                }
            }

            if (!cf)
            {
                cfgPlayGame cfpg = new cfgPlayGame();

                cfpg.shortName = gpvm.PlayGame.shortName;
                cfpg.cName     = gpvm.PlayGame.shortName;
                cfpg.eName     = gpvm.PlayGame.shortName;
                cfpg.valid     = 2;
                gp.PlayGameSn  = new cfgPlayGameRepository().Create(cfpg);
            }

            new GamePostsRepository().update(gp);
            gpvm.gamepost = gp;
            gpvm.game     = game;

            ///把新的topic推播到前端
            new SignalRHelper().UpdateTopic(game, encryptedKey, gpvm.md5GameSn);
            return(Json(gpvm, JsonRequestBehavior.AllowGet));
            // return RedirectToAction(game.betDetails, new { id = gpvm.gamepost.sn });
            //}
            //catch (Exception ex)
            //{
            //    return View(gpvm);
            //}
        }
        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 <JsonResult> LivePayData(int id)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            GamePosts gamepost = new GamePostsRepository().get(id);
            gameDto   game     = null;

            game = await new GamesRepository().GetGamePayDetail(gamepost.GameSn);

            List <VedioRecord> vrlist = new List <VedioRecord>();

            vrlist = new VedioRecordRepository().getAll();


            GamePostViewModel gpvm = new GamePostViewModel(id, encryptedKey, game);

            gpvm.gamepost = gamepost;
            List <Teams> teamlist = new TeamsRepository().getAll();

            gpvm.TeamA = teamlist.Where(p => p.sn == gamepost.TeamASn).FirstOrDefault();
            gpvm.TeamB = teamlist.Where(p => p.sn == gamepost.TeamBSn).FirstOrDefault();
            if (gpvm.gamepost.PlayGameSn.HasValue)
            {
                gpvm.PlayGame = new cfgPlayGameRepository().get(gpvm.gamepost.PlayGameSn.Value);
            }
            gpvm.vedio = vrlist.Where(p => p.sn == gpvm.gamepost.VedioRecordSn).FirstOrDefault();


            //VedioRecord movieclass_twitch_string = new VedioRecordRepository().getnew(gp.VedioRecordSn);
            //var movieclass_twitch = gpvm.vedio.vediourl.Substring(0, 21);
            //string movieclass_youtube = gpvm.vedio.vediourl.Substring(0, 23);
            if (gpvm.vedio == null)
            {
                gpvm.vedio_url = "";
            }
            else
            {
                string movieclass_twitch  = "";
                string movieclass_youtube = "";
                string movieclass_huya    = "";
                if (gpvm.vedio.vediourl.Length >= 22)
                {
                    movieclass_twitch = gpvm.vedio.vediourl.Substring(0, 22);
                }
                if (gpvm.vedio.vediourl.Length >= 24)
                {
                    movieclass_youtube = gpvm.vedio.vediourl.Substring(0, 24);
                }
                if (gpvm.vedio.vediourl.Length >= 21)
                {
                    movieclass_huya = gpvm.vedio.vediourl.Substring(0, 21);
                }

                if (movieclass_twitch == "https://www.twitch.tv/")
                {
                    gpvm.vedio_url = Regex.Replace(gpvm.vedio.vediourl, movieclass_twitch, String.Empty);
                    gpvm.vedio_url = "https://player.twitch.tv/?channel=" + gpvm.vedio_url;
                }
                else if (movieclass_youtube == "https://www.youtube.com/")
                {
                    int    vediolength   = gpvm.vedio.vediourl.Length - 32;
                    string regex_youtube = gpvm.vedio.vediourl.Substring(32, vediolength);
                    //regex_youtube = Regex.Replace(gpvm.vedio.vediourl, regex_youtube, String.Empty);
                    gpvm.vedio_url = "https://www.youtube.com/embed/" + regex_youtube;
                }
                else if (movieclass_huya == "https://www.huya.com/")
                {
                    gpvm.vedio_url = Regex.Replace(gpvm.vedio.vediourl, movieclass_huya, String.Empty);
                    gpvm.vedio_url = "http://liveshare.huya.com/iframe/" + gpvm.vedio_url;
                }
                else if (gpvm.vedio.cfgVedioSn == 5)
                {
                    gpvm.vedio_url = gpvm.vedio_url;
                }
                else
                {
                    gpvm.vedio_url = "";
                }
            }

            gpvm.recommend    = new UserRepository().getRecommendValid(gpvm.game.userId);
            gpvm.recommendstr = new UserRepository().getRecommendStartV((int)gpvm.recommend.ReId);

            return(Json(gpvm, JsonRequestBehavior.AllowGet));
        }
        public async System.Threading.Tasks.Task <string> Create(GamePostViewModel gpvm)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            try
            {
                var vedio = new VedioRecord();
                if (gpvm.vedio == null)
                {
                    gpvm.vedio = vedio;
                }


                if (gpvm.livename == "1")
                {
                    gpvm.vedio.vediourl   = "https://www.twitch.tv/" + gpvm.live;
                    gpvm.vedio.cfgVedioSn = 4;
                }
                else if (gpvm.livename == "2")
                {
                    gpvm.vedio.vediourl   = gpvm.live;
                    gpvm.vedio.cfgVedioSn = 5;
                }
                else
                {
                    gpvm.vedio.cfgVedioSn = 0;
                }

                // gpvm.vedio = vedio;
                gpvm.vedio.title    = (string.IsNullOrEmpty(gpvm.vedio.title) ? "" : gpvm.vedio.title);
                gpvm.vedio.comment  = (string.IsNullOrEmpty(gpvm.vedio.comment) ? "" : gpvm.vedio.comment);
                gpvm.vedio.vediourl = (string.IsNullOrEmpty(gpvm.vedio.vediourl) ? "" : gpvm.vedio.vediourl);
                gpvm.vedio.valid    = 1;
                gpvm.vedio.inpdate  = DateTime.Now;
                gpvm.vedio.live     = gpvm.live;
                List <cfgVedio> cvList = new cfgVedioRepository().getAll();


                VedioRecordRepository vrr = new VedioRecordRepository();
                vrr.add(gpvm.vedio);



                gameDto game = gpvm.game;
                //game.userId = User.Identity.GetUserId();
                game.comSn    = 1;
                game.sdate    = DateTime.Now;
                game.edate    = DateTime.Now.AddYears(100);
                game.gamedate = DateTime.Now.AddYears(100);
                game.betModel = 2;
                game.rake     = 10;
                game          = await new GamesRepository().CreateLive(game);

                GamePosts gp = new GamePosts {
                    GameSn = game.sn, valid = 1, inpdate = DateTime.Now, Synchronize = game.sn
                };
                if (gpvm.vedio != null && gpvm.vedio.sn != 0)
                {
                    gp.VedioRecordSn = gpvm.vedio.sn;
                }
                gp.TeamASn    = gpvm.gamepost.TeamASn;
                gp.TeamBSn    = gpvm.gamepost.TeamBSn;
                gp.sdate      = gpvm.game.sdate;
                gp.edate      = gpvm.game.edate;
                gp.PlayGameSn = gpvm.gamepost.PlayGameSn;
                gp.UserLive   = gpvm.game.userId;

                var  cfpgame = new cfgPlayGameRepository().getAllLive();
                bool cf      = false;
                foreach (var cg in cfpgame)
                {
                    if (cg.shortName == gpvm.PlayGame.shortName)
                    {
                        cf            = true;
                        gp.PlayGameSn = cg.sn;
                    }
                }

                if (!cf)
                {
                    cfgPlayGame cfpg = new cfgPlayGame();

                    cfpg.shortName = gpvm.PlayGame.shortName;
                    cfpg.cName     = gpvm.PlayGame.shortName;
                    cfpg.eName     = gpvm.PlayGame.shortName;
                    cfpg.valid     = 2;
                    gp.PlayGameSn  = new cfgPlayGameRepository().Create(cfpg);
                }

                new UserRepository().CreateRecommend(gpvm.game.userId, str(6));

                new GamePostsRepository().add(gp);

                return(gp.sn.ToString());
            }
            catch
            {
                return("0");
            }
        }
        /* 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 async System.Threading.Tasks.Task <ActionResult> DPEdit(GamePostViewModel gpvm)
        {
            //try
            //{
            int       iGamePostSn = gpvm.getGamePostSn(encryptedKey);
            GamePosts gp          = new GamePostsRepository().get(iGamePostSn);

            if (!string.IsNullOrEmpty(gpvm.vedio.vediourl))
            {
                gpvm.vedio.title   = (string.IsNullOrEmpty(gpvm.vedio.title) ? "" : gpvm.vedio.title);
                gpvm.vedio.comment = (string.IsNullOrEmpty(gpvm.vedio.comment) ? "" : gpvm.vedio.comment);
                gpvm.vedio.valid   = 1;
                gpvm.vedio.inpdate = DateTime.Now;
                List <cfgVedio> cvList = new cfgVedioRepository().getAll();
                gpvm.vedio.cfgVedioSn = 0;
                foreach (cfgVedio cv in cvList)
                {
                    Regex defaultRegex = new Regex(cv.RegularStr);
                    if (defaultRegex.Match(gpvm.vedio.vediourl).Success)
                    {
                        gpvm.vedio.cfgVedioSn = cv.sn;
                    }

                    /*
                     * List<string> includestr = cv.includeURL.Split(',').ToList();
                     * foreach (string str in includestr)
                     * {
                     *  if (includestr.Contains(str))
                     *  {
                     *      gpvm.vedio.cfgVedioSn = cv.sn;
                     *  }
                     * }
                     */
                }
            }
            VedioRecordRepository vrr = new VedioRecordRepository();

            if (gp.VedioRecordSn.HasValue)
            {
                VedioRecord vr = new VedioRecordRepository().get(gp.VedioRecordSn.Value);
                vr.cfgVedioSn = gpvm.vedio.cfgVedioSn;
                vr.vediourl   = gpvm.vedio.vediourl;
                vrr.update(vr);
                gpvm.vedio = vr;
            }
            else
            {
                if (!string.IsNullOrEmpty(gpvm.vedio.vediourl))
                {
                    vrr.add(gpvm.vedio);
                }
            }



            gameDto game = gpvm.game;

            game.userId = User.Identity.GetUserId();
            game.comSn  = 1;
            game        = await new GamesRepository().Edit(game.sn, game);


            if (gpvm.vedio != null && gpvm.vedio.sn != 0)
            {
                gp.VedioRecordSn = gpvm.vedio.sn;
            }
            gp.TeamASn    = gpvm.gamepost.TeamASn;
            gp.TeamBSn    = gpvm.gamepost.TeamBSn;
            gp.sdate      = gpvm.game.sdate;
            gp.edate      = gpvm.game.edate;
            gp.PlayGameSn = gpvm.gamepost.PlayGameSn;
            new GamePostsRepository().update(gp);

            ///把新的topic推播到前端
            new SignalRHelper().UpdateTopic(game, encryptedKey, gpvm.md5GameSn);
            return(RedirectToAction("PrizePoolDetails", "game", new { id = gpvm.gamepost.sn }));
            //}
            //catch (Exception ex)
            //{
            //    return View(gpvm);
            //}
        }
        public async System.Threading.Tasks.Task <ActionResult> Index()
        {
            GamePostsRepository _gpr = new GamePostsRepository();

            List <GamePosts> gpList = _gpr.getLiveValidAll();

            List <gameDto>     gameList = await new GamesRepository().GetMainGameList();
            List <VedioRecord> vrlist   = new List <VedioRecord>();

            vrlist = new VedioRecordRepository().getAll();
            List <Teams> teamlist = new TeamsRepository().getAll();


            List <GamePostViewModel> gpvmList = new List <GamePostViewModel>();

            gpList = gpList.OrderByDescending(p => p.inpdate).ToList();

            DateTime dt = DateTime.Now.AddHours(-2);

            foreach (var gp in gpList)
            {
                GamePostViewModel gpvm = new GamePostViewModel();
                gpvm.gamepost = gp;
                gpvm.game     = gameList.Where(p => p.sn == gp.GameSn).FirstOrDefault();
                if (gpvm.game == null)
                {
                    continue;
                }
                if ((gp.sdate <= DateTime.Now && gp.edate >= dt) || gpvm.game.betModel == 7)
                {
                    var user = await UserManager.FindByIdAsync(gpvm.gamepost.UserLive);

                    if (user != null)
                    {
                        gpvm.gamepost.UserLive = user.UserName;
                    }
                    gpvm.vedio      = vrlist.Where(p => p.sn == gp.VedioRecordSn).FirstOrDefault();
                    gpvm.shorttitle = gpvm.game.title;

                    if (gpvm.vedio == null)
                    {
                        gpvm.vedio_url = "";
                    }
                    else
                    {
                        string movieclass_twitch  = "";
                        string movieclass_youtube = "";
                        string movieclass_huya    = "";
                        string movieclass_be      = "";
                        if (gpvm.vedio.vediourl.Length >= 22)
                        {
                            movieclass_twitch = gpvm.vedio.vediourl.Substring(0, 22);
                        }
                        if (gpvm.vedio.vediourl.Length >= 24)
                        {
                            movieclass_youtube = gpvm.vedio.vediourl.Substring(0, 24);
                        }
                        if (gpvm.vedio.vediourl.Length >= 21)
                        {
                            movieclass_huya = gpvm.vedio.vediourl.Substring(0, 21);
                        }
                        if (gpvm.vedio.vediourl.Length >= 17)
                        {
                            movieclass_be = gpvm.vedio.vediourl.Substring(0, 17);
                        }



                        if (movieclass_twitch == "https://www.twitch.tv/")
                        {
                            gpvm.vedio_url = Regex.Replace(gpvm.vedio.vediourl, movieclass_twitch, String.Empty);
                            gpvm.vedio_url = "https://player.twitch.tv/?channel=" + gpvm.vedio_url;
                        }
                        else if (movieclass_youtube == "https://www.youtube.com/")
                        {
                            int    vediolength   = gpvm.vedio.vediourl.Length - 32;
                            string regex_youtube = gpvm.vedio.vediourl.Substring(32, vediolength);
                            //regex_youtube = Regex.Replace(gpvm.vedio.vediourl, regex_youtube, String.Empty);
                            gpvm.vedio_url = "https://www.youtube.com/embed/" + regex_youtube;
                        }
                        else if (movieclass_huya == "https://www.huya.com/")
                        {
                            gpvm.vedio_url = Regex.Replace(gpvm.vedio.vediourl, movieclass_huya, String.Empty);
                            gpvm.vedio_url = "http://liveshare.huya.com/iframe/" + gpvm.vedio_url;
                        }
                        else if (movieclass_huya == "https://youtu.be/")
                        {
                            gpvm.vedio_url = Regex.Replace(gpvm.vedio.vediourl, movieclass_huya, String.Empty);
                            gpvm.vedio_url = "https://www.youtube.com/embed/" + movieclass_be;
                        }
                        else
                        {
                            gpvm.vedio_url = "";
                        }
                    }



                    if (gpvm.game.title.Length > 23)
                    {
                        gpvm.shorttitle = gpvm.game.title.Substring(0, 23);
                        gpvm.shorttitle = gpvm.shorttitle + "...";
                    }


                    gpvm.TeamA      = teamlist.Where(p => p.sn == gp.TeamASn).FirstOrDefault();
                    gpvm.TeamB      = teamlist.Where(p => p.sn == gp.TeamBSn).FirstOrDefault();
                    gpvm.gamesearch = gpvm.game.title + gpvm.game.comment + gpvm.gamepost.UserLive + gpvm.PlayGame.shortName;
                    gpvm.gamesearch = gpvm.gamesearch.ToLower();
                    gpvm.endguess   = 1;



                    if (gpvm.game.edate <= DateTime.Now)
                    {
                        gpvm.endguess = 0;
                    }
                    else if (gpvm.game.edate <= DateTime.Now.AddMinutes(30))
                    {
                        gpvm.endguess = 2;
                    }
                    if (gp.PlayGameSn.HasValue)
                    {
                        gpvm.PlayGame = new cfgPlayGameRepository().get(gp.PlayGameSn.Value);
                    }



                    if (gpvm.game.topicList.Where(x => x.valid == 1).Count() > 0)
                    {
                        gpvmList.Add(gpvm);
                    }
                }
            }



            var playgamelist = new cfgPlayGameRepository().getAll();

            ViewData["playlist"] = playgamelist;


            var gpvmListDy = gpvmList.OrderByDescending(x => x.game.betModel == 5).ThenBy(x => x.game.gamedate);


            ViewData["UserID"] = User.Identity.GetUserId();
            return(View(gpvmListDy));
        }
        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");
            }
        }
示例#18
0
        //[ValidateAntiForgeryToken]
        //直播擴充程式
        public async Task <JsonResult> LoginExtensions(LoginViewModel model, string returnUrl)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            GameAJaxDto ajd = new GameAJaxDto();
            // 這不會計算為帳戶鎖定的登入失敗
            // 若要啟用密碼失敗來觸發帳戶鎖定,請變更為 shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Name, model.Password, model.RememberMe, shouldLockout : false);

            // string[] array = new string[2];
            switch (result)
            {
            case SignInStatus.Success:
                //Session["Assets"] = new AssetsRepository().getAssetsListByUserID(User.Identity.GetUserId());
                var live = new UserRepository().getlive();


                var user = UserManager.FindByName(model.Name);
                if (live.Count == 0)
                {
                    //ModelState.AddModelError("", "登入嘗試失試。");
                    ajd.isTrue   = false;
                    ajd.ErrorMsg = "Liveerror";
                    return(Json(ajd, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    if (live.Where(x => x.username == user.Id).FirstOrDefault() == null)
                    {
                        ajd.isTrue   = false;
                        ajd.ErrorMsg = "Liveerror";
                        return(Json(ajd, JsonRequestBehavior.AllowGet));
                    }
                }



                GamePosts         gamepost = new GamePostsRepository().getLive(user.Id);
                GamePostViewModel gpvm     = new GamePostViewModel();
                gpvm.gamepost = gamepost;

                ajd.gpvm = gpvm;

                //Session["levelExp"] = new AssetsRepository().getExpByUserID(User.Identity.GetUserId());

                ajd.userId   = user.Id;
                ajd.username = user.UserName;
                ajd.isTrue   = true;
                ajd.live     = (int)live.Where(x => x.username == user.Id).FirstOrDefault().valid;
                return(Json(ajd, JsonRequestBehavior.AllowGet));

            //return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
            //return View("Lockout");
            case SignInStatus.RequiresVerification:
            //return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "登入嘗試失試。");
                ajd.ErrorMsg = "error";
                ajd.isTrue   = false;
                // array[0] = "error";
                return(Json(ajd, JsonRequestBehavior.AllowGet));
            }
        }