private ScoreModel GetScores(DateTime?fixtureDate) { using (var context = new FcDeHoekContext()) { if (fixtureDate == null) { fixtureDate = DateTime.Now.GetFirstDayOfWeek(CultureInfo.CurrentCulture); } var allGames = GameQueries.GetAllGamesByIdSeason(context, SeasonQueries.GetSeasonByDate(context, (DateTime)fixtureDate)?.IdSeason ?? SeasonQueries.GetCurrentSeason(context).IdSeason).OrderBy(g => g.MatchDate).ToList(); var allPlayWeeks = new List <DateTime>(); foreach (var game in allGames) { if (!allPlayWeeks.Contains(game.MatchDate)) { allPlayWeeks.Add(game.MatchDate); } } var model = new ScoreModel { AllFixtureDates = allPlayWeeks, Games = GetGameModels(context, (DateTime)fixtureDate) }; model.FixtureDate = model.Games.FirstOrDefault()?.MatchDay ?? DateTime.Now; return(model); } }
private List <FcDeHoekGame> GetAllFcDeHoekGames(FcDeHoekContext context, DateTime matchDate) { var gameModelList = new List <FcDeHoekGame>(); var season = SeasonQueries.GetSeasonByDate(context, matchDate) ?? SeasonQueries.GetCurrentSeason(context); var games = GameQueries.GetAllGamesByIdSeasonAndIdTeam(context, season.IdSeason, 1).ToList(); foreach (var game in games) { gameModelList.Add(new FcDeHoekGame { IdGame = game.IdGame, MatchDate = game.MatchDate, GameFixture = $"{game.GameHomeTeam.Name} - {game.GameAwayTeam.Name}" }); } return(gameModelList); }
public ActionResult Save(GameManagerModel model) { using (var context = new FcDeHoekContext()) { var game = GameQueries.GetById(context, model.Games[0].IdGame); if (game == null) { game = new Game(); } foreach (var gameModel in model.Games) { game.GoalsAwayTeam = gameModel.GoalsAwayTeam; game.GoalsHomeTeam = gameModel.GoalsHomeTeam; game.Forfait = gameModel.Forfait; game.IdCompetition = gameModel.IdCompetition; game.IdAwayTeam = gameModel.IdAwayTeam; game.IdHomeTeam = gameModel.IdHomeTeam; game.IdPostPonedGame = gameModel.IdPostPonedGame; game.IdSeason = SeasonQueries.GetSeasonByDate(context, gameModel.MatchDay)?.IdSeason ?? SeasonQueries.GetCurrentSeason(context).IdSeason; game.MatchDate = gameModel.MatchDay; game.NotPlayed = gameModel.IsPostPoned; context.Games.AddOrUpdate(game); context.SaveChanges(); } if (model.AddAnother) { if (model.Games.Count > 1) { return(RedirectToAction("AddMultipleGames", "GameManager", new { idGame = 0 })); } else { return(RedirectToAction("EditGame", "GameManager", new { idGame = 0 })); } } return(RedirectToAction("Index", "GameManager")); } }