public async Task <IActionResult> Delete(int buildingPictureId) { //Get header token if (Request.Headers.TryGetValue("Authorization", out StringValues headerValues) && buildingPictureId > -1) { 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 isDeleted = await _buildingService.DeleteBuildingPictureAsync(buildingPictureId); if (isDeleted == false) { return(StatusCode(404, "Unable to delete building picture.")); } return(StatusCode(204, "Building Picture has been deleted.")); } return(StatusCode(401, "Invalid token.")); } return(StatusCode(403, "Invalid user.")); } return(StatusCode(401, "Invalid authorization.")); } return(StatusCode(401, "Invalid authorization.")); }