public async Task <IActionResult> Create(AddMatchDto newMatch) { ServiceResponse <List <GetMatchDto> > response = await _matchService.AddMatch(newMatch); if (response.Success == false) { return(BadRequest(response)); } return(Ok(response)); }
public IActionResult AddScore([FromBody] Match match) { if (!ModelState.IsValid) { return(BadRequest(match)); } _matchService.AddMatch(match); //_teamService.AddUsertoTeam(teamId, userNick); return(Ok()); }
public async Task <IActionResult> Post([FromBody] MatchModel model) { var currentUserId = _userManager.GetUserId(User); if (model == null || (model.PlayerOneId != currentUserId && model.PlayerTwoId != currentUserId)) { return(BadRequest()); } var match = new Match() { PlayerOne = _applicationUserService.GetUserById(model.PlayerOneId ?? ""), PlayerTwo = _applicationUserService.GetUserById(model.PlayerTwoId ?? ""), Status = MatchStatus.Pending }; _matchService.AddMatch(match); await _matchService.SaveAsync(); return(Ok()); }
private void AddMatch() { PrintSpecial(Label("ADD MATCH")); try { Print("Id of the host team:"); int hostId = int.Parse(Console.ReadLine()); Print(""); Team hostTeam = teamService.GetTeamById(hostId); Print("Id of the guest team:"); int guestId = int.Parse(Console.ReadLine()); Print(""); Team guestTeam = teamService.GetTeamById(guestId); Match match = new Match() { HostId = hostId, HostTeam = hostTeam, GuestId = guestId, GuestTeam = guestTeam }; matchService.AddMatch(match); Print("Match added successfully!"); } catch (ArgumentException e) { Print(e.Message); } catch (Exception) { Print(SomethingWentWrong()); } }
public async Task <IActionResult> AcceptChallenge(int id) { var challenge = _challengeService.GetChallengeById(id); var currentUserId = _userManager.GetUserId(User); if (challenge == null) { return(NotFound()); } //Make sure the logged in player is the recieving player calling. if (challenge.ReceivingPlayerId != currentUserId) { return(BadRequest("player is not the receiver of challenge")); } if (challenge.Type == ChallengeType.TableTennis) { if (challenge.Match == null) { var newMatch = new Match { PlayerOneId = challenge.SendingPlayerId, PlayerTwoId = challenge.ReceivingPlayerId, Status = MatchStatus.Accepted }; challenge.Match = newMatch; _matchService.AddMatch(newMatch); } challenge.ReceivingPlayerStatus = ChallengeStatus.Accepted; //reset the options flags for this challenge so they don't show as options anymore foreach (var existingNotification in challenge.Notifications) { existingNotification.Message = string.Format("You accept this challenge on {0}", DateTime.UtcNow.ToString("R")); existingNotification.HasOptions = false; } var notification = new Notification { SendingPlayerId = challenge.ReceivingPlayerId, ReceivingPlayerId = challenge.SendingPlayerId, Status = NotificationStatus.Unread, Message = string.Format("{0} has accepted your challenge", challenge.ReceivingPlayer.PlayerName), Subject = "Challenge Accepted", Challenge = challenge }; _notifactionService.AddNotification(notification); } await _notifactionService.SaveAsync(); await _matchService.SaveAsync(); await _challengeService.SaveAsync(); return(Ok()); }
public IActionResult Match(MatchViewModel model) { _matchService.AddMatch(model); return(RedirectToAction("Index", "Home")); }