public string Execute(string[] data) { if (data.Count() != 1) { throw new FormatException("Invalid arguments count!"); } string teamName = data[0]; if (!AuthenticationService.IsAuthenticated()) { throw new InvalidOperationException("You should login first!"); } if (!teamService.TeamExists(teamName)) { throw new ArgumentException($"Team {teamName} not found!"); } User currentUser = AuthenticationService.GetCurrentUser(); if (!teamService.InviteExists(teamName, currentUser)) { throw new ArgumentException($"Invite from {teamName} is not found!"); } userService.AcceptInvite(teamName); string currentUserUsername = AuthenticationService.GetCurrentUser().Username; string result = $"User {currentUserUsername} joined team {teamName}!"; return(result); }
public async Task <IActionResult> AcceptInvite(int id) { var user = await _userService.GetOneByEmail(User.Identity.Name); var invite = await _userService.GetOneById(id); await _userService.AcceptInvite(user, invite); return(Ok(new { message = "Convite aceito com sucesso" })); }