private EmailReminderInfoModel GetEmailReminders() { using (var ctxt = new UsersContext()) { var reminderModel = new EmailReminderInfoModel(); var nextMatch = _matchDataRepository.GetNextMatch(); reminderModel.KickoffTime = nextMatch.KickoffTime; reminderModel.HomeTeam = nextMatch.HomeTeam; reminderModel.AwayTeam = nextMatch.AwayTeam; using (var tippContext = new TippSpielContext()) { var tippList = (from t in tippContext.TippMatchList where t.MatchId == nextMatch.MatchId select t); foreach (var user in ctxt.UserProfiles) { var tippObj = (from userTipp in tippList where userTipp.User == user.UserName select userTipp) .FirstOrDefault(); reminderModel.EmailReminderDict.Add(user.UserName, IsSendEmailReminder(user, nextMatch, tippObj)); } } return(reminderModel); } }
public static SpieltagInfo GetSpieltagInfo(IFussballDataRepository repository) { var spieltagInfo = new SpieltagInfo(); spieltagInfo.CurrentSpieltag = spieltagInfo.TippSpieltag = 1; var dataNext = repository.GetNextMatch(); var dataLast = repository.GetLastMatch(); if (dataNext == null && dataLast == null) { return(spieltagInfo); } if (dataNext == null || (dataNext.MatchId == -1)) //e.g. last season { spieltagInfo.CurrentSpieltag = dataLast.GroupId; return(spieltagInfo); } if (dataLast == null || (dataLast.GroupId > dataNext.GroupId)) //e.g. last season { spieltagInfo.CurrentSpieltag = spieltagInfo.TippSpieltag = dataNext.GroupId; return(spieltagInfo); } if (dataNext.GroupId > dataLast.GroupId) { spieltagInfo.CurrentSpieltag = dataLast.GroupId; spieltagInfo.TippSpieltag = dataNext.GroupId; } else { spieltagInfo.CurrentSpieltag = spieltagInfo.TippSpieltag = dataLast.GroupId; spieltagInfo.IsCompleted = true; } return(spieltagInfo); }
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)); }