public async Task <IActionResult> Get()
        {
            //Get header token
            if (Request.Headers.TryGetValue("Authorization", out StringValues headerValues))
            {
                var token = _customEncoder.DecodeBearerAuth(headerValues.First());
                if (token != null)
                {
                    var user = await _userService.GetUserAsyncByToken(token);

                    if (user.IsAdmin == 1 && user != null)
                    {
                        //Verify if the token exist and is not expire
                        if (await _authenticationService.CheckIfTokenIsValidAsync(token, user.UserId))
                        {
                            //Verify if messages for this userId exist
                            var participants = await _participantService.GetAllParticipantsAsync();

                            if (participants == null)
                            {
                                return(StatusCode(404, "Participants not found."));
                            }
                            return(Ok(participants));
                        }
                        return(StatusCode(401, "Invalid Token."));
                    }
                    return(StatusCode(403, "Invalid user."));
                }
                return(StatusCode(401, "Invalid Authorization."));
            }
            return(StatusCode(401, "Invalid Authorization."));
        }
 public async Task <IQueryable <ParticipantViewModel> > Get()
 {
     return(await _participantService.GetAllParticipantsAsync());
 }
Exemple #3
0
        public async Task <IActionResult> GetAllParticipantsAsync()
        {
            var result = await participantService.GetAllParticipantsAsync();

            return(result.Count == 0 ? NotFound() : Ok(result));
        }