コード例 #1
0
        public ActionResult UserRole()
        {
            try
            {
                var value = 13;
                users.id = value;
                GLobalClient gc = new GLobalClient();
                ViewBag.listUser = gc.findAllUser();
                //getAllUsersRoles(value);
                var result = (from a in db.UserRoles
                              join c in db.Roles on a.RoleId equals c.RoleId
                              join b in db.Users on a.UserId equals b.id
                              where a.UserId == users.id

                              select new Models.GetAssignRoles {
                    userid = b.id, Roleid = c.RoleId.ToString(), Rolename = c.RoleName, email = b.Email
                }).ToList();

                var        userroles = DataReaders.buildNamesList(users);
                var        roles     = DataReaders.buildAllRoleList();
                List <int> userrole  = userroles;
                List <int> role      = roles;
                var        newList   = roles.Except(userroles);

                var pageurl = (from p in db.Roles
                               where newList.Contains((int)(p.RoleId))
                               select new Models.UnGetAssignRoles {
                    Roleid = p.RoleId, Rolename = p.RoleName
                }).ToList();



                var model = new LoanViewModel
                {
                    GetAssignRoless   = result.ToList(),
                    UnGetAssignRoless = pageurl.ToList(),
                };


                return(View(model));
            }
            catch (Exception ex)
            {
                WebLog.Log(ex.Message.ToString());
                return(null);
            }
        }