Can I collect few variables and list and put it into JSON, that will be returned to client if HTTP Get call is successful?
For example:
I have this Controller that has to return list of accounts, and few more values:
public class BankAccountController : ApiController
{
[Authorize]
[Route("/accounts")]
public IHttpActionResult GetAccounts()
{
List<Account> userAccounts = new List<Account>{
new Account {
AccountNumber = 1,
Available = 2346.220m,
Balance = 3219.12m,
Currency = "euro",
InterestRate = 1,
Name = "Current account",
Type = ""},
new Account {
AccountNumber = 2,
Available = 12346.220m,
Balance = 32219.12m,
Currency = "euro",
InterestRate = 3,
Name = "Saving account",
Type = ""},
new Account {
AccountNumber = 3,
Available = 346.220m,
Balance = 219.12m,
Currency = "euro",
InterestRate = 3,
Name = "Current account",
Type = ""},
new Account {
AccountNumber = 4,
Available = 37846.220m,
Balance = 21943.12m,
Currency = "euro",
InterestRate = 3,
Name = "Saving account",
Type = ""},
new Account {
AccountNumber = 5,
Available = 137846.220m,
Balance = 21943.12m,
Currency = "euro",
InterestRate = 3,
Name = "Saving account",
Type = ""},
new Account {
AccountNumber = 6,
Available = 7846.220m,
Balance = 21943.12m,
Currency = "euro",
InterestRate = 3,
Name = "Current account",
Type = ""}
};
var currentAccountsTotal = userAccounts.Count();
string currentsAccountTotalCurrency = "something";
string savingsAccountTotalCurrency = "something";
decimal savingsAccountsTotal = userAccounts.Where(a => a.Name == "Saving account").Select(b => b.Balance).Sum();
return ?;
}
Can I take userAccounts list, currentAccountsTotal, currentsAccountTotalCurrency , savingsAccountsTotal and put them into some JSON that will be returned to client?
I have call specification and it looks like this: On 200 code I return all mentioned in JSON to client.

What should I put as return value in this case?
return Ok(new { userAccounts = userAccounts , something = foo1, somethingelse = foo2});