public ActionResult GetAllMatches(int spieltag)
        {
            var matches = _matchDataRepository.GetMatchesByGroup(spieltag);

            using (var ctxt = new MatchInfoContext())
            {
                foreach (var m in matches)
                {
                    ctxt.Items.Add(new MatchInfoItem()
                    {
                        GroupId         = m.GroupId,
                        MatchId         = m.MatchId,
                        MatchNr         = m.MatchNr,
                        HomeTeamId      = m.HomeTeamId,
                        AwayTeamId      = m.AwayTeamId,
                        HomeTeam        = m.HomeTeam,
                        AwayTeam        = m.AwayTeam,
                        HomeTeamScore   = m.HomeTeamScore,
                        AwayTeamScore   = m.AwayTeamScore,
                        HomeTeamIcon    = m.HomeTeamIcon,
                        AwayTeamIcon    = m.AwayTeamIcon,
                        KickoffTime     = m.KickoffTime,
                        KickoffTimeUtc  = m.KickoffTimeUTC,
                        IsFinished      = m.IsFinished,
                        HasProlongation = m.HasVerlaengerung
                    });
                }

                ctxt.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public async Task <IEnumerable <MatchDataModel> > GetMatchesAsync(int?groupId)
 {
     if (groupId.HasValue)
     {
         return(await _matchProvider.GetMatchesByGroup(groupId.Value));
     }
     else
     {
         return(_matchProvider.GetAllMatches());
     }
 }
Beispiel #3
0
        public ActionResult Index(int?Spieltag)
        {
            log.Debug("Index begin");

            var allGroups = _matchDataRepository.GetAllGroups();

            int currentSpieltag = Spieltag ?? SportsdataConfigInfo.Current.CurrentSpieltag;

            // build dropdown list data
            {
                var count             = SportsdataConfigInfo.Current.EndSpieltag - SportsdataConfigInfo.Current.StartSpieltag + 1;
                var ddlSpieltageRange = (from e in allGroups
                                         where e.Id <= SportsdataConfigInfo.Current.EndSpieltag &&
                                         e.Id >= SportsdataConfigInfo.Current.StartSpieltag
                                         select new SelectListItem()
                {
                    Value = e.Id.ToString(),
                    Text = e.Text,
                    Selected = (e.Id == currentSpieltag)
                });

                ViewBag.Spieltag = ddlSpieltageRange;
            }

            var model = new SpieltagModel();

            model.GroupId   = currentSpieltag;
            model.GroupName = allGroups.Find(g => g.Id == currentSpieltag).Text;

            var oddsList = _quoteRepository.GetOdds(currentSpieltag);

            var matches = _matchDataRepository.GetMatchesByGroup(currentSpieltag);

            matches = (from m in matches
                       orderby m.KickoffTime
                       select m).ToList();

            foreach (var m in matches)
            {
                var modelAllInfo = 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
                };

                // mixin odds quotes into match data
                MixinOddsQuotes(oddsList, modelAllInfo);

                using (var ctxt = new TippSpielContext())
                {
                    var myTippObject = (from t in ctxt.TippMatchList
                                        where t.MatchId == modelAllInfo.MatchId &&
                                        t.User == User.Identity.Name
                                        select t)
                                       .FirstOrDefault();

                    if (myTippObject != null)
                    {
                        modelAllInfo.MyOdds   = myTippObject.MyOdds;
                        modelAllInfo.MyTip    = myTippObject.MyTip;
                        modelAllInfo.IsJoker  = myTippObject.IsJoker;
                        modelAllInfo.MyAmount = myTippObject.MyAmount;
                    }
                }


                model.Matchdata.Add(modelAllInfo);
            }

            model.MaxJokers     = TippspielConfigInfo.Current.MaxJokerTips;
            model.NumJokersUsed = model.Matchdata.Count(m => m.IsJoker);

            {
                log.DebugFormat("Tipp data stats: remote hits={0}, cache hits={1}", MatchDBStats.GetRemoteHits(), MatchDBStats.GetCacheHits());
            }

            log.Debug("Index end");

            return(View(model));
        }
Beispiel #4
0
        public ActionResult Index(int?Spieltag)
        {
            var spieltagInfo = OpenDBHelper.GetSpieltagInfo(_matchDataRepository);

            int currentSpieltag = (Spieltag.HasValue == true) ?
                                  Spieltag.Value :
                                  spieltagInfo.TippSpieltag;

            // 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 == currentSpieltag)
                });

                ViewBag.Spieltag = ddlSpieltageRange;
            }

            var model = new SpieltagModel();

            model.Spieltag = currentSpieltag;

            if ((currentSpieltag == 34 || currentSpieltag == 0) && spieltagInfo.IsCompleted)
            {
                model.IsTippSpielFinished = true;
                return(View(model));
            }

            List <OddsInfoModel> oddsList = null;

            try
            {
                oddsList = WettfreundeScraper.Scrap(currentSpieltag);
            }
            catch (Exception ex)
            {
                _log.Error("Error while scrab odds: " + ex.Message);
                string fixFilename = String.Format("Odds_{0}_{1}_{2}", SportsdataConfigInfo.Current.LeagueShortcut, SportsdataConfigInfo.Current.LeagueSaison, currentSpieltag);
                _log.Info("Try fix: " + fixFilename);

                ResourceManager rm         = new ResourceManager(typeof(Resources));
                var             fixContent = rm.GetObject(fixFilename) as string;

                var oddScraper = new WettfreundeOddsBuLiScraper();

                oddsList = oddScraper.GetOdds(fixContent, currentSpieltag.ToString());
            }

            var matches = _matchDataRepository.GetMatchesByGroup(currentSpieltag);

            foreach (var m in matches)
            {
                var modelAllInfo = new MatchInfoModel()
                {
                    MatchId       = m.MatchId,
                    AwayTeam      = m.AwayTeam,
                    AwayTeamIcon  = m.AwayTeamIcon,
                    AwayTeamScore = m.AwayTeamScore,
                    HomeTeam      = m.HomeTeam,
                    HomeTeamIcon  = m.HomeTeamIcon,
                    HomeTeamScore = m.HomeTeamScore,
                    IsFinished    = m.IsFinished,
                    KickoffTime   = m.KickoffTime
                };

                model.IsSpieltagFinished = (model.IsSpieltagFinished && modelAllInfo.IsFinished);

                // mixin odds quotes into match data
                {
                    MixinOddsQuotes(oddsList, modelAllInfo);
                }

                using (var ctxt = new TippSpielContext())
                {
                    var myTippObject = (from t in ctxt.TippMatchList
                                        where t.MatchId == modelAllInfo.MatchId &&
                                        t.User == User.Identity.Name
                                        select t)
                                       .FirstOrDefault();

                    if (myTippObject != null)
                    {
                        modelAllInfo.MyOdds   = myTippObject.MyOdds;
                        modelAllInfo.MyTip    = myTippObject.MyTip;
                        modelAllInfo.MyAmount = myTippObject.MyAmount;
                    }
                }


                model.Matchdata.Add(modelAllInfo);
            }

            {
                _log.DebugFormat("Tipp data stats: remote hits={0}, cache hits={1}", MatchDBStats.GetRemoteHits(), MatchDBStats.GetCacheHits());
            }

            return(View(model));
        }