public IActionResult AssignGoals(int id, int leagueId, int?message) { var match = _dataMatches.Get(id); var homeClub = _dataClubs.Get(m => m.Id == match.HomeClubId); var awayClub = _dataClubs.Get(m => m.Id == match.AwayClubId); if (match == null) { return(RedirectToAction("Error", "Home")); } var playerList = _dataPlayer.GetByDetails(); List <Player> playersList = new List <Player>(); var contracts = _dataContract.GetByDetails().ToList(); foreach (var item in playerList) { for (int i = contracts.Count() - 1; i >= 0; i--) { if (item.Id == contracts[i].PlayerId && (contracts[i].ClubId == homeClub.Id || contracts[i].ClubId == awayClub.Id)) { playersList.Add(item); } } } var list = Globals.ToPairList <HalfTime>(typeof(HalfTime)); GoalInputVM viewmodel = new GoalInputVM { MatchId = id, ScoredPlayers = playersList.Select(x => new SelectListItem { Text = x.FirstName + " " + x.LastName, Value = x.Id.ToString() }).ToList(), AssistedPlayers = playersList.Select(x => new SelectListItem { Text = x.FirstName + " " + x.LastName, Value = x.Id.ToString() }).ToList(), Times = list.Select(x => new SelectListItem(x.Value, x.Key.ToString())), HomeTeam = homeClub.Name, AwayTeam = awayClub.Name, LeagueId = leagueId }; if (message.HasValue) { ViewBag.Mistake = "You cant add goal because input minute is lower than the last minute goal" + " or entered minute is not in correct halftime."; } return(View(viewmodel)); }
public IActionResult AddGoal(GoalInputVM model) { if (!ModelState.IsValid) { return(RedirectToAction(nameof(AssignGoals), new { id = model.MatchId, message = 1 })); } var goals = _dataGoal.GetByDetails(); var lastGoal = goals.LastOrDefault(x => x.MatchId == model.MatchId); var goal = new Goal { Minute = model.Minute, Time = model.Time, AssistantId = model.AssistantId, ScorerId = model.ScorerId, MatchId = model.MatchId }; if (lastGoal == null && ((model.Minute >= 1 && model.Minute <= 45 && model.Time.ToString() == "First") || (model.Minute >= 46 && model.Minute <= 93 && model.Time.ToString() == "Second"))) { _dataGoal.Add(goal); } else if (lastGoal != null && model.Minute > lastGoal.Minute && model.Minute >= 1 && model.Minute <= 45 && model.Time.ToString() == "First") { _dataGoal.Add(goal); } else if (lastGoal != null && model.Minute > lastGoal.Minute && model.Minute >= 46 && model.Minute <= 93 && model.Time.ToString() == "Second") { _dataGoal.Add(goal); } else { return(RedirectToAction(nameof(AssignGoals), new { id = model.MatchId, leagueId = model.LeagueId, message = 1 })); } return(RedirectToAction(nameof(Index), new { id = model.LeagueId })); }