public async Task <IActionResult> Post([FromBody] FavoriteBuildingDto favoriteBuildingDto) { //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 favoriteBuildingApiDto = await _buildingService.PostFavoriteBuildingAsync(favoriteBuildingDto); if (favoriteBuildingApiDto == null) { return(StatusCode(404, "Unable to create favorite building.")); } return(Ok(favoriteBuildingApiDto)); } return(StatusCode(401, "Invalid token.")); } return(StatusCode(403, "Invalid user.")); } return(StatusCode(401, "Invalid authorization.")); } return(StatusCode(401, "Invalid authorization.")); }
/// <summary> /// Posts the favorite building async. /// </summary> /// <returns>The favorite building async.</returns> /// <param name="favoriteBuildingDto">Favorite building dto.</param> public async Task <FavoriteBuildingApiDto> PostFavoriteBuildingAsync(FavoriteBuildingDto favoriteBuildingDto) { return(await _dal.PostFavoriteBuildingAsync(favoriteBuildingDto)); }