public ActionResult Create(Match model, string DatePart, string TimePart, string[] pLiveVideos, string[] pLiveVideosForMobile, string RecordingParams, string RecordingMobiParams, string HighlightsParams, string HighlightsMobiParams) { InitCreatBag(); if (!ModelState.IsValid) { ModelState.AddModelError("", "表单验证失败。"); return View(model); } if (!string.IsNullOrEmpty(model.KanbisaiLink) && collection.Find(Query<Match>.EQ(d => d.KanbisaiLink, model.KanbisaiLink)).Count() > 0) { ModelState.AddModelError("KanbisaiLink", "KanbisaiLink已存在。"); return View(model); } if (string.IsNullOrEmpty(DatePart) || string.IsNullOrEmpty(TimePart)) { ModelState.AddModelError("DatePart", "时间选项必填。"); return View(model); } model.CapString = CapFunc.GetChineseString((eMatchType)model.Type, model.Cap); InjectTime(model, DatePart, TimePart); InjectTeamName(model); InjectLiveVideos(model, pLiveVideos, pLiveVideosForMobile); InjectRecording(model, RecordingParams, RecordingMobiParams); InjectHighlights(model, HighlightsParams, HighlightsMobiParams); collection.Insert(model); return RedirectToAction("Edit", new { id = model.Id }); }
public void Put(Match value) { var updateResult = collection.Update( Query<Match>.EQ(p => p.Id, value.Id), Update<Match>.Replace(value), new MongoUpdateOptions { WriteConcern = WriteConcern.Acknowledged //ToDo: i don't know what's means. }); if (updateResult.DocumentsAffected == 0) { throw new Exception("No one updateed!"); } }
private Match QueryExitMatch(Match m) { return baozouMatchCollection.FindOne(Query.And( Query.Or( Query<Match>.EQ(e => e.CapString, m.CapString), Query<Match>.EQ(e => e.CapStringDetial, m.CapString) ), Query.Or( Query<Match>.EQ(e => e.TeamNameChinese, m.TeamNameChinese), Query<Match>.EQ(e => e.TeamNameChineseForGuest, m.TeamNameChinese) ), Query.Or( Query<Match>.EQ(e => e.TeamNameChinese, m.TeamNameChineseForGuest), Query<Match>.EQ(e => e.TeamNameChineseForGuest, m.TeamNameChineseForGuest) ), Query.And( Query<Match>.GT(e => e.Time, m.Time.Subtract(new TimeSpan(3, 0, 0))), Query<Match>.LT(e => e.Time, m.Time.AddHours(3)) ) )); }
private Match MatchByAzhiboTitle(Match m) { IMongoQuery queryTime = Query.And( Query<Match>.GT(e => e.Time, m.Time.Subtract(new TimeSpan(3, 0, 0))), Query<Match>.LT(e => e.Time, m.Time.AddHours(3)) ); Match match = null; if (m.CapString == "网球") { match = baozouMatchCollection.FindOne(Query.And( queryTime, Query<Match>.EQ(e => e.Type, (int)eMatchType.Tennis), Query.Where(new BsonJavaScript("'" + m.Title + "'.indexOf(this.CapString) > -1")) )); } else if (m.CapString == "乒乓球") { match = baozouMatchCollection.FindOne(Query.And( queryTime, Query<Match>.EQ(e => e.Type, (int)eMatchType.Pingpong), Query<Match>.EQ(e => e.Title, m.Title) )); } else { IMongoQuery queryCap; if (m.CapString == "足球友谊赛") { queryCap = Query.And(queryTime, Query<Match>.EQ(e => e.Type, (int)eMatchType.Soccer)); } else if (m.CapString == "篮球友谊赛") { queryCap = Query.And(queryTime, Query<Match>.EQ(e => e.Type, (int)eMatchType.Nba)); } else { queryCap = Query.And(queryTime, Query<Match>.EQ(e => e.CapString, m.CapString)); } match = baozouMatchCollection.FindOne(Query.And( queryCap, Query<Match>.EQ(e => e.Title, m.Title) )); if (match == null) { var matchs = baozouMatchCollection.Find(queryCap); if (matchs.Count() == 0) return null; foreach (var item in matchs.ToList()) { if (m.Title.Contains(item.TeamNameChinese) || m.Title.Contains(item.TeamNameChineseForGuest)) { match = item; break; } } } } return match; }
private bool InjectTeamName(Match m) { var team = baozouTeamCollection.AsQueryable<Team>().FirstOrDefault(d => d.NameChinese == m.TeamNameChinese || d.NameAlias.Contains(m.TeamNameChinese)); if (team != null) { m.TeamName = team.Name; m.TeamNameChinese = team.NameChinese; } var teamGorGuest = baozouTeamCollection.AsQueryable<Team>().FirstOrDefault(d => d.NameChinese == m.TeamNameChineseForGuest || d.NameAlias.Contains(m.TeamNameChineseForGuest)); if (teamGorGuest != null) { m.TeamNameForGuest = teamGorGuest.Name; m.TeamNameChineseForGuest = teamGorGuest.NameChinese; } return (team != null || teamGorGuest != null); }
private void InjectLiveVideos(Match match, IEnumerable<Link> links, bool isMobi) { if (match.LockSpider) return; IEnumerable<string> liveStrings = links.Select(d => d.Name); var lives = baozouLiveCollection.AsQueryable().OrderByDescending(d => d.Rank).ToList(); foreach (var lv in lives) { if (lv.Name == "腾讯看比赛") lv.Link = lv.LinkForMobile = lv.LinkForAndroid = match.KanbisaiLink; } if (isMobi) { var livesMobi = lives.Where(d => d.LinkForMobile != null && d.AliasForMobile != null); var liveVideosMobi = livesMobi.Where(d => d.AliasForMobile.ContainsAny(liveStrings) //http://goo.gl/WyLqec mongo 1.5+ 版本支持ContainsAny && (!d.IsAimTypeCap || (d.IsAimTypeCap && d.AimTypes.Contains(match.Type) && d.AimCaps.Contains(match.Cap)) )); match.LiveVideosForMobile = liveVideosMobi.Select(x => x.GenerateLinkMobi()).ToList(); match.LiveVideosForAndroid = liveVideosMobi.Select(x => x.GenerateLinkAndroid()).ToList(); } else { match.LiveVideos = lives.Where(d => d.Alias.ContainsAny(liveStrings) && (!d.IsAimTypeCap || (d.IsAimTypeCap && d.AimTypes.Contains(match.Type) && d.AimCaps.Contains(match.Cap)) )) .Select(x => x.GenerateLinkAndroid()); } }
private bool AnalyzeAzhiboCapString(Match m) { if (m.CapString.Contains("乒乓球")) { m.Type = (int)eMatchType.Pingpong; } if (m.CapString.Contains("天下足球")) { m.Type = (int)eMatchType.Arts; } return (m.Type != 0); }
public bool AnalyzeCapString(Match m) { m.Type = 0; m.Cap = 0; foreach (var cap in (eBasketballCap[])Enum.GetValues(typeof(eBasketballCap))) { string capChinese = cap.GetAttachedData<string>(DescripCap.Chinese); if (m.CapString == capChinese) { m.Type = (int)eMatchType.Nba; m.Cap = (int)cap; if (m.CapString != capChinese) { m.CapStringDetial = m.CapString; m.CapString = capChinese; } break; } } if (m.Type != 0) return true; foreach (var cap in (eSoccerCap[])Enum.GetValues(typeof(eSoccerCap))) { string capChinese = cap.GetAttachedData<string>(DescripCap.Chinese); if (m.CapString == capChinese) { m.Type = (int)eMatchType.Soccer; m.Cap = (int)cap; if (m.CapString != capChinese) { m.CapStringDetial = m.CapString; m.CapString = capChinese; } break; } } if (m.Type != 0) return true; foreach (var cap in (eTennisCap[])Enum.GetValues(typeof(eTennisCap))) { string capChinese = cap.GetAttachedData<string>(DescripCap.Chinese); if (m.CapString == capChinese) { m.Type = (int)eMatchType.Tennis; m.Cap = (int)cap; if (m.CapString != capChinese) { m.CapStringDetial = m.CapString; m.CapString = capChinese; } break; } } if (m.Type != 0) return true; foreach (var cap in (eArtsCap[])Enum.GetValues(typeof(eArtsCap))) { string capChinese = cap.GetAttachedData<string>(DescripCap.Chinese); if (m.CapString == capChinese) { m.Type = (int)eMatchType.Arts; m.Cap = (int)cap; if (m.CapString != capChinese) { m.CapStringDetial = m.CapString; m.CapString = capChinese; } break; } } if (m.Type != 0) return true; foreach (var cap in (eBasketballCap[])Enum.GetValues(typeof(eBasketballCap))) { string capChinese = cap.GetAttachedData<string>(DescripCap.Chinese); if (m.CapString.Contains(capChinese)) { m.Type = (int)eMatchType.Nba; m.Cap = (int)cap; if (m.CapString != capChinese) { m.CapStringDetial = m.CapString; m.CapString = capChinese; } break; } } if (m.Type != 0) return true; foreach (var cap in (eSoccerCap[])Enum.GetValues(typeof(eSoccerCap))) { string capChinese = cap.GetAttachedData<string>(DescripCap.Chinese); if (m.CapString.Contains(capChinese)) { m.Type = (int)eMatchType.Soccer; m.Cap = (int)cap; if (m.CapString != capChinese) { m.CapStringDetial = m.CapString; m.CapString = capChinese; } break; } } if (m.Type != 0) return true; foreach (var cap in (eTennisCap[])Enum.GetValues(typeof(eTennisCap))) { string capChinese = cap.GetAttachedData<string>(DescripCap.Chinese); if (m.CapString.Contains(capChinese)) { m.Type = (int)eMatchType.Tennis; m.Cap = (int)cap; if (m.CapString != capChinese) { m.CapStringDetial = m.CapString; m.CapString = capChinese; } break; } } if (m.Type != 0) return true; foreach (var cap in (eArtsCap[])Enum.GetValues(typeof(eArtsCap))) { string capChinese = cap.GetAttachedData<string>(DescripCap.Chinese); if (m.CapString.Contains(capChinese)) { m.Type = (int)eMatchType.Arts; m.Cap = (int)cap; if (m.CapString != capChinese) { m.CapStringDetial = m.CapString; m.CapString = capChinese; } break; } } if (m.Type != 0) return true; if (m.CapString.Contains("斯诺克")) { m.Type = (int)eMatchType.Billiards; } return (m.Type != 0); }
public ActionResult Edit(Match model, string DatePart, string TimePart, string[] pLiveVideos, string[] pLiveVideosForMobile , string RecordingParams, string RecordingMobiParams, string HighlightsParams, string HighlightsMobiParams) { if (!ModelState.IsValid) { // HTML.DropDownList multiple 下有bug,selectedvalues无法在当前页面返回时准确反馈状态,只能用这种丑陋的办法 return RedirectToAction("Edit", new { id = model.Id, error = true }); } if (string.IsNullOrEmpty(DatePart) || string.IsNullOrEmpty(TimePart)) { return RedirectToAction("Edit", new { id = model.Id, datePartError = true }); } model.CapString = CapFunc.GetChineseString((eMatchType)model.Type, model.Cap); InjectLiveVideos(model, pLiveVideos, pLiveVideosForMobile); InjectRecording(model, RecordingParams, RecordingMobiParams); InjectHighlights(model, HighlightsParams, HighlightsMobiParams); InjectTime(model, DatePart, TimePart); InjectTeamName(model); collection.Save(model); return RedirectToAction("Edit", new { id = model.Id }); }
private void InjectTime(Match model, string DatePart, string TimePart) { model.Time = DateTime.Parse(DatePart); DateTime time = DateTime.ParseExact(TimePart, "H:mm", CultureInfo.InvariantCulture); model.Time = model.Time.Add(time.TimeOfDay); }
private void InjectTeamName(Match model) { if (!string.IsNullOrEmpty(model.TeamName)) { Team team = teamCollection.FindOne(Query<Team>.EQ(e => e.Name, model.TeamName)); model.TeamNameChinese = team.NameChinese; } if (!string.IsNullOrEmpty(model.TeamNameForGuest)) { Team teamGuest = teamCollection.FindOne(Query<Team>.EQ(e => e.Name, model.TeamNameForGuest)); model.TeamNameChineseForGuest = teamGuest.NameChinese; } }
private void InjectRecording(Match model, string RecordingParams, string RecordingMobiParams) { if (!string.IsNullOrEmpty(RecordingParams)) { //window下表单input换行会新增出\r,在mac/linux下执行会Error model.Recording = RecordingParams.Split(new[] { "\r\n-\r\n" }, StringSplitOptions.RemoveEmptyEntries).Select(d => new Link { Name = d.Split('|')[0], Url = d.Split('|')[1] }).ToList(); } if (!string.IsNullOrEmpty(RecordingMobiParams)) { model.RecordingMobi = RecordingMobiParams.Split(new[] { "\r\n-\r\n" }, StringSplitOptions.RemoveEmptyEntries).Select(d => new Link { Name = d.Split('|')[0], Url = d.Split('|')[1] }).ToList(); } }
private void InjectLiveVideos(Match model, string[] pLiveVideos, string[] pLiveVideosForMobile) { var lives = liveVideoCollection.FindAll().OrderByDescending(d => d.Rank); foreach (var lv in lives) { if (lv.Name == "腾讯看比赛") lv.Link = lv.LinkForMobile = lv.LinkForAndroid = model.KanbisaiLink; } if (pLiveVideos != null) { model.LiveVideos = lives.Where(d => pLiveVideos.Contains(d.Id)).Select(x => x.GenerateLink()); } if (pLiveVideosForMobile != null) { model.LiveVideosForMobile = lives.Where(d => pLiveVideosForMobile.Contains(d.Id)).Select(x => x.GenerateLinkMobi()); model.LiveVideosForAndroid = lives.Where(d => pLiveVideosForMobile.Contains(d.Id)).Select(x => x.GenerateLinkAndroid()); } }
private void InitEditBag(Match model) { ViewBag.MatchTypeSel = ((eMatchType)model.Type).ToSelectListItems(); ViewBag.StatusSel = ((eMatchStatus)model.Status).ToSelectListItems(); ViewBag.GradeSel = ((eGrade)model.Grade).ToSelectListItems(); ViewBag.soccerCapSel = ((eSoccerCap)(model.Type == 1 ? model.Cap : 1)).ToSelectListItems(DescripCap.Chinese); ViewBag.basketballCapSel = ((eBasketballCap)(model.Type == 2 ? model.Cap : 1)).ToSelectListItems(DescripCap.Chinese); ViewBag.tennisCapSel = ((eTennisCap)(model.Type == 3 ? model.Cap : 1)).ToSelectListItems(DescripCap.Chinese); IEnumerable<Team> values = teamCollection.FindAll(); ViewBag.TeamNameSel = new SelectList(values, "Name", "NameChinese", model.TeamName); ViewBag.TeamNameForGuestSel = new SelectList(values, "Name", "NameChinese", model.TeamNameForGuest); var lvs = liveVideoCollection.FindAll(); IEnumerable<string> selectedValues = null; if (model.LiveVideos != null && model.LiveVideos.Count() > 0) selectedValues = lvs.Where(d => model.LiveVideos.Select(l => l.Url).Contains(d.Link)).Select(s => s.Id); ViewBag.LiveVideosSel = new MultiSelectList(lvs, "Id", "Name", selectedValues); var lvsMobi = liveVideoCollection.AsQueryable().Where(d => d.LinkForMobile != null).ToList(); IEnumerable<string> selectedValuesMobi = null; if (model.LiveVideosForMobile != null && model.LiveVideosForMobile.Count() > 0) selectedValuesMobi = lvsMobi.Where(d => model.LiveVideosForMobile.Select(l => l.Url).Contains(d.LinkForMobile)).Select(s => s.Id); ViewBag.LiveVideosMobiSel = new MultiSelectList(lvsMobi, "Id", "Name", selectedValuesMobi); ViewBag.DatePart = model.Time.ToString("yyyy 年 MM 月 dd 日"); ViewBag.TimePart = model.Time.ToString("H:mm"); if (model.Recording != null) { IEnumerable<string> paramsLines = model.Recording.Select(d => string.Format("{0}|{1}", d.Name.Trim(), d.Url.Trim())); ViewBag.RecordingParams = string.Join("\n-\n", paramsLines); } if (model.RecordingMobi != null) { IEnumerable<string> paramsLines = model.RecordingMobi.Select(d => string.Format("{0}|{1}", d.Name.Trim(), d.Url.Trim())); ViewBag.RecordingMobiParams = string.Join("\n-\n", paramsLines); } if (model.Highlights != null) { IEnumerable<string> paramsLines = model.Highlights.Select(d => string.Format("{0}|{1}", d.Name.Trim(), d.Url.Trim())); ViewBag.HighlightsParams = string.Join("\n-\n", paramsLines); } if (model.HighlightsMobi != null) { IEnumerable<string> paramsLines = model.HighlightsMobi.Select(d => string.Format("{0}|{1}", d.Name.Trim(), d.Url.Trim())); ViewBag.HighlightsMobiParams = string.Join("\n-\n", paramsLines); } }