Hello,

I am upgrading my legacy web API to core. I was using IHttpActionResult in my controller in my legacy code. I wonder if I can use it in core 6 web API?

[HttpPost]  
        [Route("purchase")]  
        public async Task<IHttpActionResult> PurchaseGame(RequestDto game)  
            if (!ModelState.IsValid) return BadRequest(ModelState);  
            HttpResponseMessage gameConfirmResponse;  
            if (game.ProductCode is "132" or "133")  
                //Call Razer  
                gameConfirmResponse = await _services.RazerPurchase(game);  
                //Call Services  
                gameConfirmResponse = await _services.EzpinPurchase(game);  
            //If there are no games  
            if (gameConfirmResponse == null)  
                return new ResponseMessageResult(  
                    Request.CreateErrorResponse((HttpStatusCode)222, new HttpError("No Results Found")));  
            if (gameConfirmResponse.Content == null)  
                return new ResponseMessageResult(  
                    Request.CreateErrorResponse((HttpStatusCode)222, new HttpError("No Results Found")));  
            switch (gameConfirmResponse.StatusCode)  
                case HttpStatusCode.NotFound:  
                        return NotFound();  
                case HttpStatusCode.InternalServerError:  
                        return InternalServerError();  
                case HttpStatusCode.OK:  
                        var responseStream = await gameConfirmResponse.Content.ReadAsStringAsync();  
                        var resultResponse = JsonConvert.DeserializeObject<GameConfirmResponse>(responseStream);  
                        if (resultResponse.Coupons == null)  
                            return new ResponseMessageResult(  
                                Request.CreateErrorResponse((HttpStatusCode)222,  
                                    new HttpError("No Coupons Available for this Game")));  
                        var resultDto = _mapper.Map<GameConfirmResponse, GameConfirmResponseDto>(resultResponse);  
                        return Ok(resultDto);  
                case HttpStatusCode.Unauthorized:  
                        return Unauthorized();  
                case HttpStatusCode.RequestTimeout:  
                        return InternalServerError();  
            gameConfirmResponse.Dispose();  
            return Ok(gameConfirmResponse);  
						

Hi @Cenk ,

In asp.net core application, you can use the IActionResult to replace the IHttpActionResult:

     public async Task<IActionResult> PurchaseGame(RequestDto game)  

Then, you can also return BadRequest(), Ok() and Unauthorized().

For the InternalServerError error, you can return a StatusCode, like this:

    return StatusCode(StatusCodes.Status500InternalServerError, "Error message");  

More detail information, see Controller action return types in ASP.NET Core web API.

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best regards,
Dillion