I want to send response message like this
{"message_code": 00, "message": "Success"}
My Response Message Class
public class ResponseMessage
{
public string MessageCode { get; set; }
public string Message { get; set; }
}
And my Message Method
public ResponseMessage Message(FundTransfer transfer)
{
var checkBalance =
BusinessLayer.Api.AccountHolderApi.GetBalance(transfer.FromAccount);
if (checkBalance.Balance.ToDecimal() < transfer.Amount)
{
return new ResponseMessage
{
MessageCode = "22",
Message = "Insufficient Balance"
};
}
else
{
var transferData = BusinessLayer.Api.AccountHolderApi
.FundTransfer(transfer);
if (transferData == true)
{
return new ResponseMessage { MessageCode = "00", Message = "Success" };
}
else
{
return new ResponseMessage { MessageCode = "11", Message = "Some Error" };
}
}
}
And my API Method
[HttpPost]
[ActionName("transfer")]
public IHttpActionResult FundTransfer([FromBody] FundTransfer transfer)
{
var response = Message(transfer);
if (response.MessageCode == "11")
{
return Content(HttpStatusCode.BadRequest, response.Message);
}
else
{
return Ok(response.Message);
}
}
Now for example when the transferData == true in my Message() Method I get only message object value as "Success" since in my return content I am returning the response.Message. I want to get the response in JSON as
{"message_code": 00, "message": "Success"}
instead of just "success"
Currently learning Web API.