public ActionResult DailyWinners(int?Spieltag) { _log.Debug("Begin DailyWinners"); using (var client = new SvcFussballDB.SportsdataSoapClient()) { int currSpieltag = (Spieltag.HasValue == true) ? Spieltag.Value : OpenDBHelper.GetSpieltagInfo(_matchDataRepository).CurrentSpieltag; // build dropdown list data { var count = SportsdataConfigInfo.Current.EndSpieltag - SportsdataConfigInfo.Current.StartSpieltag + 1; var ddlSpieltageRange = (from e in Enumerable.Range(SportsdataConfigInfo.Current.StartSpieltag, count) select new SelectListItem() { Value = e.ToString(), Text = "Spieltag " + e.ToString(), Selected = (e == currSpieltag) }); ViewBag.Spieltag = ddlSpieltageRange; } var viewModel = DailyWinnersInternal(currSpieltag); _log.Debug("End DailyWinners"); return(View(viewModel)); } }
private List <MatchInfoModel> GetMatchModelListBySpieltag(int spieltag) { using (var client = new SvcFussballDB.SportsdataSoapClient()) { var matchList = new List <MatchInfoModel>(); var oddsList = WettfreundeScraper.Scrap(spieltag); var matches = client.GetMatchdataByGroupLeagueSaison(spieltag, SportsdataConfigInfo.Current.LeagueShortcut, SportsdataConfigInfo.Current.LeagueSaison); foreach (var m in matches) { var matchInfoModel = new MatchInfoModel(); matchInfoModel.MatchId = m.matchID; matchInfoModel.KickoffTime = m.matchDateTime; matchInfoModel.IsFinished = m.matchIsFinished; matchInfoModel.HomeTeam = m.nameTeam1; matchInfoModel.AwayTeam = m.nameTeam2; matchInfoModel.HomeTeamIcon = m.iconUrlTeam1; matchInfoModel.AwayTeamIcon = m.iconUrlTeam2; matchInfoModel.HomeTeamScore = m.pointsTeam1; matchInfoModel.AwayTeamScore = m.pointsTeam2; // mixin odds quotes into match data { MixinOddsQuotes(oddsList, matchInfoModel); } matchList.Add(matchInfoModel); } return(matchList); } }
public ActionResult ReportDailyWinners() { _log.Debug("Begin All DailyWinners"); using (var client = new SvcFussballDB.SportsdataSoapClient()) { int endSpieltag = OpenDBHelper.GetSpieltagInfo(_matchDataRepository).CurrentSpieltag; int beginSpieltag = SportsdataConfigInfo.Current.StartSpieltag; var allWinnersModel = new OverallDailyWinnerInfoModel(); using (var ctxt = new TippSpielContext()) { using (var userCtxt = new UsersContext()) { var allUsers = (from t in ctxt.TippMatchList select t.User).Distinct().ToArray(); foreach (var user in allUsers) { var displayName = (from u in userCtxt.UserProfiles where u.UserName == user select u.DisplayName) .FirstOrDefault(); allWinnersModel.AllDailyWinnerMap.Add(user, new OverallDailyWinnerRankingItemModel() { User = user, DisplayName = displayName, Rang = -1, Wins = 0 }); } } } for (int day = beginSpieltag; day <= endSpieltag; day++) { var result = DailyWinnersInternal(day); foreach (var item in result.Ranking.Where(r => r.Rang == 1)) { allWinnersModel.AllDailyWinnerMap[item.User].Wins += 1; } } var orderResult = (from kp in allWinnersModel.AllDailyWinnerMap orderby kp.Value.Wins descending select kp).ToDictionary(p => p.Key, p => p.Value); int counter = 1; orderResult.ForEach(e => { e.Value.Rang = counter++; }); allWinnersModel.AllDailyWinnerMap = orderResult; _log.Debug("End All DailyWinners"); return(View(allWinnersModel)); } }
private DailyWinnerInfoModel DailyWinnersInternal(int currSpieltag) { _log.Debug("Current spieltag=" + currSpieltag.ToString()); var viewModel = new DailyWinnerInfoModel(); using (var client = new SvcFussballDB.SportsdataSoapClient()) { var matchesDB = client.GetMatchdataByGroupLeagueSaison(currSpieltag, SportsdataConfigInfo.Current.LeagueShortcut, SportsdataConfigInfo.Current.LeagueSaison); foreach (var m in matchesDB) { viewModel.MatchInfo.Add(OpenDBHelper.Create(m)); } using (var ctxt = new TippSpielContext()) { var resultDict = new Dictionary <string, RankingInfoModel>(); using (var userCtxt = new UsersContext()) { // init result dict { foreach (var username in (from t in ctxt.TippMatchList select t.User).Distinct()) { var m = new RankingInfoModel(); m.User = username; m.DisplayName = (from u in userCtxt.UserProfiles where u.UserName == username select u.DisplayName) .FirstOrDefault(); resultDict.Add(username, m); viewModel.AllTippInfoDict.Add(username, new List <MatchInfoModel>()); } } } // 1. get all tipps for match with id foreach (var match in matchesDB) { var tippSet = (from t in ctxt.TippMatchList where t.MatchId == match.matchID && t.MyTip.HasValue && t.MyAmount.HasValue && t.MyOdds.HasValue select t); foreach (var tip in tippSet) { var matchModelObj = OpenDBHelper.Create(match); matchModelObj.MyOdds = tip.MyOdds; matchModelObj.MyAmount = tip.MyAmount; matchModelObj.MyTip = tip.MyTip; if (matchModelObj.HasStarted == true) { resultDict[tip.User].TippCount++; resultDict[tip.User].TotalPoints += (matchModelObj.MyPoints.HasValue) ? matchModelObj.MyPoints.Value : 0.0; } if (matchModelObj.HasStarted == true) { viewModel.AllTippInfoDict[tip.User].Add(matchModelObj); } } } var resultList = (from kp in resultDict select kp.Value).ToList(); viewModel.Ranking = (from e in resultList orderby e.TotalPoints descending, e.PointAvg, e.TippCount descending select e) .ToList(); int counter = 1; viewModel.Ranking.ForEach(e => { e.Rang = counter++; }); return(viewModel); } } }
public JsonResult SendDailyWinnerEmail(string username) { _log.Debug("Begin SendDailyWinnerEmail()"); using (var client = new SvcFussballDB.SportsdataSoapClient()) { // precondition to send daily winner email { var completeInfo = OpenDBHelper.IsSpieltagComplete(client); var jsonResponse = new { Success = true, Receivers = new List <string>() }; if (completeInfo.IsCompleted == false) { _log.DebugFormat("Spieltag is not yet completed"); return(Json(jsonResponse, JsonRequestBehavior.AllowGet)); } else if (completeInfo.IsCompletedRecently == false) { _log.DebugFormat("Spieltag is out-dated"); return(Json(jsonResponse, JsonRequestBehavior.AllowGet)); } } var spieltag = OpenDBHelper.GetSpieltagInfo(_matchDataRepository).CurrentSpieltag; var result = this.DailyWinnersInternal(spieltag); using (var ctxt = new UsersContext()) { var userList = new List <string>(); var profiles = ctxt.UserProfiles as IQueryable <UserProfile>; if (String.IsNullOrEmpty(username) == false) { profiles = profiles.Where(p => p.UserName == username); } foreach (var user in profiles) { if (user != null && !String.IsNullOrEmpty(user.Email)) { TippMailer.EmailDailyWinner(user.Email, result, spieltag).Send(); _log.Debug("Email sent to " + user.Email); userList.Add(user.UserName); } } var jsonResponse = new { Success = true, Receivers = userList }; _log.Debug("End SendDailyWinnerEmail()"); return(Json(jsonResponse, JsonRequestBehavior.AllowGet)); } } }
public ActionResult OverallStanding() { using (var client = new SvcFussballDB.SportsdataSoapClient()) { int maxSpieltag = OpenDBHelper.GetSpieltagInfo(_matchDataRepository).CurrentSpieltag; using (var ctxt = new TippSpielContext()) { var resultDict = new Dictionary <string, RankingInfoModel>(); using (var userCtxt = new UsersContext()) { // init dict { foreach (var username in (from t in ctxt.TippMatchList select t.User).Distinct()) { var m = new RankingInfoModel(); m.User = username; m.DisplayName = (from u in userCtxt.UserProfiles where u.UserName == username select u.DisplayName) .FirstOrDefault(); resultDict.Add(username, m); } } } foreach (var tip in ctxt.TippMatchList.Where(t => t.MyTip.HasValue)) { var rankingObj = resultDict[tip.User]; var matchInfo = _matchDataRepository.GetMatchData(tip.MatchId); var matchModelObj = new MatchInfoModel() { MatchId = matchInfo.MatchId, AwayTeam = matchInfo.AwayTeam, AwayTeamIcon = matchInfo.AwayTeamIcon, AwayTeamScore = matchInfo.AwayTeamScore, HomeTeam = matchInfo.HomeTeam, HomeTeamIcon = matchInfo.HomeTeamIcon, HomeTeamScore = matchInfo.HomeTeamScore, IsFinished = matchInfo.IsFinished, KickoffTime = matchInfo.KickoffTime, MyOdds = tip.MyOdds, MyAmount = tip.MyAmount, MyTip = tip.MyTip }; if (tip.MyOdds.HasValue && tip.MyAmount.HasValue) { matchModelObj.MyOdds = tip.MyOdds; matchModelObj.MyAmount = tip.MyAmount; matchModelObj.MyTip = tip.MyTip; if (matchModelObj.HasStarted == true) { rankingObj.TippCount++; rankingObj.TotalPoints += (matchModelObj.MyPoints.HasValue) ? matchModelObj.MyPoints.Value : 0.0; } // count longshot and favorite { rankingObj.TippCountFavorite += (matchModelObj.FavoriteTippIndex == tip.MyTip.Value) ? 1 : 0; rankingObj.TippCountLongshot += (matchModelObj.LongshotTippIndex == tip.MyTip.Value) ? 1 : 0; } } } var resultList = (from kp in resultDict select kp.Value).ToList(); resultList = (from e in resultList orderby e.TotalPoints descending, e.PointAvg, e.TippCount descending select e) .ToList(); int counter = 1; resultList.ForEach(e => { e.Rang = counter++; }); return(View(resultList)); } } }