public ActionResult Clear()
        {
            // delete all tipper data
            using (var ctxt = new TippSpielContext())
            {
                foreach (var tipp in ctxt.TippMatchList)
                {
                    ctxt.Entry(tipp).State = EntityState.Deleted;
                }

                ctxt.SaveChanges();
            }

            // delete all users
            var users = GetUserList();

            foreach (var user in users)
            {
                var username = user.username;

                try
                {
                    if (WebSecurity.UserExists(username) == true)
                    {
                        Membership.DeleteUser(username);
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    log.ErrorFormat("User {0} not created: {1}", user.username, e.Message);
                }
            }

            return(RedirectToAction("Index"));
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        public ActionResult ReportDailyWinners()
        {
            _log.Debug("Begin All DailyWinners");

            using (var client = new SvcFussballDB.SportsdataSoapClient())
            {
                int endSpieltag   = OpenDBHelper.GetSpieltagInfo(_matchDataRepository).CurrentSpieltag;
                int beginSpieltag = SportsdataConfigInfo.Current.StartSpieltag;

                var allWinnersModel = new OverallDailyWinnerInfoModel();

                using (var ctxt = new TippSpielContext())
                {
                    using (var userCtxt = new UsersContext())
                    {
                        var allUsers = (from t in ctxt.TippMatchList select t.User).Distinct().ToArray();
                        foreach (var user in allUsers)
                        {
                            var displayName =
                                (from u in userCtxt.UserProfiles where u.UserName == user select u.DisplayName)
                                .FirstOrDefault();

                            allWinnersModel.AllDailyWinnerMap.Add(user, new OverallDailyWinnerRankingItemModel()
                            {
                                User        = user,
                                DisplayName = displayName,
                                Rang        = -1,
                                Wins        = 0
                            });
                        }
                    }
                }


                for (int day = beginSpieltag; day <= endSpieltag; day++)
                {
                    var result = DailyWinnersInternal(day);
                    foreach (var item in result.Ranking.Where(r => r.Rang == 1))
                    {
                        allWinnersModel.AllDailyWinnerMap[item.User].Wins += 1;
                    }
                }

                var orderResult = (from kp in allWinnersModel.AllDailyWinnerMap orderby kp.Value.Wins descending select kp).ToDictionary(p => p.Key, p => p.Value);
                int counter     = 1;
                orderResult.ForEach(e => { e.Value.Rang = counter++; });


                allWinnersModel.AllDailyWinnerMap = orderResult;

                _log.Debug("End All DailyWinners");

                return(View(allWinnersModel));
            }
        }
        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 ActionResult DeleteTipps()
        {
            // delete all tipper data
            using (var ctxt = new TippSpielContext())
            {
                foreach (var tipp in ctxt.TippMatchList)
                {
                    ctxt.Entry(tipp).State = System.Data.EntityState.Deleted;
                }

                ctxt.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Пример #6
0
            public TippspielDBInitializer()
            {
                Database.SetInitializer <TippSpielContext>(null);

                try
                {
                    using (var context = new TippSpielContext())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the tipp database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("Tippspiel database could not be initialized.", ex);
                }
            }
        public ActionResult CorrectJokerTipps()
        {
            var allMatches = _matchDataRepository.GetAllMatches();

            using (var ctxt = new TippSpielContext())
            {
                var jokerTipps = (from t in ctxt.TippMatchList
                                  where t.IsJoker == true
                                  select t);

                foreach (var t in jokerTipps)
                {
                    if (allMatches.Where(m => m.MatchId == t.MatchId).FirstOrDefault() == null)
                    {
                        t.IsJoker = false;
                    }
                }

                ctxt.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Пример #8
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));
        }
Пример #9
0
        public JsonResult SetMatchTipp(int id, int groupId, int tip, double?odds)
        {
            try
            {
                var user = User.Identity.Name.Trim().ToLower();

                log.Debug($"match id={id}, tip={tip}, odds={odds:0.00}, user={user}");

                var matchToTip = _matchDataRepository.GetMatchData(id);

                if (matchToTip != null)
                {
                    if (matchToTip.KickoffTime < DateTime.Now)
                    {
                        log.Warn($"User {user} tried to change tip for match {id} after kickoff time utc {matchToTip.KickoffTime}");

                        return(Json(new
                        {
                            Success = false,
                            Error = "Tipp kann nicht mehr entgegengenommen werden. Das Spiel hat bereits begonnnen.",
                            MatchId = id
                        }));
                    }
                }

                using (var ctxt = new TippSpielContext())
                {
                    var matchObj = (from m in ctxt.TippMatchList
                                    where m.MatchId == id &&
                                    m.User == user
                                    select m)
                                   .FirstOrDefault();

                    if (matchObj == null)
                    {
                        var newMatchObj = new TippMatchModel()
                        {
                            MatchId     = id,
                            GroupId     = groupId,
                            MyOdds      = odds,
                            MyTip       = tip,
                            MyAmount    = MapGroup2Amount(groupId),
                            User        = user,
                            LastUpdated = DateTime.Now
                        };

                        ctxt.TippMatchList.Add(newMatchObj);
                    }
                    else
                    {
                        matchObj.LastUpdated = DateTime.Now;
                        matchObj.GroupId     = groupId;
                        matchObj.User        = user;
                        matchObj.MyOdds      = odds;
                        matchObj.MyTip       = tip;
                        matchObj.MyAmount    = MapGroup2Amount(groupId);
                        matchObj.MyTip       = tip;
                    }

                    ctxt.SaveChanges();

                    var result = new
                    {
                        Success = true,
                        MatchId = id,
                        MyOdds  = $"{odds:0.00}"
                    };

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

                    return(Json(result));
                }
            }
            catch (FormatException ex)
            {
                log.ErrorFormat("Match id cannot be converted, id={0}." + id.ToString());
                log.ErrorFormat("Exception message={0}." + ex.Message);

                return(Json(new {
                    Success = false,
                    Error = ex.Message,
                    MatchId = id
                }));
            }
        }
Пример #10
0
        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));
        }
Пример #11
0
        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));
            }
        }
Пример #12
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);
                }
            }
        }
Пример #13
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));
        }
Пример #14
0
        public JsonResult SetMatchTipp(int id, int tip, double?odds)
        {
            try
            {
                var user = User.Identity.Name.ToLower();

                _log.DebugFormat("match id={0}, tip={1}, odds={2:0.00}, user={3}", id, tip, odds, user);

                using (var ctxt = new TippSpielContext())
                {
                    var matchObj = (from m in ctxt.TippMatchList
                                    where m.MatchId == id &&
                                    m.User == user
                                    select m)
                                   .FirstOrDefault();

                    if (matchObj == null)
                    {
                        var newMatchObj = new TippMatchModel()
                        {
                            MatchId     = id,
                            MyOdds      = odds,
                            MyTip       = tip,
                            MyAmount    = 1.0,
                            User        = user,
                            LastUpdated = DateTime.Now
                        };

                        ctxt.TippMatchList.Add(newMatchObj);
                    }
                    else
                    {
                        matchObj.LastUpdated = DateTime.Now;
                        matchObj.User        = user;
                        matchObj.MyOdds      = odds;
                        matchObj.MyTip       = tip;
                        matchObj.MyAmount    = 1.0;
                        matchObj.MyTip       = tip;
                    }

                    ctxt.SaveChanges();

                    var result = new
                    {
                        Success = true,
                        MatchId = id,
                        MyOdds  = String.Format("{0:0.00}", odds)
                    };

                    return(Json(result));
                }
            }
            catch (FormatException ex)
            {
                _log.ErrorFormat("Match id cannot be converted, id={0}." + id.ToString());
                _log.ErrorFormat("Exception message={0}." + ex.Message);

                return(Json(new {
                    Success = false,
                    Error = ex.Message,
                    MatchId = id
                }));
            }
        }
Пример #15
0
        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 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));
        }