Ejemplo n.º 1
0
        private void SetUpPermissions()
        {
            if (GetExistingUser() == null)
            {
                var roleId     = GetRoleId();
                var privileges = GetPrivilegeRecords();

                var addPrivilegesRoleRequest = new AddPrivilegesRoleRequest
                {
                    RoleId     = roleId,
                    Privileges =
                        (
                            from p in privileges
                            select new RolePrivilege(RequiredPrivileges[(string)p.Value["name"]], (Guid)p.Value["privilegeid"], BusinessUnitId.Value)
                        ).ToArray()
                };
                CrmSvc.ExecuteCrmOrganizationRequest(addPrivilegesRoleRequest);

                var user = CreateProposalManagerUser();
                PackageLog.Log("User created...");
                PackageLog.Log(user.ToString());

                CrmSvc.Associate(
                    "systemuser",
                    user,
                    new Relationship("systemuserroles_association"),
                    new EntityReferenceCollection {
                    new EntityReference("role", roleId)
                });
            }
        }
Ejemplo n.º 2
0
 private void AssignRoleToUser(Guid appUserId, Guid roleId)
 {
     // Associate the user with the role if the role isn't already assigned to the user
     if (roleId != Guid.Empty && appUserId != Guid.Empty && !IsRoleAssignedToUser(appUserId, roleId))
     {
         CrmSvc.Associate(
             "systemuser",
             appUserId,
             new Relationship("systemuserroles_association"),
             new EntityReferenceCollection()
         {
             new EntityReference("role", roleId)
         });
     }
 }