public IActionResult AssignFouls(FoulInputVM model) { if (!ModelState.IsValid) { return(RedirectToAction(nameof(AssignFouls), new { id = model.MatchId, message = 1 })); } var fouls = _dataFoul.GetByDetails(); var lastFoul = fouls.LastOrDefault(x => x.MatchId == model.MatchId); var foul = new Foul { Minute = model.Minute, MatchId = model.MatchId, Penalty = model.Penalty, PlayerId = model.PlayerId, VictimId = model.VictimId }; if (lastFoul == null && model.Minute >= 1 && model.Minute <= 93) { _dataFoul.Add(foul); } else if (lastFoul != null && model.Minute >= 1 && model.Minute <= 93 && model.Minute > lastFoul.Minute) { _dataFoul.Add(foul); } else { return(RedirectToAction(nameof(AssignFouls), new { id = model.MatchId, leagueId = model.LeagueId, message = 1 })); } return(RedirectToAction(nameof(Index), new { id = model.LeagueId })); }
public IActionResult AssignFouls(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)); FoulInputVM viewmodel = new FoulInputVM { MatchId = id, Players = playersList.Select(x => new SelectListItem { Text = x.FirstName + " " + x.LastName, Value = x.Id.ToString() }).ToList(), Victims = playersList.Select(x => new SelectListItem { Text = x.FirstName + " " + x.LastName, Value = x.Id.ToString() }).ToList(), LeagueId = leagueId }; if (message.HasValue) { ViewBag.Mistake = "You cant add foul because input minute is lower than the last minute foul" + " or entered minute is not correct."; } return(View(viewmodel)); }