public ActionResult updateRoles(int Roleid)
        {
            RolesViewModel rolesView = new RolesViewModel();

            rolesView.roles        = new Roles();
            rolesView.roles.RoleId = Roleid;
            UserService.UserServiceClient client = new UserService.UserServiceClient();
            DataSet dsrole  = new DataSet();
            string  xmldata = client.GetAllRoles(Roleid);

            dsrole.ReadXml(new StringReader(xmldata));
            rolesView.roles.RoleName    = Convert.ToString(dsrole.Tables[0].Rows[0]["Role_Name"]);
            rolesView.roles.IsGroupRole = Convert.ToBoolean(Convert.ToInt32(dsrole.Tables[0].Rows[0]["Is_Group_Role"]));
            xmldata = client.GetPrivilege();
            DataSet ds = new DataSet();

            ds.ReadXml(new StringReader(xmldata));
            rolesView.Privilege = new List <SelectListItem>();
            dsrole  = new DataSet();
            xmldata = client.getRolePrivilege(rolesView.roles.RoleId);
            dsrole.ReadXml(new StringReader(xmldata));
            if (ds.Tables.Count > 0)
            {
                foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                {
                    bool selected = false;
                    if (dsrole.Tables.Count > 0)
                    {
                        foreach (System.Data.DataRow roleid in dsrole.Tables[0].Rows)
                        {
                            if (Convert.ToInt32(roleid["Privilege_ID"]) == Convert.ToInt32(row["Privilege_ID"]))
                            {
                                selected = true;
                                break;
                            }
                        }
                    }
                    rolesView.Privilege.Add(new SelectListItem()
                    {
                        Text = row["Privilege_Name"].ToString(), Value = row["Privilege_ID"].ToString(), Selected = selected
                    });
                }
            }
            return(View("_AddRole", rolesView));
        }
        public ActionResult ListofRoles()
        {
            UserService.UserServiceClient client = new UserService.UserServiceClient();
            string  xmldata = client.GetAllRoles(0);
            DataSet ds      = new DataSet();

            ds.ReadXml(new StringReader(xmldata));
            RolesViewModel model = new RolesViewModel();

            model.roles     = new Roles();
            model.Privilege = new List <SelectListItem>();
            List <RolesViewModel> roles = new List <RolesViewModel>();
            DataSet dsprivilege         = new DataSet();

            if (ds.Tables.Count > 0)
            {
                foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                {
                    model                   = new RolesViewModel();
                    model.roles             = new Roles();
                    model.Privilege         = new List <SelectListItem>();
                    model.roles.RoleId      = Convert.ToInt32(row["Role_ID"]);
                    model.roles.RoleName    = Convert.ToString(row["Role_Name"]);
                    model.roles.IsGroupRole = Convert.ToBoolean(Convert.ToInt32(row["Is_Group_Role"]));
                    model.roles.IsActive    = Convert.ToBoolean(Convert.ToInt32(row["Is_Active"]));
                    xmldata                 = client.getRolePrivilege(model.roles.RoleId);
                    dsprivilege.ReadXml(new StringReader(xmldata));
                    if (dsprivilege.Tables.Count > 0)
                    {
                        foreach (System.Data.DataRow item in dsprivilege.Tables[0].Rows)
                        {
                            model.Privilege.Add(new SelectListItem {
                                Text = Convert.ToString(item["Privilege_Name"]), Value = Convert.ToString(item["Privilege_ID"])
                            });
                        }
                    }
                    xmldata = string.Empty;
                    dsprivilege.Clear();
                    roles.Add(model);
                }
            }

            return(View("_ListofRoles", roles));
        }