Exemplo n.º 1
0
        public async Task <ActionResult <List <MeetingReport> > > GetMeetingReports(string builderId)
        {
            var currentUserId = User.Identity.Name;
            List <MeetingReport> result;

            try
            {
                if (User.IsInRole(Role.Admin))
                {
                    result = await _buildersService.GetMeetingReportsFromAdminAsync(builderId);
                }
                else if (User.IsInRole(Role.Coach))
                {
                    result = await _buildersService.GetMeetingReportsFromCoachAsync(currentUserId, builderId);
                }
                else if (User.IsInRole(Role.Builder))
                {
                    result = await _buildersService.GetMeetingReportsFromBuilderAsync(currentUserId, builderId);
                }
                else
                {
                    return(Unauthorized("You must be part of the Buildup program"));
                }
            }
            catch (UnauthorizedAccessException e)
            {
                return(Unauthorized($"You are not allowed to get reports: {e.Message}"));
            }
            catch (Exception e)
            {
                return(BadRequest($"Can't get the builder's meeting reports: {e.Message}"));
            }

            return(Ok(result));
        }