public ActionResult CleanupDuplicates() { var matches = _matchDataRepository.GetAllMatches(); var list2deleted = new List <int>(); foreach (var m in matches) { List <string> users = null; using (var ctxt = new TippSpielContext()) { users = (from t in ctxt.TippMatchList select t.User).Distinct().ToList(); } foreach (var username in users) { using (var ctxt = new TippSpielContext()) { var filter = (from t in ctxt.TippMatchList where t.MatchId == m.MatchId && t.User == username select t); int count = filter.Count(); if (count > 1) { list2deleted.Add(filter.First().Id); } } } } using (var ctxt = new TippSpielContext()) { foreach (var e in list2deleted) { var match = (from m in ctxt.TippMatchList where m.Id == e select m) .First(); ctxt.Entry(match).State = System.Data.EntityState.Deleted; } ctxt.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task <IEnumerable <MatchDataModel> > GetMatchesAsync(int?groupId) { if (groupId.HasValue) { return(await _matchProvider.GetMatchesByGroup(groupId.Value)); } else { return(_matchProvider.GetAllMatches()); } }
public ActionResult DailyReport(DateTime?Spieltag) { log.Debug("DailyReport begin"); var kickoff = Spieltag; // extract spieltage if (kickoff == null) { var match = _matchDataRepository.GetLastMatch(); if (match.MatchId == -1) { match = _matchDataRepository.GetNextMatch(); } kickoff = match.KickoffTimeUTC; } var matchFilter = (from m in _matchDataRepository.GetAllMatches() where m.KickoffTimeUTC.ToShortDateString() == kickoff.Value.ToShortDateString() && m.HasStarted == true select m); // build dropdown list data { var distinctByKickoff = (from m in _matchDataRepository.GetAllMatches() orderby m.KickoffTime select new { KickoffDate = m.KickoffTime.ToShortDateString(), KickoffDateUTC = m.KickoffTimeUTC.ToShortDateString() }) .DistinctBy(a => a.KickoffDateUTC); var ddlSpieltageRange = (from m in distinctByKickoff select new SelectListItem() { Value = m.KickoffDateUTC, Text = m.KickoffDate, Selected = (m.KickoffDateUTC == kickoff.Value.ToShortDateString()) }) .Distinct(); ViewBag.Spieltag = ddlSpieltageRange; } var viewModel = new DailyWinnerInfoModel(); { viewModel.MatchInfo = matchFilter.ToList(); } 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 m in matchFilter) { var tippSet = (from t in ctxt.TippMatchList where t.MatchId == m.MatchId && t.MyTip.HasValue && t.MyAmount.HasValue && t.MyOdds.HasValue select t); foreach (var tip in tippSet) { var matchModelObj = new MatchInfoModel() { MatchId = m.MatchId, GroupId = m.GroupId, MatchNr = m.MatchNr, AwayTeam = m.AwayTeam, AwayTeamIcon = m.AwayTeamIcon, AwayTeamScore = m.AwayTeamScore, HomeTeam = m.HomeTeam, HomeTeamIcon = m.HomeTeamIcon, HomeTeamScore = m.HomeTeamScore, IsFinished = m.IsFinished, KickoffTime = m.KickoffTime }; matchModelObj.MyOdds = tip.MyOdds; matchModelObj.IsJoker = tip.IsJoker; if (tip.IsJoker == true) { matchModelObj.MyAmount = tip.MyAmount * TippspielConfigInfo.Current.JokerMultiplicator; } else { matchModelObj.MyAmount = tip.MyAmount; } matchModelObj.MyTip = tip.MyTip; if (matchModelObj.HasStarted == true) { resultDict[tip.User].TippCount++; resultDict[tip.User].TotalPoints += matchModelObj.MyPoints ?? 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++; }); } log.Debug("DailyReport end"); return(View(viewModel)); }