// GET /api/tokens public Token Get() { string connectionString = ConfigurationManager.ConnectionStrings[PointValues.ConnectionStringName].ConnectionString; try { HetEKSpelEntities db = new HetEKSpelEntities(connectionString); var query = from it in db.Participants orderby it.Id select it; var deelnemersList = new List<Participant>(); foreach (var user in query) { } return new Token { Key = "foo", Secret = "bar" }; } catch (Exception e) { return new Token { Key = " ExceptionMessage: " + e, Secret = e.StackTrace.ToString() }; } }
public IEnumerable<TotoStats> GetTotoStats() { HetEKSpelEntities db = new HetEKSpelEntities(connectionString); var games = db.Games.Where(g => g.PredictionType_Id == PredictionType.Game).ToList(); var predictions = db.Predictions.Where(p => p.PredictionType_Id == PredictionType.Game).ToList(); var totoStatsList = new List<TotoStats>(); foreach (var game in games) { var homeTeam = db.Teams.SingleOrDefault(t => t.Id == game.HomeTeam_Id).Team1; var awayTeam = db.Teams.SingleOrDefault(t => t.Id == game.AwayTeam_Id).Team1; var home = predictions.Count(p => p.Game_Id == game.Id && p.TotoScore == 1); var away = predictions.Count(p => p.Game_Id == game.Id && p.TotoScore == 2); var draw = predictions.Count(p => p.Game_Id == game.Id && p.TotoScore == 3); var totoStat = new TotoStats { GameId = game.Id, HomeTeam = homeTeam, AwayTeam = awayTeam, Home = string.Format(home+"x"), Away = string.Format(away+"x"), Draw = string.Format(draw+"x"), SortId = (int) game.sortId }; totoStatsList.Add(totoStat); } var orderedTotoStatsList = totoStatsList.OrderBy(t => t.SortId).ToList(); return orderedTotoStatsList; }
public IEnumerable<PoulePrediction> GetTablePredictions(int id) { HetEKSpelEntities db = new HetEKSpelEntities(connectionString); var tablePredictions = db.Predictions.Where(p => p.Participant_Id == id && p.PredictionType_Id == PredictionType.Table); var games = db.Games.Where(g => g.PredictionType_Id == PredictionType.Table).ToList(); var teams = db.Teams.ToList(); var predictionList = new List<PoulePrediction>(); foreach (var tablePrediction in tablePredictions) { var team = teams.SingleOrDefault(t => t.Id == tablePrediction.Team_Id).Team1; const string result = ""; if (games.SingleOrDefault(g => g.HomeTeam_Id == tablePrediction.Team_Id && g.PredictionType_Id == PredictionType.Table) != null ) { games.SingleOrDefault( g => g.HomeTeam_Id == tablePrediction.Team_Id && g.PredictionType_Id == PredictionType.Table). TablePosition.ToString(); } var prediction = new PoulePrediction { Team = team, Prediction = tablePrediction.TablePosition.ToString(), Result = result, Points = tablePrediction.Points.ToString() }; predictionList.Add(prediction); } return predictionList; }
private IEnumerable<SecondRoundPrediction> GetSecondRoundPrediction(int participantId, int predictionType) { HetEKSpelEntities db = new HetEKSpelEntities(connectionString); var predictions = db.Predictions.Where(p => p.Participant_Id == participantId && p.PredictionType_Id == predictionType).ToList(); var teams = db.Teams.ToList(); var predictionList = new List<SecondRoundPrediction>(); foreach (var prediction in predictions) { var predictionLine = new SecondRoundPrediction { TeamId = (int)prediction.Team_Id, TeamName = teams.SingleOrDefault(t => t.Id == prediction.Team_Id).Team1, Short = teams.SingleOrDefault(t => t.Id == prediction.Team_Id).Short, PredictionType = prediction.PredictionType_Id, Points = prediction.Points.ToString() }; predictionList.Add(predictionLine); } return predictionList; }
public IEnumerable<ParticipantView> GetDeelnemerById(int id) { HetEKSpelEntities db = new HetEKSpelEntities(connectionString); //if (Id < 0 || Id > db.Participants.Count()) //{ // throw new HttpResponseException(System.Net.HttpStatusCode.NotFound); //} // var participantId = db.Tables.Single(t => t.Id == id).ParticipantId; var participant = db.Participants.SingleOrDefault(p => p.Id == id); var allTables = db.Tables; var latestTableId = allTables.Max(t => t.TableId); var latestTable = allTables.Where(t => t.TableId == latestTableId); var maxTableLineId = latestTable.Max(t => t.Id); var minTablelineId = latestTable.Min(t => t.Id); var tables = db.Tables.Where(t => t.ParticipantId == id).ToList(); var tableLine = tables.LastOrDefault(); var nextParticipantId = ""; var previousParticipantId = ""; if (tableLine.Id != minTablelineId) { previousParticipantId = latestTable.Single(t => t.Id == tableLine.Id - 1).ParticipantId.ToString(); } if (tableLine.Id != maxTableLineId) { nextParticipantId = latestTable.Single(t => t.Id == tableLine.Id + 1).ParticipantId.ToString(); } var deelnemersList = new List<ParticipantView>(); var deelnemer = new ParticipantView { ParticipantId = participant.Id, Location = participant.Location, Name = participant.Name, Gender = participant.Gender, Points = tableLine.TotalPoints.ToString(), Position = tableLine.Position, TablelineId = tableLine.Id.ToString(), MaxTablelineId = maxTableLineId.ToString(), MinTablelineId = minTablelineId.ToString(), NextParticipantId = nextParticipantId, PreviousParticipantId = previousParticipantId }; deelnemersList.Add(deelnemer); return deelnemersList; }
public static IEnumerable<DetailTableView> GetLatestDetailedTable() { string connectionString = ConfigurationManager.ConnectionStrings["HetEKSpelEntities"].ConnectionString; HetEKSpelEntities db = new HetEKSpelEntities(connectionString); var latestTableId = Standen.GetLatestTableId(); var table = db.Tables.Where(t => t.TableId == latestTableId); var participants = from it in db.Participants select it; var list = participants.ToList(); var detailedTableView = new List<DetailTableView>(); foreach (var line in table) { var newLine = new DetailTableView() { Id =line.Id, ParticipantId = line.ParticipantId, Position = line.Position, ParticipantName = list.SingleOrDefault(p => p.Id == line.ParticipantId).Name, TotalPoints = line.TotalPoints, PouleA = line.PouleA, PouleB = line.PouleB, PouleC = line.PouleC, PouleD = line.PouleD, PouleTables = line.Table1, QuarterFinal = line.QuarterFinals, SemiFinal = line.SemiFinals, Final = line.Finals, Winner = line.Winner }; detailedTableView.Add(newLine); } return detailedTableView; }
public IEnumerable<ParticipantView> GetAllDeelnemers() { HetEKSpelEntities db = new HetEKSpelEntities(connectionString); var query = db.Participants; var participantsList = new List<ParticipantView>(); foreach (var participant in query) { var newParticipant = new ParticipantView { ParticipantId = participant.Id, Location = participant.Location, Name = participant.Name, Gender = participant.Gender }; participantsList.Add(newParticipant); } return participantsList.OrderBy(p=>p.ParticipantId); }
public static IEnumerable<DetailTableView> GetLatestGameTable() { string connectionString = ConfigurationManager.ConnectionStrings["HetEKSpelEntities"].ConnectionString; HetEKSpelEntities db = new HetEKSpelEntities(connectionString); var latestTableId = Standen.GetLatestTableId(); var table = db.Tables.Where(t => t.TableId == latestTableId); var participants = from it in db.Participants select it; var list = participants.ToList(); var detailedTableView = new List<DetailTableView>(); foreach (var line in table) { var newLine = new DetailTableView() { Id = line.Id, ParticipantId = line.ParticipantId, Position = line.Position, ParticipantName = list.SingleOrDefault(p => p.Id == line.ParticipantId).Name, TotalPoints = line.PouleA + line.PouleB + line.PouleC + line.PouleD, PouleA = line.PouleA, PouleB = line.PouleB, PouleC = line.PouleC, PouleD = line.PouleD }; detailedTableView.Add(newLine); } var orderedTable = detailedTableView.OrderByDescending(d => d.TotalPoints); //Add position to Table var position = 0; var previous = -1; foreach (var standLine in orderedTable) { if (position == 0) { position++; standLine.Position = position; } else { if (orderedTable.ElementAt(previous).TotalPoints == standLine.TotalPoints) { standLine.Position = position; } else { position = previous + 2; standLine.Position = position; } } previous++; } return orderedTable; }
public static int GetLatestTableId() { string connectionString = ConfigurationManager.ConnectionStrings["HetEKSpelEntities"].ConnectionString; HetEKSpelEntities db = new HetEKSpelEntities(connectionString); var table = db.Tables.ToList(); if (table.Count == 0) { return 0; } return db.Tables.Max(t => t.TableId); }
public static IEnumerable<TableView> GetLatestTable() { string connectionString = ConfigurationManager.ConnectionStrings["HetEKSpelEntities"].ConnectionString; HetEKSpelEntities db = new HetEKSpelEntities(connectionString); var latestTableId = Standen.GetLatestTableId(); var table = db.Tables.Where(t => t.TableId == latestTableId); var participants = from it in db.Participants select it; var list = participants.ToList(); var tableView = new List<TableView>(); foreach (var line in table) { var newLine = new TableView { Id = line.Id, ParticipantId = line.ParticipantId, Position = line.Position, ParticipantName = list.SingleOrDefault(p => p.Id == line.ParticipantId).Name, TotalPoints = line.TotalPoints }; tableView.Add(newLine); } return tableView; }
public IEnumerable<GameView> GetAllDeelnemers() { HetEKSpelEntities db = new HetEKSpelEntities(connectionString); var firstRoundMatches = db.Games.Where(g => g.PredictionType_Id == PredictionType.Game).ToList(); var secondRoundMatches = db.SecondRounds.ToList(); var teams = db.Teams.ToList(); var gameView = new List<GameView>(); foreach (var firstRoundMatch in firstRoundMatches) { var awayTeamShort = teams.Single(t => t.Id == firstRoundMatch.AwayTeam_Id).Short; var homeTeamShort = teams.Single(t => t.Id == firstRoundMatch.HomeTeam_Id).Short; var awayTeam = teams.Single(t => t.Id == firstRoundMatch.AwayTeam_Id).Team1; var homeTeam = teams.Single(t => t.Id == firstRoundMatch.HomeTeam_Id).Team1; var newline = new GameView { AwayScore = firstRoundMatch.AwayScore.ToString(), HomeScore = firstRoundMatch.HomeScore.ToString(), AwayTeam = awayTeam, HomeTeam = homeTeam, AwayTeamShort = awayTeamShort, HomeTeamShort = homeTeamShort, GameId = firstRoundMatch.Id, Date = string.Format(firstRoundMatch.Date +" om " +firstRoundMatch.Time), City = firstRoundMatch.City, SortId = (int) firstRoundMatch.sortId }; gameView.Add(newline); } foreach (var secondRoundMatch in secondRoundMatches) { var awayTeam = teams.Single(t => t.Id == secondRoundMatch.AwayTeam_Id).Team1; var homeTeam = teams.Single(t => t.Id == secondRoundMatch.HomeTeam_Id).Team1; var awayTeamShort = teams.Single(t => t.Id == secondRoundMatch.AwayTeam_Id).Short; var homeTeamShort = teams.Single(t => t.Id == secondRoundMatch.HomeTeam_Id).Short; var newline = new GameView { //todo scores meegeven HomeScore = secondRoundMatch.HomeScore.ToString(), AwayScore = string.Format(secondRoundMatch.AwayScore +" "+ secondRoundMatch.Uitslag), AwayTeamShort = awayTeamShort, HomeTeamShort = homeTeamShort, AwayTeam = awayTeam, HomeTeam = homeTeam, GameId = secondRoundMatch.Id, Date = string.Format(secondRoundMatch.Date + " om " + secondRoundMatch.Time), City = secondRoundMatch.City, SortId = secondRoundMatch.Id }; gameView.Add(newline); } var sortedList = gameView.OrderBy(g => g.SortId).ToList(); return sortedList; }