public async Task <IActionResult> Post([FromBody] SearchLocationDto searchLocationDto) { //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 != null) { //Verify if the token exist and is not expire if ((await _authenticationService.CheckIfTokenIsValidAsync(token) && user.IsAdmin == 1) || await _authenticationService.CheckIfTokenIsValidAsync(token, user.UserId)) { var searchLocationApiDto = await _searchLocationService.GetSearchLocationsAsync(searchLocationDto); if (searchLocationApiDto.Count == 0) { return(StatusCode(404, "Location(s) not found.")); } return(Ok(searchLocationApiDto)); } return(StatusCode(401, "Invalid token.")); } return(StatusCode(403, "Invalid user.")); } return(StatusCode(401, "Invalid authorization.")); } return(StatusCode(401, "Invalid authorization.")); }
/// <summary> /// Gets the search locations async. /// </summary> /// <returns>The search locations async.</returns> /// <param name="searchLocationDto">Search location dto.</param> public async Task <List <SearchLocationApiDto> > GetSearchLocationsAsync(SearchLocationDto searchLocationDto) { return(await _dal.GetSearchLocationsAsync(searchLocationDto)); }