コード例 #1
0
 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()));
 }
コード例 #2
0
        public async Task deleteEntireLeague(int id, string userId)
        {
            var league = await leagueRepository.FindLeagueForIdAndUser(id, userId);

            IList <Season> seasonsToRemove = new List <Season>();

            foreach (var season in league.Seasons)
            {
                await deleteSeasonRelevantInformation(season);
            }
            await seasonRepository.deleteMany(league.Seasons);

            await leagueRepository.DeleteLeague(id);
        }
コード例 #3
0
        public IActionResult Delete(Guid id)
        {
            if (!_leagueRepository.LeagueExists(id))
            {
                _logger.LogError($"League {id} does not exist.");
                return(NotFound());
            }
            var league = _leagueRepository.GetLeague(id);

            _leagueRepository.DeleteLeague(league);
            if (!_mlbDraftRepository.Save())
            {
                _logger.LogError($"Could not delete league {id}");
                throw new Exception($"Deleting league {id} failed on save.");
            }

            return(NoContent());
        }