Да, я видел примеры. Проверка изменения статуса было, добавил проверку изменения ответственного. Все ли верно?
Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EleWise.ELMA.API;
using EleWise.ELMA.CRM.Managers;
using EleWise.ELMA.CRM.Models;
using EleWise.ELMA.Common.ExtensionPoints;
using EleWise.ELMA.Common.Models;
using EleWise.ELMA.Common.Models.API;
using EleWise.ELMA.ComponentModel;
using EleWise.ELMA.ConfigurationModel;
using EleWise.ELMA.Documents.Models;
using EleWise.ELMA.Extensions;
using EleWise.ELMA.Logging;
using EleWise.ELMA.Model.Actions;
using EleWise.ELMA.Model.Common;
using EleWise.ELMA.Model.Entities;
using EleWise.ELMA.Model.Events;
using EleWise.ELMA.Model.Managers;
using EleWise.ELMA.Model.Services;
using EleWise.ELMA.Model.Types.Settings;
using EleWise.ELMA.Runtime.Managers;
using EleWise.ELMA.Runtime.NH.Listeners;
using EleWise.ELMA.Security;
using EleWise.ELMA.Security.Managers;
using EleWise.ELMA.Security.Models;
using EleWise.ELMA.Security.Services;
using EleWise.ELMA.Services;
using EleWise.ELMA.Workflow.Managers;
using EleWise.ELMA.Workflow.Services;
using NHibernate.Event;
namespace EleWise.ELMA.CRM.Models.Scripts
{
/// <summary>
/// Модуль сценариев объекта "Возможность"
/// </summary>
public class LeadScripts : EleWise.ELMA.Model.Scripts.Entities.EntityScriptModule<ILeadConfigExt>
{
[Component]
public class ReSaveStatus : PostFlushEventListener
{
// событие редактирования объекта/документа
public override void OnPostUpdate(PostUpdateEvent @event)
{
if (!(@event.Entity is ILeadConfigExt)) return;
var statusIndex = Array.IndexOf(@event.Persister.PropertyNames, "Status");
var responsible = Array.IndexOf(@event.Persister.PropertyNames, "Responsible");
var lead = @event.Entity as ILeadConfigExt;
if (((int)@event.OldState[statusIndex]) != ((int)@event.State[statusIndex]))
{
var messageTypeFind = WorkflowMessageTypeManager.Instance.Find("Name like 'Смена статуса Возможности%'").FirstOrDefault();
var webData = new EleWise.ELMA.Common.Models.WebData {
Items = new[] { new EleWise.ELMA.Common.Models.WebDataItem { Name = "IdLead", Value = string.Format("{0}", lead.Id) } }
};
var workflowMessageService = Locator.GetServiceNotNull<IWorkflowMessagingService>();
var result = workflowMessageService.SendMessage(messageTypeFind, webData);
}
if ((int)@event.OldState[responsible] != (int)@event.State[responsible])
{
var messageTypeFind = WorkflowMessageTypeManager.Instance.Find("Name like 'Смена ответственного%'").FirstOrDefault();
var webData = new EleWise.ELMA.Common.Models.WebData {
Items = new[] { new EleWise.ELMA.Common.Models.WebDataItem { Name = "IdLead", Value = string.Format("{0}", lead.Id) } }
};
var workflowMessageService = Locator.GetServiceNotNull<IWorkflowMessagingService>();
var result = workflowMessageService.SendMessage(messageTypeFind, webData);
}
}
}
}
}