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 Delete(PlayerMatch playermatch) { try { _repository.DeletePlayerMatch(playermatch); return(RedirectToAction("ViewPlayerMatches", new { id = playermatch.PlayerID })); } catch (Exception ex) { //error msg for failed delete in XML file ViewBag.ErrorMsg = "Error deleting record. " + ex.Message; return(View(playermatch)); } }
public ActionResult Delete(Match match) { try { //Delete all related player matches List <PlayerMatch> playerMatches = _playerMatchRepository.GetPlayerMatchesByMatchId(match.ID).ToList(); foreach (var playerMatch in playerMatches) { _playerMatchRepository.DeletePlayerMatch(playerMatch); } _repository.DeleteMatch(match.ID); return(RedirectToAction("Index")); } catch (Exception ex) { //error msg for failed delete in XML file ViewBag.ErrorMsg = "Error deleting record. " + ex.Message; return(View(_repository.GetMatchByID(match.ID))); } }