Example #1
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
                }));
            }
        }
Example #2
0
        private static bool IsSendEmailReminder(UserProfile user, MatchDataModel matchObj, TippMatchModel tippObj)
        {
            if (user.HasEmailReminder == false)
            {
                return(false);
            }

            if ((tippObj == null || tippObj.MyTip.HasValue == false) &&
                (matchObj.KickoffTime > DateTime.Now) &&
                (DateTime.Now > matchObj.KickoffTime.AddDays(-1)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
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
                }));
            }
        }
        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));
        }