public async Task <ActionResult <Coach> > GetCoachForBuilder(string builderId) { var currentUserId = User.Identity.Name; Coach coach; try { if (User.IsInRole(Role.Admin)) { coach = await _buildersService.GetCoachForBuilderFromAdminAsync(builderId); } else if (User.IsInRole(Role.Builder)) { coach = await _buildersService.GetCoachForBuilderFromBuilderAsync(currentUserId, builderId); } else { return(Forbid("You must be part of the Buildup program")); } } catch (UnauthorizedAccessException e) { return(Forbid($"You are not allowed to get the builder's coach: {e.Message}")); } catch (Exception e) { return(BadRequest($"Can't get the coach: {e.Message}")); } if (coach == null) { return(NotFound()); } return(Ok(coach)); }