Appointment Helper

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

/// <summary>
/// 约会
/// </summary>
public class AppointmentHelper
{
    public static readonly string entityName = "appointment";
    public Guid appointmentId = Guid.Empty;
    public IOrganizationService service;

    /// <summary>
    /// 创建约会
    /// </summary>
    public void Create()
    {
        WhoAmIRequest userRequest = new WhoAmIRequest();
        WhoAmIResponse userResponse = (WhoAmIResponse)service.Execute(userRequest);
        Entity activitypartyEn = new Entity() { LogicalName = "activityparty" };
        activitypartyEn["partyId"] = new EntityReference() { LogicalName = "systemuser", Id = userResponse.UserId };

        Entity en = new Entity() { LogicalName = entityName };
        en["subject"] = "约会测试";
        en["scheduledstart"] = DateTime.Now.AddHours(1);
        en["scheduledend"] = DateTime.Now.AddHours(2);
        en["location"] = "办公室";
        en["requiredattendees"] = new Entity[] { activitypartyEn };
        en["organizer"] = new Entity[] { activitypartyEn };
        appointmentId = service.Create(en);
    }

    /// <summary>
    /// 向现有约会中添加定期信息,以使其成为定期主约会
    /// </summary>
    /// <param name="target">目标信息</param>
    public void AddRecurrence(Entity target)
    {
        AddRecurrenceRequest request = new AddRecurrenceRequest();
        request.AppointmentId = appointmentId;
        request.Target = target;
        AddRecurrenceResponse response = (AddRecurrenceResponse)service.Execute(request);
        Guid id = response.id;
    }

    /// <summary>
    /// 将约会分派给其他用户或团队
    /// </summary>
    /// <param name="assignee">用户或团队引用</param>
    public void Assign(EntityReference assignee)
    {
        AssignRequest request = new AssignRequest();
        request.Target = new EntityReference() { LogicalName = entityName, Id = appointmentId };
        request.Assignee = assignee;
        AssignResponse response = (AssignResponse)service.Execute(request);
    }

    /// <summary>
    /// 安排或预定约会
    /// </summary>
    public void Book()
    {
        BookRequest request = new BookRequest();
        request.Target = new Entity() { LogicalName = entityName, Id = appointmentId };
        BookResponse response = (BookResponse)service.Execute(request);
        ValidationResult validationResult = response.ValidationResult;
    }

    /// <summary>
    /// 重新安排约会
    /// </summary>
    public void Reschedule()
    {
        RescheduleRequest request = new RescheduleRequest();
        request.Target = new Entity() { LogicalName = entityName, Id = appointmentId };
        RescheduleResponse response = (RescheduleResponse)service.Execute(request);
        ValidationResult validationResult = response.ValidationResult;
    }

    /// <summary>         /// 
    /// 删除约会         /// 
    /// </summary>         
    public void Delete() { service.Delete(entityName, appointmentId); }
}

 

转载于:https://www.cnblogs.com/bennylam/p/9921282.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值