public static MvcHtmlString PlayGameSelect(this HtmlHelper htmlhelper, string name, int?defualValue) //開放、靜態、的擴充方法 { List <cfgPlayGame> PlayGameList = new cfgPlayGameRepository().getAll(); List <SelectListItem> sliList = new List <SelectListItem>(); sliList.Add(new SelectListItem { Text = "請選擇", Value = "" }); defualValue = (defualValue.HasValue ? defualValue.Value : 0); foreach (var s in PlayGameList) { SelectListItem sli = new SelectListItem { Text = s.shortName, Value = s.sn.ToString(), Selected = (s.sn == defualValue.Value ? true : false) }; sliList.Add(sli); } return(System.Web.Mvc.Html.SelectExtensions.DropDownList(htmlhelper, name, sliList, new { @class = "form-control" })); }
public static MvcHtmlString AreaGameSelect(this HtmlHelper htmlhelper, string name, int?defualValue) //開放、靜態、的擴充方法 { List <Leagues> leaguedata = new LeaguesRepository().getAll(); List <cfgPlayGame> PlayGameList = new cfgPlayGameRepository().getAll(); List <SelectListGroup> sgList = new List <SelectListGroup>(); TeamsViewModel LeaguesList = new TeamsViewModel { LeaguesData = leaguedata }; sgList.Add(new SelectListGroup { Name = "Other" }); foreach (var p in PlayGameList) { sgList.Add(new SelectListGroup { Name = p.shortName }); } List <SelectListItem> sliList = new List <SelectListItem>(); sliList.Add(new SelectListItem { Text = "請選擇", Value = "" }); defualValue = (defualValue.HasValue ? defualValue.Value : 0); foreach (var s in LeaguesList.LeaguesData) { SelectListGroup sg = new SelectListGroup(); string lgName = ""; if (s.playGamesn != null) { lgName = PlayGameList.Where(p => p.sn == s.playGamesn).FirstOrDefault().shortName; } else { lgName = "Other"; } sg = sgList.Where(p => p.Name == lgName).FirstOrDefault(); SelectListItem sli = new SelectListItem { Text = s.shortName, Value = s.sn.ToString(), Selected = (s.sn == defualValue.Value ? true : false), Group = sg }; sliList.Add(sli); } return(System.Web.Mvc.Html.SelectExtensions.DropDownList(htmlhelper, name, sliList, new { @class = "form-control" })); }
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 <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> 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 TeamsController() { this.teamsRepository = new TeamsRepository(); this.leaguesRepository = new LeaguesRepository(); this.playgameRepository = new cfgPlayGameRepository(); }