public void Handle(LeaveLeagueCommand command) { // TODO validate using (var dbContext = new ManagementDataContext()) { Team team = dbContext.Teams.SingleOrDefault(t => t.Id == command.TeamId); if (team == null) { throw new ServerSideException("Ups, something went wrong! Refresh page and try agine"); } League league = dbContext.Leagues.SingleOrDefault(l => l.Teams.Contains(team)); if (league == null) { throw new ServerSideException("Ups, something went wrong! Refresh page and try agine"); } team.LeaveLeague(league); dbContext.SaveChanges(); } }
public ActionResult LeaveLeague(LeaveLeagueCommand command) { HandleCommand(command, Json("Team leaved league")); return(RedirectToAction("Index")); }