I have a controller
public ActionResult UsersInRoles()
{
using (var ctx1 = new UsersModel())
{
var model = new UsersInRolesViewModel();
model.UserProfiles = ctx1.UserProfiles.ToList();
model.UserRoles = ctx1.UserRoles.ToList();
return View(model);
}
}
I am Passing both of those models through to my View: UserRoles Contains all of my possible roles in the system. Now I need to get an array in my controller of all the roles that a User Is registered for, and pass that through to me view as well, So that I can know not to display roles in a box of available roles which the user is already registered for.
How can I do this?
I see two options:
Some how using linq statement to try and get the data in one go, or To pass the full model of roles through and and array of roles that the user is registered for and then I am able to display either or etc in the view?
AUX Classes related to the Usermodel:
public class UsersModel : DbContext
{
public UsersModel()
: base("name=UsersConnection")
{}
public DbSet<UserProfile> UserProfiles { get; set; }
public DbSet<Roles> UserRoles { get; set; }
public DbSet<UsersInRoles> UsersInUserRoles { get; set; }
}
and
public class UsersInRolesViewModel
{
public IList<UserProfile> UserProfiles { get; set; }
public IList<Roles> UserRoles { get; set; }
public IList<ut_GMUTempData> GMUTempData { get; set; }
}