コード例 #1
0
        private void ShowDetail()
        {
            ///Show Groups
            Sys_NguoiDungNhomRepository userGroupRepository = new Sys_NguoiDungNhomRepository();
            List <Sys_NguoiDungNhom>    userGroups          = userGroupRepository.GetTable().Where(x => x.UserId == new Guid(user.ProviderUserKey.ToString())).ToList();
            List <int> userGroupsIds = new List <int>();

            userGroups.ForEach(x => userGroupsIds.Add(x.GroupID));

            Sys_DanhMucNhomRepository groupRepository = new Sys_DanhMucNhomRepository();
            List <Sys_DanhMucNhom>    groups          = groupRepository.GetAll().ToList();
            List <UserGroupViewModel> vms             = new List <UserGroupViewModel>();

            groups.FindAll(x => userGroupsIds.Contains(x.ID)).ForEach(x => vms.Add(new UserGroupViewModel {
                Group = x, IsChecked = true
            }));

            rptGroups.DataSource = vms.OrderBy(x => x.Group.TenNhom).ToList();
            rptGroups.DataBind();

            ///Show Permissions
            IsSystemAdmin = xRPMembership.IsSystemAdmin(user.UserName);

            if (!IsSystemAdmin)
            {
                List <Role> roles = xRPMembership.GetRoleForUser(user.UserName);
                rptPermissions.DataSource = roles;
                rptPermissions.DataBind();
            }
            else
            {
                rptPermissions.Visible = false;
            }

            if (staff != null)
            {
                txtName.Text        = staff.TenCanBo;
                txtSoDienThoai.Text = staff.SoDienThoai;
            }

            List <PositionViewModel> positions = new List <PositionViewModel>();

            if (staff != null)
            {
                positions = staffService.GetPositionByStaff(staff.ID);
            }
            rptDepartments.DataSource = positions;
            rptDepartments.DataBind();
        }
コード例 #2
0
ファイル: xRPMembership.cs プロジェクト: duyhungdu/eQtsx
        public static bool UpdateGroupForUser(Guid userId, List <int> groupIds)
        {
            bool isSuccess = false;

            List <int> removalGroups  = new List <int>();
            List <int> additionGroups = new List <int>();
            List <int> userGroups     = new List <int>();


            Sys_NguoiDungNhom deleteNguoiDungNhom = new Sys_NguoiDungNhom();

            Sys_NguoiDungNhomRepository userGroupRepository = new Sys_NguoiDungNhomRepository();

            userGroupRepository.GetTable().Where(x => x.UserId == userId).ToList().ForEach(x => userGroups.Add(x.GroupID));


            removalGroups  = userGroups.FindAll(x => !groupIds.Contains(x));
            additionGroups = groupIds.FindAll(x => !userGroups.Contains(x));

            foreach (int i in removalGroups)
            {
                deleteNguoiDungNhom = userGroupRepository.GetTable().FirstOrDefault(x => x.GroupID == i && x.UserId == userId);
                if (deleteNguoiDungNhom != null)
                {
                    userGroupRepository.Delete(deleteNguoiDungNhom.ID);
                }
            }

            foreach (int i in additionGroups)
            {
                Sys_NguoiDungNhom addNguoiDungNhom = new Sys_NguoiDungNhom();
                addNguoiDungNhom.GroupID = i;
                addNguoiDungNhom.UserId  = userId;
                userGroupRepository.Add(addNguoiDungNhom);
            }
            userGroupRepository.SubmitChanges();
            isSuccess = true;

            return(isSuccess);
        }
コード例 #3
0
        private void ShowDetail()
        {
            ///Show Groups
            Sys_NguoiDungNhomRepository userGroupRepository = new Sys_NguoiDungNhomRepository();
            List <Sys_NguoiDungNhom>    userGroups          = userGroupRepository.GetTable().Where(x => x.UserId == new Guid(user.ProviderUserKey.ToString())).ToList();
            List <int> userGroupsIds = new List <int>();

            userGroups.ForEach(x => userGroupsIds.Add(x.GroupID));

            Sys_DanhMucNhomRepository groupRepository = new Sys_DanhMucNhomRepository();
            List <Sys_DanhMucNhom>    groups          = groupRepository.GetAll().ToList();

            List <UserGroupViewModel> vms = new List <UserGroupViewModel>();

            groups.FindAll(x => !userGroupsIds.Contains(x.ID)).ForEach(x => vms.Add(new UserGroupViewModel {
                Group = x, IsChecked = false
            }));
            groups.FindAll(x => userGroupsIds.Contains(x.ID)).ForEach(x => vms.Add(new UserGroupViewModel {
                Group = x, IsChecked = true
            }));


            rptGroups.DataSource = vms.OrderBy(x => x.Group.TenNhom).ToList();
            rptGroups.DataBind();

            ///Show Permissions

            List <UserPermissionViewModel> permissions = new List <UserPermissionViewModel>();

            List <Role> allRole        = xRPMembership.GetAllRoles();
            List <Role> rolesFromGroup = xRPMembership.GetUserRolesFromGroup(new Guid(user.ProviderUserKey.ToString()));
            List <Role> grantRoles     = xRPMembership.GetGrantRolesForUser(new Guid(user.ProviderUserKey.ToString()));
            List <Role> denyRoles      = xRPMembership.GetDenyRolesForUser(new Guid(user.ProviderUserKey.ToString()));

            List <Guid> guids          = new List <Guid>();
            List <Guid> groupRoleGuids = new List <Guid>();

            rolesFromGroup.ForEach(x => groupRoleGuids.Add(x.ID));
            rolesFromGroup.ForEach(x => guids.Add(x.ID));

            grantRoles.ForEach(x => guids.Add(x.ID));
            denyRoles.ForEach(x => guids.Add(x.ID));

            allRole.RemoveAll(x => guids.Contains(x.ID));

            guids = new List <Guid>();
            denyRoles.ForEach(x => guids.Add(x.ID));
            grantRoles.ForEach(x => guids.Add(x.ID));

            rolesFromGroup.RemoveAll(x => guids.Contains(x.ID));
            rolesFromGroup.ForEach(x => permissions.Add(new UserPermissionViewModel {
                IsInherit = true, Role = x
            }));

            grantRoles.FindAll(x => groupRoleGuids.Contains(x.ID)).ForEach(x => permissions.Add(new UserPermissionViewModel {
                IsOverride = true, Role = x, IsGrant = true, IsAssigned = true
            }));
            grantRoles.FindAll(x => !groupRoleGuids.Contains(x.ID)).ForEach(x => permissions.Add(new UserPermissionViewModel {
                Role = x, IsGrant = true, IsAssigned = true
            }));

            denyRoles.FindAll(x => groupRoleGuids.Contains(x.ID)).ForEach(x => permissions.Add(new UserPermissionViewModel {
                IsOverride = true, Role = x, IsDeny = true, IsAssigned = true
            }));
            denyRoles.FindAll(x => !groupRoleGuids.Contains(x.ID)).ForEach(x => permissions.Add(new UserPermissionViewModel {
                Role = x, IsDeny = true, IsAssigned = true
            }));

            allRole.ForEach(x => permissions.Add(new UserPermissionViewModel {
                Role = x, IsOrphan = true
            }));

            rptPermissions.DataSource = permissions.OrderBy(x => x.Role.Name).ToList();
            rptPermissions.DataBind();
        }