public async Task <IActionResult> CreateMatch(CreateMatchModel createMatchModel) { try { return(Ok(await _matchService.CreateMatch(createMatchModel))); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public Task <Match> CreateMatch(CreateMatchModel match) { var query = @" mutation {{ createMatch(data: {{ player1Id: \""{0}\"", player2Id: \""{1}\"", score1: {2}, score2: {3} }}) {{ id }} }} "; var withParams = string.Format( query, match.Player1Id, match.Player2Id, match.Score1, match.Score2); return(graphHelper.ExecuteMutation <Match>(withParams, "createMatch")); }
public async Task <IActionResult> CreateMatch(CreateMatchModel match) { bool checkExist = _repo.CheckExist(match.HomeTeamName, match.AwayTeamName); if (checkExist) { return(RedirectToAction("CreateMatch", new { checkExist = checkExist })); } var stadium = await _repo.GetStadiumIdByNameAsync(match.StadiumName); var model = new Match() { Datetime = match.Datetime, Attendance = match.Attendance, StadiumID = stadium.StadiumID, HomeTeamName = match.HomeTeamName, AwayTeamName = match.AwayTeamName }; await _repo.CreateMatchAsync(model); var matchAfter = await _repo.GetMatchWithHomeAndAwayTeamAsync(match.HomeTeamName, match.AwayTeamName); return(RedirectToAction("CreateResult", "Result", new { matchId = matchAfter.MatchID })); }
public async Task <MatchDTO> CreateMatch(CreateMatchModel createMatch) { var participantHome = await _participantRepository.GetAsync(createMatch.IdParticipantHome); if (participantHome == null) { throw new AppException("Home participant doesn't exist."); } var participantAway = await _participantRepository.GetAsync(createMatch.IdParticipantAway); if (participantAway == null) { throw new AppException("Away participant doesn't exist."); } var matchParticipant = new ParticipantsMatch(participantHome, participantAway); var match = new Match(new Guid(), matchParticipant, DateTime.Now, createMatch.BeginsAt); await _matchRepository.AddAsync(match); return(_mapper.Map <MatchDTO>(match)); }