1. 程式人生 > >crm操作約會實體

crm操作約會實體

span ges reference part don class a 定期 cat end

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);
}
}

crm操作約會實體