0

I have get method, which should return users and there permissions. I have a users object and a permissions object, which i populate like this:

List<Users> users= MtFacade.GetUser(query);
List<UserPermissions> upermissions = MtFacade.GetUserPermission(User.Identity.Name);

My API controller returns a HttpResponse, for which I need to send back two lots of JSON, using the two objects.

I can do this if i return just one at a time, but how do i combined the two?

1 Answer 1

4

Wrap them in a class that encompasses properties of their types.

I'm sure you've already figured this out since you've accepted the answer, but in case it helps you or others that see this question here is a code example:

// this would be your class that can encompass the two objects
public class UsersAndPermissions
{
    public List<User> Users { get; set; }
    public List<UserPermissions> Permissions { get; set; }
}

In your web api method use the above class like this

var usersAndPerms = new UsersAndPermissions
{
    Users = MtFacade.GetUser(query),
    Permissions = MtFacade.GetUserPermission(User.Identity.Name)
};

// now your json that you return from the web api has both of the objects data
return usersAndPerms;
Sign up to request clarification or add additional context in comments.

2 Comments

edhedges, both users and userpermissions are already classes.
Yes I understand that, but you can return one object that has properties of the two objects you want to return.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.