public void add(VedioRecord vr)
        {
            vr.inpdate = DateTime.Now;
            vr.valid   = 1;
            db.VedioRecord.Add(vr);

            db.SaveChanges();
        }
 public GamePostViewModel()
 {
     vedio    = new VedioRecord();
     gamepost = new GamePosts();
     game     = new gameDto();
     cfgVedio = new cfgVedio();
     TeamA    = new Teams();
     TeamB    = new Teams();
     PlayGame = new cfgPlayGame();
 }
        public void update(VedioRecord vr)
        {
            VedioRecord vrd = db.VedioRecord.Where(p => p.sn == vr.sn).FirstOrDefault();

            vrd.vediourl   = (string.IsNullOrEmpty(vr.vediourl) ? "" : vr.vediourl);
            vrd.cfgVedioSn = vr.cfgVedioSn;
            vrd.comment    = vr.comment;
            vrd.title      = vr.title;

            db.SaveChanges();
        }
        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 <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");
            }
        }