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")); }
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")); }
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")); }
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 })); } }
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)); }