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)); } } }
public ActionResult OverallStanding() { _matchDataRepository.GetCurrentGroup(); var groupModel = _matchDataRepository.GetCurrentGroup(); var maxSpieltag = groupModel.Id; 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); if (matchInfo.LeagueShortcut == SportsdataConfigInfo.Current.LeagueShortcut && tip.MyOdds.HasValue && tip.MyAmount.HasValue) { var matchModelObj = new MatchInfoModel() { MatchId = matchInfo.MatchId, MatchNr = matchInfo.MatchNr, AwayTeam = matchInfo.AwayTeam, AwayTeamIcon = matchInfo.AwayTeamIcon, AwayTeamScore = matchInfo.AwayTeamScore, HomeTeam = matchInfo.HomeTeam, HomeTeamIcon = matchInfo.HomeTeamIcon, HomeTeamScore = matchInfo.HomeTeamScore, IsFinished = matchInfo.IsFinished, KickoffTime = matchInfo.KickoffTime, GroupId = tip.GroupId, MyOdds = tip.MyOdds, MyAmount = tip.MyAmount, MyTip = tip.MyTip, IsJoker = tip.IsJoker, }; if (tip.IsJoker == true) { matchModelObj.MyAmount = tip.MyAmount * TippspielConfigInfo.Current.JokerMultiplicator; } else { matchModelObj.MyAmount = tip.MyAmount; } if (matchModelObj.HasStarted == true) { rankingObj.TippCount++; rankingObj.TotalPoints += matchModelObj.MyPoints ?? 0.0; rankingObj.TotalPointsClean += matchModelObj.MyPointsClean ?? 0.0; if (tip.IsJoker) { rankingObj.JokerUsed++; } } } } 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)); } }
public ActionResult MigrateOpenliga(string newLeagueSeason, string newLeagueShortcut) { var m = new MigrationResultModel() { CurrentLeagueSeason = SportsdataConfigInfo.Current.LeagueSaison, CurrentLeagueShortcut = SportsdataConfigInfo.Current.LeagueShortcut }; // precondition: db exists under new name { if (_matchDataRepository.Exist(newLeagueShortcut, newLeagueSeason)) { log.DebugFormat("League {0}/{1} is valid", newLeagueShortcut, newLeagueSeason); var newClient = new WMFussballDataRepository(newLeagueShortcut, newLeagueSeason); var newMatches = newClient.GetMatchesByCurrentGroup(); using (var ctxt = new TippSpielContext()) { var migrationList = new List <TippMatchModel>(); foreach (var tipp in ctxt.TippMatchList) { // // Basic idea: // 1. is match tipp among the matches to be migrated, if yes it is already migrated => finish // 2. if no, then migrate it but only if tipp belongs to old league. Do not touch others // var newMatchObj = (from t in newMatches where t.MatchId == tipp.MatchId select t) .FirstOrDefault(); if (newMatchObj == null) { var oldMatchObj = _matchDataRepository.GetMatchData(tipp.MatchId); if (oldMatchObj != null) { // find corresponding match in new league var newMatchByTeams = (from t in newMatches where t.HomeTeamId == oldMatchObj.HomeTeamId && t.AwayTeamId == oldMatchObj.AwayTeamId select t) .FirstOrDefault(); if (newMatchByTeams != null) { using (var ctxt2 = new TippSpielContext()) { var tippObj = (from t in ctxt2.TippMatchList where t.User == tipp.User && t.MatchId == newMatchByTeams.MatchId select t) .FirstOrDefault(); if (tippObj == null) // not null means tipp has already been migrated { var newTipp = new TippMatchModel() { MatchId = newMatchByTeams.MatchId, GroupId = tipp.GroupId, IsJoker = tipp.IsJoker, LastUpdated = DateTime.Now, MyAmount = tipp.MyAmount, MyOdds = tipp.MyOdds, MyTip = tipp.MyTip, User = tipp.User }; migrationList.Add(newTipp); } } } } } } // save migration list foreach (var t in migrationList) { log.DebugFormat("Migrate match={0} for user={1}", t.MatchId, t.User); ctxt.TippMatchList.Add(t); } ctxt.SaveChanges(); } } else { var errMsg = String.Format("League {0}/{1} does not exist", newLeagueShortcut, newLeagueSeason); log.Debug(errMsg); ModelState.AddModelError("league", errMsg); } } return(View(m)); }