码迷,mamicode.com
首页 > 其他好文 > 详细

crm操作案例实体

时间:2014-07-20 10:14:18      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:crm创建案例   crm计算在案例上花费的总时间   crm验证是否可随时结束案例   crm删除案例   

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

    /// <summary>
    /// 案例
    /// </summary>
    public class IncidentHelper
    {
        public static readonly string entityName = "incident";
        public Guid incidentId = Guid.Empty;
        public IOrganizationService service;

        /// <summary>
        /// 创建案例
        /// </summary>
        public void Create()
        {
            Entity en = new Entity() { LogicalName = entityName };
            en["name"] = "案例测试";
            incidentId = service.Create(en);
        }

        /// <summary>
        /// 计算在案例上花费的总时间
        /// </summary>
        public void CalculateTotalTimeIncident()
        {
            CalculateTotalTimeIncidentRequest request = new CalculateTotalTimeIncidentRequest();
            request.IncidentId = incidentId;
            CalculateTotalTimeIncidentResponse response = (CalculateTotalTimeIncidentResponse)service.Execute(request);
            long time = response.TotalTime;
        }

        /// <summary>
        /// 将案例的状态设置为“已结束”
        /// </summary>
        /// <param name="status">结束的状态</param>
        public void CloseIncident(int status)
        {
            CloseIncidentRequest request = new CloseIncidentRequest();
            request.IncidentResolution = new Entity() { LogicalName = entityName ,Id = incidentId };
            request.Status = new OptionSetValue(status);
            CloseIncidentResponse response = (CloseIncidentResponse)service.Execute(request);
        }

        /// <summary>
        /// 验证是否可随时结束案例
        /// </summary>
        /// <param name="state">Active,Resolved,Canceled</param>
        /// <param name="status">InProgress:1,OnHold:2,WaitingforDetails:3,Researching:4</param>
        /// <param name="status">ProblemSolved:5,InformationProvided:1000,Canceled:6</param>
        public void IsValidStateTransition(string state,int status)
        {
            IsValidStateTransitionRequest request = new IsValidStateTransitionRequest();
            request.Entity = new EntityReference() { LogicalName = entityName,Id = incidentId };
            request.NewState = state;
            request.NewStatus = status;
            IsValidStateTransitionResponse response = (IsValidStateTransitionResponse)service.Execute(request);
            bool isValid = response.IsValid;
        }

        /// <summary>
        /// 删除指定安全主体(用户或团队)对案例的所有访问权限
        /// </summary>
        /// <param name="revokee">用户或团队引用</param>
        public void RevokeAccess(EntityReference revokee)
        {
            RevokeAccessRequest request = new RevokeAccessRequest();
            request.Target = new EntityReference() { LogicalName = entityName, Id = incidentId };
            request.Revokee = revokee;
            RevokeAccessResponse response = (RevokeAccessResponse)service.Execute(request);
        }

        /// <summary>
        /// 删除案例
        /// </summary>
        public void Delete()
        {
            service.Delete(entityName, incidentId);
        }
    }

crm操作案例实体

标签:crm创建案例   crm计算在案例上花费的总时间   crm验证是否可随时结束案例   crm删除案例   

原文地址:http://blog.csdn.net/y_f123/article/details/37988243

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!