crm建立團隊設定團隊的業務部門

來源:互聯網
上載者:User

標籤:crm建立團隊   crm設定團隊的業務部門   crm添加和移除使用者   crm把記錄分配給團隊   crm添加和移除資訊安全角色   

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Crm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Messages;

    /// <summary>
    /// 團隊
    /// </summary>
    public class TeamHelper
    {
        public static readonly string entityName = "team";
        public Guid teamId = Guid.Empty;

        /// <summary>
        /// 建立團隊
        /// </summary>
        /// <param name="service">服務</param>
        public void Create(IOrganizationService service)
        {
            Entity en = new Entity() { LogicalName = entityName };
            en["name"] = "軟體Team Dev";
            teamId = service.Create(en);
        }

        /// <summary>
        /// 設定團隊的業務部門
        /// </summary>
        /// <param name="service">服務</param>
        /// <param name="unitId">業務部門id</param>
        public void SetParentUnit(IOrganizationService service,Guid unitId)
        {
            SetParentTeamRequest request = new SetParentTeamRequest();
            //業務部門id
            request.BusinessId = unitId;
            //團隊id
            request.TeamId = teamId;
            service.Execute(request);
        }

        /// <summary>
        /// 修改團隊
        /// </summary>
        /// <param name="service">服務</param>
        public void Update(IOrganizationService service)
        {
            Entity en = new Entity() { LogicalName = entityName,Id = teamId };
            en["name"] = "軟體研發團隊";
            service.Update(en);
        }

        /// <summary>
        /// 向團隊中新增成員
        /// </summary>
        /// <param name="service">服務</param>
        /// <param name="userArrays">使用者id數組</param>
        public void AddUser(IOrganizationService service,Guid[] userArrays)
        {
            AddMembersTeamRequest request = new AddMembersTeamRequest();
            //團隊
            request.TeamId = teamId;
            //使用者id數組
            request.MemberIds = userArrays;
            service.Execute(request);
        }

        /// <summary>
        /// 向團隊中移除成員
        /// </summary>
        /// <param name="service">服務</param>
        /// <param name="userArrays">使用者id數組</param>
        public void RemoveUser(IOrganizationService service, Guid[] userArrays)
        {
            RemoveMembersTeamRequest request = new RemoveMembersTeamRequest();
            //團隊
            request.TeamId = teamId;
            //使用者id數組
            request.MemberIds = userArrays;
            service.Execute(request);
        }

        /// <summary>
        /// 查詢團隊的許可權
        /// </summary>
        /// <param name="service">服務</param>
        public void SearchTeamRole(IOrganizationService service)
        {
            RetrieveTeamPrivilegesRequest request = new RetrieveTeamPrivilegesRequest();
            //團隊
            request.TeamId = teamId;
            RetrieveTeamPrivilegesResponse response = (RetrieveTeamPrivilegesResponse)service.Execute(request);
            if (response.RolePrivileges != null)
            {
                RolePrivilege[] array = response.RolePrivileges;
            }
        }

        /// <summary>
        /// 添加和移除資訊安全角色
        /// </summary>
        /// <param name="service">服務</param>
        /// <param name="roleId">資訊安全角色的id</param>
        public void AddAndRemoveRole(IOrganizationService service,Guid roleId)
        {
            //添加資訊安全角色
            AddConnection(service, "teamroles_association", new EntityReference() { LogicalName = "role",Id = roleId });
            //移除資訊安全角色
            RemoveConnection(service, "teamroles_association", new EntityReference() { LogicalName = "role", Id = roleId });
        }

        /// <summary>
        /// 把一條記錄分配給團隊
        /// </summary>
        /// <param name="service">服務</param>
        /// <param name="target">記錄對象</param>
        public void AssignToTeam(IOrganizationService service,EntityReference target)
        {
            AssignRequest request = new AssignRequest();
            request.Target = target;
            request.Assignee = new EntityReference() { LogicalName = entityName,Id = teamId };
            service.Execute(request);
        }

        /// <summary>
        /// 刪除團隊
        /// </summary>
        /// <param name="service">服務</param>
        public void Delete(IOrganizationService service)
        {
            service.Delete(entityName, teamId);
        }

        public void AddConnection(IOrganizationService service, string name, params EntityReference[] array)
        {
            Relationship ship = new Relationship(name);
            AssociateRequest request = new AssociateRequest();
            request.Relationship = ship;
            request.Target = new EntityReference() { LogicalName = entityName, Id = teamId };
            request.RelatedEntities = new EntityReferenceCollection();
            request.RelatedEntities.AddRange(array);
            service.Execute(request);
        }

        public void RemoveConnection(IOrganizationService service, string name, params EntityReference[] array)
        {
            Relationship ship = new Relationship(name);
            DisassociateRequest request = new DisassociateRequest();
            request.Relationship = ship;
            request.Target = new EntityReference() { LogicalName = entityName, Id = teamId };
            request.RelatedEntities = new EntityReferenceCollection();
            request.RelatedEntities.AddRange(array);
            service.Execute(request);
        }
    }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.