public List<GameSchedulesViewModel> GetGames(int seasonId, int divisionId, int teamId) { using (var db = new CSBCDbContext()) { var rep = new TeamRepository(db); var team = rep.GetById(teamId); int teamNo; if (Int32.TryParse(team.TeamNumber, out teamNo)) { var scheduleNumber = db.Set<ScheduleGame>().FirstOrDefault(g => g.DivisionId == divisionId).ScheduleNumber; var teamNumber = db.Set<ScheduleDivTeam>() .FirstOrDefault(s => s.ScheduleTeamNumber == teamNo && s.ScheduleNumber == scheduleNumber).TeamNumber; var result = (from t in db.Teams from g in db.ScheduleGames from l in db.ScheduleLocations where g.SeasonId == seasonId where t.TeamID == teamId where (g.VisitingTeamNumber == teamNumber || g.HomeTeamNumber == teamNumber) where g.ScheduleNumber == scheduleNumber where g.LocationNumber == l.LocationNumber select new GameSchedulesViewModel { DivisionID = t.DivisionID, GameDate = g.GameDate, GameTimeString = g.GameTime, LocationName = l.LocationName, GameNumber = g.GameNumber, VisitingTeamNumber = g.VisitingTeamNumber, HomeTeamNumber = g.HomeTeamNumber, ScheduleNumber = g.ScheduleNumber, HomeTeamScore = (int)g.HomeTeamScore, VisitingTeamScore = (int)g.VisitingTeamScore }); List<TeamViewModel> teams; //var count = result.Count<GameSchedulesViewModel>(); var games = GetTeamNamesFromScheduledGames(db, result); var playoffGames = GetPlayoffGames(divisionId); games.AddRange(playoffGames); return games; } else { return new List<GameSchedulesViewModel>(); } } }
private static List<GameSchedulesViewModel> GetTeamNamesFromScheduledGames(CSBCDbContext db, IQueryable<GameSchedulesViewModel> result) { List<GameSchedulesViewModel> games = new List<GameSchedulesViewModel>(); var teams = TeamViewModel.GetDivisionTeams(result.FirstOrDefault<GameSchedulesViewModel>().DivisionID); var schedDiv = db.Set<ScheduleDivTeam>().Select(s => s).ToList<ScheduleDivTeam>(); foreach (GameSchedulesViewModel game in result) { //first get real game time DateTime time; if (DateTime.TryParse(game.GameTimeString, out time)) game.GameTime = time; game.GameDate = CombineDateAndTime(game.GameDate, game.GameTime); game.VisitingTeamSeasonNumber = schedDiv.FirstOrDefault(s => s.ScheduleNumber == game.ScheduleNumber && s.TeamNumber == game.VisitingTeamNumber).ScheduleTeamNumber; if (teams.Any()) { var team = teams.FirstOrDefault(t => t.TeamNo == game.VisitingTeamSeasonNumber); if (team != null) game.VisitingTeamName = team.TeamName; } game.HomeTeamSeasonNumber = schedDiv.FirstOrDefault(s => s.ScheduleNumber == game.ScheduleNumber && s.TeamNumber == game.HomeTeamNumber).ScheduleTeamNumber; if (teams.Any()) ////get teamID! { var team = teams.FirstOrDefault(t => t.TeamNo == game.HomeTeamSeasonNumber); if (team != null) game.HomeTeamName = team.TeamName; } games.Add(game); } return games; }
public int GetScheduleNumber(string divisionName) { try { using (var db = new CSBCDbContext()) { var scheduleNo = db.Set<ScheduleDivision>().FirstOrDefault(s => s.ScheduleName.ToUpper() == divisionName.ToUpper()).ScheduleNumber; return scheduleNo; } } catch (Exception e) { //MasterVM.MsgBox(Msg.e() return 0; } }
//Private Sub CheckForStats() // If KeepStats() Then // 'transfer to stats // Response.Redirect("GamesStats.aspx") // Exit Sub // End If //End Sub private bool CheckAD(int divisionId, User user) { bool functionReturnValue = false; using (var db = new CSBCDbContext()) { var divisionRepo = new DivisionRepository(db); var division = divisionRepo.GetById(divisionId); if (division.DirectorID != 0) { if (user.HouseID != 0) { var householdMembers = db.Set<Person>().Where(p => p.HouseID == user.HouseID); functionReturnValue = householdMembers.Any(h => h.PeopleID == division.DirectorID); lblName.Text = user.Name; lblName.Visible = true; } } } return functionReturnValue; }
public List<ScheduleGamesVM> GetGames(int divisionId) { using (var db = new CSBCDbContext()) { var rep = new ScheduleGameRepository(db); var games = (from g in db.ScheduleGames from d in db.Divisions from l in db.ScheduleLocations where (g.DivisionId == divisionId) where (d.DivisionID == divisionId) where (g.LocationNumber == l.LocationNumber) select new { g.ScheduleNumber, g.DivisionId, g.GameDate, g.GameTime, d.Div_Desc, g.LocationNumber, l.LocationName, g.GameNumber, HomeTeamNo = db.Set<ScheduleDivTeam>().FirstOrDefault(t => t.TeamNumber == g.HomeTeamNumber).ScheduleTeamNumber, VisitorTeamNo = db.Set<ScheduleDivTeam>().FirstOrDefault(t => t.TeamNumber == g.VisitingTeamNumber).ScheduleTeamNumber }); var schedGames = new List<ScheduleGamesVM>(); var teams = db.Set<Team>().Where(t => t.DivisionID == divisionId).ToList<Team>(); foreach (var g in games) { var game = new ScheduleGamesVM(); game.ScheduleNumber = g.ScheduleNumber; game.DivisionId = (int)g.DivisionId; game.GameDate = (DateTime)g.GameDate; game.GameTime = g.GameTime; game.Division = g.Div_Desc; game.LocationNumber = (int)g.LocationNumber; game.LocationName = g.LocationName; game.GameNumber = g.GameNumber; game.HomeTeam = GetTeamName(teams, g.HomeTeamNo); game.VisitorTeam = GetTeamName(teams, g.VisitorTeamNo); game.GameType = GameTypes.Regular; schedGames.Add(game); } schedGames = schedGames.Where(g => g.DivisionId == divisionId) .OrderBy(g => g.GameDate).ThenBy(g => g.GameTime).ThenBy(g => g.DivisionId).ToList<ScheduleGamesVM>(); return schedGames; } }
public ScheduleGamesVM GetGame(int divisionId, int gameNo, int seasonId) { using (var db = new CSBCDbContext()) { var games = ( from g in db.ScheduleGames from d in db.Divisions from l in db.ScheduleLocations where (g.DivisionId == divisionId && g.GameNumber == gameNo) where (d.DivisionID == divisionId) where (g.LocationNumber == l.LocationNumber) select new { g.ScheduleNumber, d.DivisionID, g.GameDate, g.GameTime, d.Div_Desc, g.LocationNumber, l.LocationName, g.GameNumber, HomeTeamNo = db.Set<ScheduleDivTeam>().FirstOrDefault(t => t.TeamNumber == g.HomeTeamNumber).ScheduleTeamNumber, VisitorTeamNo = db.Set<ScheduleDivTeam>().FirstOrDefault(t => t.TeamNumber == g.VisitingTeamNumber).ScheduleTeamNumber }); var schedGames = new List<ScheduleGamesVM>(); var teams = db.Set<Team>().Where(t => t.DivisionID == divisionId).ToList<Team>(); foreach (var g in games) { var game = new ScheduleGamesVM { ScheduleNumber = g.ScheduleNumber, DivisionId = g.DivisionID, GameDate = (DateTime)g.GameDate, GameTime = g.GameTime, Division = g.Div_Desc, LocationNumber = (int)g.LocationNumber, LocationName = g.LocationName, GameNumber = g.GameNumber, HomeTeamNo = g.HomeTeamNo, VisitorTeamNo = g.VisitorTeamNo }; game.HomeTeam = GetTeamName(teams, g.HomeTeamNo); game.VisitorTeam = GetTeamName(teams, g.VisitorTeamNo); game.GameType = GameTypes.Regular; schedGames.Add(game); } //var game = db.ScheduleGames.FirstOrDefault(s => s.ScheduleNumber == scheduleNo && s.GameNumber == gameNo); var sgame = schedGames.FirstOrDefault<ScheduleGamesVM>(); return sgame; } }
public static int GetScheduleNumber(int divisionId) { try { using (var db = new CSBCDbContext()) { var scheduleNo = db.Set<ScheduleGame>().FirstOrDefault(s => s.DivisionId == divisionId).ScheduleNumber; return scheduleNo; } } catch (Exception e) { //MasterVM.MsgBox(Msg.e() return 0; } }
public static TeamViewModel ConvertRecordForTeamNumber(Team team) { var newTeam = new TeamViewModel { TeamID = team.TeamID, CompanyID = team.CompanyID, SeasonID = team.SeasonID, DivisionId = team.DivisionID, CoachID = team.CoachID, TeamName = team.TeamName, TeamNumber = team.TeamNumber, TeamColor = team.TeamColor, TeamColorID = team.TeamColorID }; int teamNo = 0; if (Int32.TryParse(team.TeamNumber, out teamNo)) { newTeam.TeamNo = teamNo; } if (String.IsNullOrEmpty(team.TeamName)) { if (team.TeamColorID > 0) { using (var db = new CSBCDbContext()) { newTeam.TeamName = db.Set<Color>().FirstOrDefault(c => c.ID == team.TeamColorID).ColorName + " (" + team.TeamNumber.ToString() + ")"; } } else newTeam.TeamName = team.TeamNumber; } return newTeam; }
private int GetTeamNo(int divisionNo, int teamNo) { using (var db = new CSBCDbContext()) { return db.Set<ScheduleDivTeam>().FirstOrDefault(t => t.DivisionNumber == divisionNo && t.ScheduleTeamNumber == teamNo).TeamNumber; } }