public async void CreateTeamMatch(int teamId, int matchId) { try { TeamMatches teamMatch = PassTeamMatchParameters(teamId, matchId); await _context.TeamMatches.AddAsync(teamMatch); await _context.SaveChangesAsync(); } catch (Exception) { throw new GlobalException(GlobalExceptionMessage.GlobalErrorMessage); } }
public async Task <ActionResult> Create(string teamName) { if (!db.Teams.Any(x => x.Name == teamName) || string.IsNullOrWhiteSpace(teamName)) { db.Teams.Add(new Team { Name = teamName, Points = 0 }); await db.SaveChangesAsync(); } return(RedirectToAction("Index")); }
public async Task <ActionResult> FinishCreate(string teamNameLeft, string teamNameRight) { if (teamNameLeft == teamNameRight) { TempData["Error"] = $"Choose different teams!"; return(RedirectToAction("Create")); } var teamLeft = db.Teams.Single(x => x.Name == teamNameLeft); var teamRight = db.Teams.Single(x => x.Name == teamNameRight); var match = new Match() { LeftTeam = teamLeft, RightTeam = teamRight, DateTime = DateTime.Now }; var playedMatch = matchManager.PlayMatch(match); db.Matches.Add(playedMatch); playedMatch.LeftTeam.Points += matchManager.GetLeftTeamPoints(playedMatch); playedMatch.RightTeam.Points += matchManager.GetRightTeamPoints(playedMatch); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <Team> CreateTeamAsync(Team newTeam) { try { Team team = PassTeamParameters(newTeam); await _context.Teams.AddAsync(team); await _context.SaveChangesAsync(); return(team); } catch (Exception) { throw new GlobalException(GlobalExceptionMessage.GlobalErrorMessage); } }
public async Task <Match> CreateMatchAsync(Match newMatch) { await _teamServices.CheckIfTeamExcist(newMatch); try { Match match = PassMatchParameters(newMatch); await _context.Matches.AddAsync(match); await _context.SaveChangesAsync(); _teamMatchServices.HandleNewTeamMatchRequest(match); return(match); } catch (Exception) { throw new GlobalException(GlobalExceptionMessage.GlobalErrorMessage); } }