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