public ActionResult DeleteConfirmed(String id) { if (ModelState.IsValid) { try { //todo delete all matches in league and all player matches related to match List <Match> matches = _matchRepository.GetMatchesByLeagueName(id).ToList(); foreach (var match in matches) { List <PlayerMatch> playerMatches = _playerMatchRepository.GetPlayerMatchesByMatchId(match.ID).ToList(); foreach (var playerMatch in playerMatches) { _playerMatchRepository.DeletePlayerMatch(playerMatch); } _matchRepository.DeleteMatch(match.ID); } _repository.DeleteLeague(id); return(RedirectToAction("Index")); } catch (Exception e) { ViewBag.ErrorMsg = "Error deleting record. " + e.Message; return(View(_repository.GetLeagueByName(id))); } } return(View(_repository.GetLeagues())); }
public ActionResult Details(String id) { Match match = _repository.GetMatchByID(id); if (match == null) { return(RedirectToAction("Index")); } IEnumerable <PlayerMatch> temp = _playerMatchRepository.GetPlayerMatchesByMatchId(id); foreach (var item in temp) { item.Player = _playerRepository.GetPlayerByID(item.PlayerID); } if (temp != null && match != null) { match.PlayerMatches = temp; } return(View(match)); }