static void Main(string[] args) { using (var context = new TtcDbContext()) { try { // This code can be triggered from the UI! // Admin > Spelers > Frenoy Sync button (float: right) //var vttlPlayers = new FrenoyPlayersApi(context, Competition.Vttl); //vttlPlayers.StopAllPlayers(true); //vttlPlayers.SyncPlayers(); //var sportaPlayers = new FrenoyPlayersApi(context, Competition.Sporta); //sportaPlayers.SyncPlayers(); // This code can be triggered by deploying a new migration // --> No more at the moment with asyncy stuff see README. var vttl = new FrenoyMatchesApi(context, Competition.Vttl); vttl.SyncTeamsAndMatches(); var sporta = new FrenoyMatchesApi(context, Competition.Sporta); sporta.SyncTeamsAndMatches(); //RandomizeMatchDatesForTestingPurposes(context); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } } }
//private readonly StringBuilder _log = new StringBuilder(); private void CommitChanges() { //_db.Database.Log = Console.Write; //_db.Database.Log = message => _log.AppendLine(message); //_db.Database.Log = _logFile.Write; _db.SaveChanges(); //_db.Database.Log = null; }
public Player UpdateStyle(PlayerStyle playerStyle) { using (var dbContext = new TtcDbContext()) { var existingSpeler = dbContext.Players.FirstOrDefault(x => x.Id == playerStyle.PlayerId); if (existingSpeler == null) { return null; } existingSpeler.Stijl = playerStyle.Name; existingSpeler.BesteSlag = playerStyle.BestStroke; dbContext.SaveChanges(); } var newMatch = GetPlayer(playerStyle.PlayerId); return newMatch; }
public async Task <Match> UpdateScore(int matchId, MatchScore score) { using (var dbContext = new TtcDbContext()) { var match = await dbContext.Matches .WithIncludes() .SingleAsync(x => x.Id == matchId); if (match.IsSyncedWithFrenoy) { return(await GetMatch(dbContext, match.Id)); } match.AwayScore = score.Out; match.HomeScore = score.Home; dbContext.SaveChanges(); return(await GetMatch(dbContext, match.Id)); } }
public async Task <Team> ToggleTeamPlayer(TeamToggleRequest req) { using (var db = new TtcDbContext()) { var team = db.Teams.Include(x => x.Players).Single(x => x.Id == req.TeamId); var exPlayer = team.Players.SingleOrDefault(x => x.PlayerId == req.PlayerId); if (exPlayer == null) { team.Players.Add(new TeamPlayerEntity { PlayerId = req.PlayerId, TeamId = req.TeamId, PlayerType = (TeamPlayerType)Enum.Parse(typeof(TeamPlayerType), req.Role) }); } else { db.Entry(exPlayer).State = EntityState.Deleted; } db.SaveChanges(); return(await GetTeam(req.TeamId, false)); } }
public void FixExcessWhitespaceAndTelephoneNumbers() { using (var dbContext = new TtcDbContext()) { foreach (var player in dbContext.Players) { if (player.Email != null) { player.Email = player.Email.Trim(); } if (player.Adres != null) { player.Adres = player.Adres.Trim(); } if (player.Gemeente != null) { player.Gemeente = player.Gemeente.Trim(); } //player.BesteSlag = player.BesteSlag.Trim(); //player.Stijl = player.Stijl.Trim(); player.Gsm = FixGsm(player.Gsm); } foreach (var player in dbContext.ClubLokalen) { //player.Adres = player.Adres.Trim(); //player.Gemeente = player.Gemeente.Trim(); player.Telefoon = FixGsm(player.Telefoon); } dbContext.SaveChanges(); } }
public Team ToggleTeamPlayer(TeamToggleRequest req) { using (var db = new TtcDbContext()) { var team = db.Teams.Include(x => x.Players).Single(x => x.Id == req.TeamId); var exPlayer = team.Players.SingleOrDefault(x => x.PlayerId == req.PlayerId); if (exPlayer == null) { team.Players.Add(new TeamPlayerEntity { PlayerId = req.PlayerId, TeamId = req.TeamId, PlayerType = (TeamPlayerType)Enum.Parse(typeof(TeamPlayerType), req.Role) }); } else { db.Entry(exPlayer).State = EntityState.Deleted; } db.SaveChanges(); return GetTeam(req.TeamId, false); } }
public Match DeleteComment(int commentId) { using (var dbContext = new TtcDbContext()) { var comment = dbContext.MatchComments.Single(x => x.Id == commentId); dbContext.MatchComments.Remove(comment); dbContext.SaveChanges(); return GetMatch(dbContext, comment.MatchId); } }
public Match AddComment(MatchComment comment) { using (var dbContext = new TtcDbContext()) { var entity = Mapper.Map<MatchCommentEntity>(comment); entity.PostedOn = TtcDbContext.GetCurrentBelgianDateTime(); dbContext.MatchComments.Add(entity); dbContext.SaveChanges(); } var newMatch = GetMatch(comment.MatchId); return newMatch; }
public Match UpdateReport(MatchReport report) { using (var dbContext = new TtcDbContext()) { var existingMatch = dbContext.Matches.First(x => x.Id == report.MatchId); existingMatch.ReportPlayerId = report.PlayerId; existingMatch.Description = report.Text; dbContext.SaveChanges(); } var newMatch = GetMatch(report.MatchId); return newMatch; }
/// <summary> /// Set all players for the match to Captain/Major /// </summary> /// <param name="blockAlso">Also block the match to the newStatus level</param> public Match EditMatchPlayers(int matchId, int[] playerIds, string newStatus, bool blockAlso) { Debug.Assert(newStatus == PlayerMatchStatus.Captain || newStatus == PlayerMatchStatus.Major); using (var db = new TtcDbContext()) { var match = db.Matches.Single(x => x.Id == matchId); match.Block = blockAlso ? newStatus : null; var existingPlayers = db.MatchPlayers .Where(x => x.MatchId == matchId) .Where(x => x.Status == newStatus) .ToArray(); db.MatchPlayers.RemoveRange(existingPlayers); for (int i = 0; i < playerIds.Length; i++) { var player = db.Players.Find(playerIds[i]); var newMatchPlayer = new MatchPlayerEntity { Id = i * -1, MatchId = matchId, PlayerId = player.Id, Name = player.NaamKort, Status = newStatus, Ranking = match.Competition == Competition.Vttl ? player.KlassementVttl : player.KlassementSporta, Home = match.IsHomeMatch.Value, Position = i }; db.MatchPlayers.Add(newMatchPlayer); } db.SaveChanges(); } var newMatch = GetMatch(matchId); return newMatch; }
/// <summary> /// Toggle Captain/Major player by any player of the team on the day of the match /// </summary> public Match ToggleMatchPlayer(MatchPlayer matchPlayer) { Debug.Assert(matchPlayer.Status == PlayerMatchStatus.Captain || matchPlayer.Status == PlayerMatchStatus.Major); using (var dbContext = new TtcDbContext()) { var match = dbContext.Matches.Find(matchPlayer.MatchId); var existingPlayer = dbContext.MatchPlayers .Where(x => x.MatchId == matchPlayer.MatchId && x.PlayerId == matchPlayer.PlayerId) .FirstOrDefault(x => x.Status == matchPlayer.Status); match.Block = matchPlayer.Status; if (existingPlayer != null) { dbContext.MatchPlayers.Remove(existingPlayer); } else { dbContext.MatchPlayers.Add(Mapper.Map<MatchPlayer, MatchPlayerEntity>(matchPlayer)); } dbContext.SaveChanges(); } var newMatch = GetMatch(matchPlayer.MatchId); return newMatch; }
public Match SetMyFormation(MatchPlayer matchPlayer) { using (var dbContext = new TtcDbContext()) { var existingPlayer = dbContext.MatchPlayers .Include(x => x.Match) .Where(x => x.MatchId == matchPlayer.MatchId && x.PlayerId == matchPlayer.PlayerId) .FirstOrDefault(x => x.Status != PlayerMatchStatus.Captain && x.Status != PlayerMatchStatus.Major); if (existingPlayer != null) { existingPlayer.Status = matchPlayer.Status; existingPlayer.StatusNote = matchPlayer.StatusNote; } else { var verslagSpeler = Mapper.Map<MatchPlayer, MatchPlayerEntity>(matchPlayer); dbContext.MatchPlayers.Add(verslagSpeler); } dbContext.SaveChanges(); } var newMatch = GetMatch(matchPlayer.MatchId); return newMatch; }
public Match UpdateScore(int matchId, MatchScore score) { using (var dbContext = new TtcDbContext()) { var match = dbContext.Matches .WithIncludes() .Single(x => x.Id == matchId); match.AwayScore = score.Out; match.HomeScore = score.Home; dbContext.SaveChanges(); return GetMatch(dbContext, match.Id); } }
public Player UpdatePlayer(Player player) { using (var dbContext = new TtcDbContext()) { var existingSpeler = dbContext.Players.FirstOrDefault(x => x.Id == player.Id); if (existingSpeler == null) { existingSpeler = new PlayerEntity(); MapPlayer(player, existingSpeler); dbContext.Players.Add(existingSpeler); } else { MapPlayer(player, existingSpeler); } dbContext.SaveChanges(); player.Id = existingSpeler.Id; } var newPlayer = GetPlayer(player.Id); return newPlayer; }
public Guid EmailMatchesPlayer(string email, int playerId) { using (var dbContext = new TtcDbContext()) { var player = dbContext.Players.SingleOrDefault(x => x.Id == playerId && x.Email.ToLower() == email.ToLower()); if (player == null) { throw new Exception("Email komt niet overeen voor " + playerId); } var passwordReset = new PlayerPasswordResetEntity(playerId); dbContext.PlayerPasswordResets.Add(passwordReset); dbContext.SaveChanges(); return passwordReset.Guid; } }