コード例 #1
0
    /// <summary>
    /// Gets the contact targets.
    /// </summary>
    /// <returns></returns>
    private IList GetContactTargets()
    {
        IList              contactList;
        IQueryable         query       = (IQueryable)EntityFactory.GetRepository <IContact>();
        IExpressionFactory expressions = query.GetExpressionFactory();
        IProjections       projections = query.GetProjectionsFactory();
        ICriteria          criteria    = query.CreateCriteria("a1")
                                         .CreateCriteria("Account", "account")
                                         .CreateCriteria("a1.Addresses", "address")
                                         .SetProjection(projections.ProjectionList()
                                                        .Add(projections.Distinct(projections.Property("Id")))
                                                        .Add(projections.Property("FirstName"))
                                                        .Add(projections.Property("LastName"))
                                                        .Add(projections.Property("AccountName"))
                                                        .Add(projections.Property("Email"))
                                                        .Add(projections.Property("address.City"))
                                                        .Add(projections.Property("address.State"))
                                                        .Add(projections.Property("address.PostalCode"))
                                                        .Add(projections.Property("WorkPhone"))

                                                        );

        AddExpressionsCriteria(criteria, expressions);
        contactList = criteria.List();
        // NOTE: The generic exception handler was removed since the exception was rethrown; this exception would be logged twice otherwise.
        // We may want to throw a UserObservableApplicationException in the future.
        return(contactList);
    }
コード例 #2
0
    /// <summary>
    /// Gets the contact targets.
    /// </summary>
    /// <returns></returns>
    private IList GetContactTargets()
    {
        IList contactList;

        try
        {
            IQueryable         query       = (IQueryable)EntityFactory.GetRepository <IContact>();
            IExpressionFactory expressions = query.GetExpressionFactory();
            IProjections       projections = query.GetProjectionsFactory();
            ICriteria          criteria    = query.CreateCriteria("a1")
                                             .CreateCriteria("Account", "account")
                                             .CreateCriteria("a1.Addresses", "address")
                                             .SetProjection(projections.ProjectionList()
                                                            .Add(projections.Distinct(projections.Property("Id")))
                                                            .Add(projections.Property("FirstName"))
                                                            .Add(projections.Property("LastName"))
                                                            .Add(projections.Property("Account"))
                                                            .Add(projections.Property("Email"))
                                                            .Add(projections.Property("address.City"))
                                                            .Add(projections.Property("address.State"))
                                                            .Add(projections.Property("address.PostalCode"))
                                                            .Add(projections.Property("WorkPhone"))
                                                            );
            AddExpressionsCriteria(criteria, expressions);
            contactList = criteria.List();
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
            throw;
        }
        return(contactList);
    }
コード例 #3
0
    /// <summary>
    /// Adds the distinct CampaignStage stage names to list.
    /// </summary>
    private void AddDistinctStageItemsToList()
    {
        lbxStages.Items.Clear();
        lbxStages.Items.Add("");

        IRepository <ICampaignStage> rep = EntityFactory.GetRepository <ICampaignStage>();
        IQueryable         query         = (IQueryable)rep;
        IExpressionFactory expressions   = query.GetExpressionFactory();
        IProjections       projections   = query.GetProjectionsFactory();
        ICriteria          criteria      = query.CreateCriteria()
                                           .SetProjection(projections.Distinct(projections.Property("Description")))
                                           .Add(expressions.And(expressions.Eq("Campaign.Id", EntityContext.EntityID), expressions.IsNotNull("Description")));

        IList <object> stages = criteria.List <object>();

        if (stages != null)
        {
            foreach (string stage in stages)
            {
                if (!String.IsNullOrEmpty(stage))
                {
                    ListItem item = new ListItem {
                        Text = stage
                    };
                    lbxStages.Items.Add(item);
                }
            }
        }
    }
コード例 #4
0
    /// <summary>
    /// Adds the distinct CampaignTarget group names to list.
    /// </summary>
    private void AddDistinctGroupItemsToList()
    {
        lbxGroups.Items.Clear();
        lbxGroups.Items.Add(String.Empty);

        IRepository <ICampaignTarget> rep = EntityFactory.GetRepository <ICampaignTarget>();
        IQueryable         query          = (IQueryable)rep;
        IExpressionFactory expressions    = query.GetExpressionFactory();
        IProjections       projections    = query.GetProjectionsFactory();
        ICriteria          criteria       = query.CreateCriteria()
                                            .SetProjection(projections.Distinct(projections.Property("GroupName")))
                                            .Add(expressions.And(expressions.Eq("Campaign.Id", EntityContext.EntityID), expressions.IsNotNull("GroupName")));

        IList <object> groups = criteria.List <object>();

        if (groups != null)
        {
            foreach (string group in groups)
            {
                if (!String.IsNullOrEmpty(group))
                {
                    ListItem item = new ListItem {
                        Text = @group
                    };
                    lbxGroups.Items.Add(item);
                }
            }
        }
    }
コード例 #5
0
 /// <summary>
 /// Aborts the import.
 /// </summary>
 /// <param name="importHistory">The import history.</param>
 private void AbortImport(IImportHistory importHistory)
 {
     try
     {
         IRepository <IImportHistory> rep        = EntityFactory.GetRepository <IImportHistory>();
         IQueryable         qry                  = (IQueryable)rep;
         IExpressionFactory ep                   = qry.GetExpressionFactory();
         Sage.Platform.Repository.ICriteria crit = qry.CreateCriteria();
         crit.Add(ep.Eq("Id", importHistory.Id));
         IProjections projections = qry.GetProjectionsFactory();
         crit.SetProjection(projections.Property("ProcessState"));
         object state = crit.UniqueResult();
         if (state != null)
         {
             ImportProcessState processState = (ImportProcessState)Enum.Parse(typeof(ImportProcessState), state.ToString());
             if (!processState.Equals(ImportProcessState.Completed) || !processState.Equals(ImportProcessState.Abort))
             {
                 SetProcessState(importHistory.Id.ToString(), Enum.GetName(typeof(ImportProcessState), ImportProcessState.Abort), "Aborted");
             }
         }
     }
     catch (Exception)
     {
         //throw new ApplicationException("Error getting process state");
     }
 }
コード例 #6
0
    /// <summary>
    /// Gets the Lead targets.
    /// </summary>
    /// <returns></returns>
    private IList GetLeadTargets()
    {
        IList leadList = null;

        try
        {
            IQueryable         query       = (IQueryable)EntityFactory.GetRepository <ILead>();
            IExpressionFactory expressions = query.GetExpressionFactory();
            IProjections       projections = query.GetProjectionsFactory();
            ICriteria          criteria    = query.CreateCriteria("lead")
                                             .SetCacheable(true)
                                             .CreateCriteria("CampaignTargets", "target")
                                             .Add(expressions.Eq("Campaign.Id", EntityContext.EntityID))
                                             .CreateCriteria("TargetResponses", "response")
                                             .SetProjection(projections.ProjectionList()
                                                            .Add(projections.Property("response.LeadSource"))
                                                            .Add(projections.Property("LeadNameLastFirst"))
                                                            .Add(projections.Property("target.TargetType"))
                                                            .Add(projections.Property("response.ResponseDate"))
                                                            .Add(projections.Property("response.ResponseMethod"))
                                                            .Add(projections.Property("response.Stage"))
                                                            .Add(projections.Property("response.Comments"))
                                                            .Add(projections.Property("target.Id"))
                                                            .Add(projections.Property("response.Id"))
                                                            .Add(projections.Property("lead.LastName"))
                                                            );
            criteria = GetExpressions(criteria, expressions);
            if (chkName.Checked)
            {
                criteria.Add(expressions.InsensitiveLike("lead.LastName", txtName.Text, LikeMatchMode.BeginsWith));
            }
            leadList = criteria.List();
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
            throw;
        }
        return(leadList);
    }
コード例 #7
0
    /// <summary>
    /// Gets the contact targets via a join through Account.
    /// </summary>
    /// <returns></returns>
    private IList GetAccountTargets()
    {
        IList contactList;

        try
        {
            IQueryable         query       = (IQueryable)EntityFactory.GetRepository <IContact>();
            IExpressionFactory expressions = query.GetExpressionFactory();
            IProjections       projections = query.GetProjectionsFactory();
            ICriteria          criteria    = query.CreateCriteria("a1")
                                             .CreateCriteria("Account", "account")
                                             .CreateCriteria("Addresses", "address")
                                             .SetProjection(projections.ProjectionList()
                                                            .Add(projections.Distinct(projections.Property("Id")))
                                                            .Add(projections.Property("FirstName"))
                                                            .Add(projections.Property("LastName"))
                                                            .Add(projections.Property("Account"))
                                                            .Add(projections.Property("Email"))
                                                            .Add(projections.Property("address.City"))
                                                            .Add(projections.Property("address.State"))
                                                            .Add(projections.Property("address.PostalCode"))
                                                            .Add(projections.Property("WorkPhone"))
                                                            );
            AddExpressionsCriteria(criteria, expressions);
            contactList = criteria.List();
        }
        catch (NHibernate.QueryException nex)
        {
            log.Error(nex.Message);
            string message = GetLocalResourceObject("QueryError").ToString();
            if (nex.Message.Contains("could not resolve property"))
            {
                message += "  " + GetLocalResourceObject("QueryErrorInvalidParameter");
            }

            throw new ValidationException(message);
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
            throw;
        }
        return(contactList);
    }
コード例 #8
0
    /// <summary>
    /// Gets the contact targets via a join through Account.
    /// </summary>
    /// <returns></returns>
    private IList GetAccountTargets()
    {
        IList contactList;

        try
        {
            IQueryable         query       = (IQueryable)EntityFactory.GetRepository <IContact>();
            IExpressionFactory expressions = query.GetExpressionFactory();
            IProjections       projections = query.GetProjectionsFactory();
            ICriteria          criteria    = query.CreateCriteria("a1")
                                             .CreateCriteria("Account", "account")
                                             .CreateCriteria("Addresses", "address")
                                             .SetProjection(projections.ProjectionList()
                                                            .Add(projections.Distinct(projections.Property("Id")))
                                                            .Add(projections.Property("FirstName"))
                                                            .Add(projections.Property("LastName"))
                                                            .Add(projections.Property("AccountName"))
                                                            .Add(projections.Property("Email"))
                                                            .Add(projections.Property("address.City"))
                                                            .Add(projections.Property("address.State"))
                                                            .Add(projections.Property("address.PostalCode"))
                                                            .Add(projections.Property("WorkPhone"))
                                                            );
            AddExpressionsCriteria(criteria, expressions);
            contactList = criteria.List();
        }
        catch (NHibernate.QueryException nex)
        {
            log.Error("The call to ManageTargets.GetAccountTargets() failed", nex);
            string message = GetLocalResourceObject("QueryError").ToString();
            if (nex.Message.Contains("could not resolve property"))
            {
                message += "  " + GetLocalResourceObject("QueryErrorInvalidParameter");
            }

            throw new ValidationException(message);
        }
        // NOTE: The generic exception handler was removed since the exception was rethrown; this exception would be logged twice otherwise.
        // We may want to throw a UserObservableApplicationException in the future.
        return(contactList);
    }