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);
            }
        }
Exemple #2
0
        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);
                }
            }
        }