Esempio n. 1
0
    /// <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")));
    }
Esempio n. 2
0
    /// <summary>
    /// Returns data of automation states for my pending contacts.
    /// </summary>
    private DataSet GetPendingContacts(UserInfo user, string completeWhere, string currentOrder, int currentTopN, string columns, int currentOffset, int currentPageSize, ref int totalRecords)
    {
        // Get all pending contacts from automation state where status is Pending
        var allPendingContacts = AutomationStateInfo.Provider.Get()
                                 .WhereEquals("StateStatus", (int)ProcessStatusEnum.Pending)
                                 .WhereEquals("StateObjectType", ContactInfo.OBJECT_TYPE);


        // Get complete where condition for pending steps
        var condition = WorkflowStepInfoProvider.GetAutomationPendingStepsWhereCondition(user, SiteContext.CurrentSiteID);

        if (!String.IsNullOrEmpty(condition?.WhereCondition))
        {
            // Get automation steps specified by condition with permission control
            var automationWorkflowSteps = WorkflowStepInfo.Provider.Get()
                                          .Where(condition)
                                          .Column("StepID")
                                          .WhereEquals("StepWorkflowType", (int)WorkflowTypeEnum.Automation);

            allPendingContacts.WhereIn("StateStepID", automationWorkflowSteps);
        }

        // Get contact IDs based on filtering or ownership
        ObjectQuery <ContactInfo> contactIDs = null;

        if (ShowOnlyMyPendingContacts || !String.IsNullOrEmpty(completeWhere))
        {
            contactIDs = ContactInfo.Provider.Get()
                         .Column("ContactID")
                         .Where(completeWhere);
            if (ShowOnlyMyPendingContacts)
            {
                contactIDs.WhereEquals("ContactOwnerUserID", user.UserID);
            }
        }

        var query = allPendingContacts.OrderBy(currentOrder).TopN(currentTopN).Columns(columns);

        if (contactIDs != null)
        {
            // Add restriction based on selected contacts
            query.WhereIn("StateObjectID", SqlInstallationHelper.DatabaseIsSeparated() ? contactIDs.AsMaterializedList("ContactID") : contactIDs);
        }

        query.IncludeBinaryData = false;
        query.Offset            = currentOffset;
        query.MaxRecords        = currentPageSize;

        var data = query.Result;

        totalRecords = query.TotalRecords;

        return(data);
    }
    /// <summary>
    /// Setup control.
    /// </summary>
    private void SetupControl()
    {
        if (!URLHelper.IsPostback() && (PageSize > 0))
        {
            listElem.Pager.DefaultPageSize = PageSize;
        }

        listElem.ZeroRowsText = GetString("ma.pendingcontacts.nowaitingcontacts");

        // Hide site column for site records
        if (SiteID != UniSelector.US_ALL_RECORDS)
        {
            // Site column
            listElem.GridColumns.Columns[5].Visible = false;
        }

        listElem.EditActionUrl  = "Process_Detail.aspx?stateid={0}&siteid=" + SiteID + (ContactHelper.IsSiteManager ? "&issitemanager=1" : String.Empty);
        listElem.WhereCondition = "StateStatus = " + (int)ProcessStatusEnum.Pending + " ";

        listElem.RememberStateByParam = String.Empty;

        if (SiteID != 0)
        {
            // Prepare site filtering
            string siteCondition = "AND (StateSiteID {0})";

            switch (SiteID)
            {
            case UniSelector.US_GLOBAL_RECORD:
                siteCondition = String.Format(siteCondition, "IS NULL");
                break;

            case UniSelector.US_ALL_RECORDS:
                siteCondition = String.Empty;
                break;

            default:
                siteCondition = String.Format(siteCondition, "= " + SiteID);
                break;
            }

            // Append site condition
            listElem.WhereCondition += siteCondition;
        }

        // Get complete where condition for pending steps
        string where = WorkflowStepInfoProvider.GetAutomationPendingStepsWhereCondition(CurrentUser, SiteInfoProvider.GetSiteName(SiteID));

        // If empty current user has Manage processes permissions and show all processes
        if (!String.IsNullOrEmpty(where))
        {
            // Create query parameters
            QueryDataParameters parameters = new QueryDataParameters();
            parameters.Add("@SiteID", SiteID);
            parameters.Add("@UserID", CurrentUser.UserID);

            listElem.QueryParameters = parameters;

            // Add pending steps where condition
            listElem.WhereCondition = SqlHelperClass.AddWhereCondition(listElem.WhereCondition, where);
        }

        listElem.OnExternalDataBound += listElem_OnExternalDataBound;

        // Register scripts for contact details dialog
        ScriptHelper.RegisterDialogScript(Page);
        ScriptHelper.RegisterWOpenerScript(Page);
        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ViewContactDetails", ScriptHelper.GetScript(
                                                   "function Refresh() { \n " +
                                                   "window.location.href = window.location.href;\n" +
                                                   "}" +
                                                   "function viewContactDetails(contactId) {" +
                                                   "    modalDialog('" + URLHelper.ResolveUrl("~/CMSModules/ContactManagement/Pages/Tools/Account/Contact_Detail.aspx") + "?isSiteManager=" + ContactHelper.IsSiteManager + "&contactId=' + contactId, 'ViewContactDetails', '1024', '700');" +
                                                   "}"));

        // If widget register action for view process in dialog
        if (IsWidget)
        {
            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ViewPendingContactProcess", ScriptHelper.GetScript(
                                                       "function viewPendingContactProcess(stateId) {" +
                                                       "    modalDialog('" + URLHelper.ResolveUrl("~/CMSModules/ContactManagement/Pages/Tools/PendingContacts/Process_Detail_Frameset.aspx") + "?dialogmode=1&stateId=' + stateId, 'ViewPendingContactProcess', '1024', '700');" +
                                                       "}"));
        }
    }