/// <summary> /// Returns object query of automation states for my pending contacts which can be used as datasource for unigrid. /// </summary> /// <param name="user">User for whom pending contacts are shown</param> /// <param name="contactsWhereCondition">Where condition for filtering contacts</param> private ObjectQuery <AutomationStateInfo> GetPendingContacts(UserInfo user, string contactsWhereCondition) { // Get complete where condition for pending steps var condition = WorkflowStepInfoProvider.GetAutomationPendingStepsWhereCondition(user, SiteContext.CurrentSiteID); // Get automation steps specified by condition with permission control var automationWorkflowSteps = WorkflowStepInfoProvider.GetWorkflowSteps() .Where(condition) .Column("StepID") .WhereEquals("StepWorkflowType", (int)WorkflowTypeEnum.Automation); // Get all pending contacts from automation state where status is Pending and current user is the owner var allPendingContacts = AutomationStateInfoProvider.GetAutomationStates() .WhereIn("StateStepID", automationWorkflowSteps) .WhereEquals("StateStatus", (int)ProcessStatusEnum.Pending) .WhereEquals("StateObjectType", ContactInfo.OBJECT_TYPE); var contactIDs = ContactInfoProvider.GetContacts() .Column("ContactID") .Where(contactsWhereCondition); if (ShowOnlyMyPendingContacts) { contactIDs.WhereEquals("ContactOwnerUserID", user.UserID); } return(allPendingContacts.WhereIn("StateObjectID", contactIDs.AsMaterializedList("ContactID"))); }
/// <summary> /// Remove contact from process. Called when the "Remove contact from process" button is pressed. /// Expects the CreateAutomationState method to be run first. /// </summary> private bool RemoveContactFromProcess() { // Get dataset of contacts string where = "ContactLastName LIKE N'My New Contact%'"; int topN = 1; var contacts = ContactInfoProvider.GetContacts().Where(where).TopN(topN); // Get the process WorkflowInfo process = WorkflowInfoProvider.GetWorkflowInfo("MyNewProcess", WorkflowTypeEnum.Automation); if (DataHelper.DataSourceIsEmpty(contacts) || (process == null)) { return(false); } // Get the contact from dataset ContactInfo contact = contacts.First <ContactInfo>(); // Get the instance of automation manager AutomationManager manager = AutomationManager.GetInstance(CurrentUser); // Get the states var states = AutomationStateInfoProvider.GetAutomationStates() .WhereEquals("StateWorkflowID", process.WorkflowID) .WhereEquals("StateObjectID", contact.ContactID) .WhereEquals("StateObjectType", PredefinedObjectType.CONTACT); if (states.Any()) { // Loop through the individual items foreach (AutomationStateInfo state in states) { // Remove contact from process manager.RemoveProcess(contact, state); } return(true); } return(false); }