I'd need to search for users based on their User Settings (ac_UserSettings)
Ideally it would search directly on that.
However since the settings are primarily Yes/No types I could modify my code so that when the user setting is saved it adds them to a group.
If I were going to do that though I would need to search multiple groups at one time.
So, would turning the Group dropdown into a checkbox list handle searching on multiple groups? Thanks!
Search for Users on UserSettings
Re: Search for Users on UserSettings
I think you may try using a multiple-selection list box instead of check-box list. You can have a look at 'Change Assigned Groups' dialog on edit user page for example.
EDIT: Currently, the user search only supported against a single group. Therefore, you have to update back end logic to search against multiple groups to achieve the desired result.
EDIT: Currently, the user search only supported against a single group. Therefore, you have to update back end logic to search against multiple groups to achieve the desired result.
Re: Search for Users on UserSettings
Is there any example I can follow that can do a multi group search? Thanks so much.
May
Re: Search for Users on UserSettings
Multi group search is not supported at the moment. You have to modify the code to work it against multi group.
Re: Search for Users on UserSettings
Here is an example code for you. Open CommerceBuilder/Users/UserSearchCriteria.cs and made the following updates:
Include the following using statement at the top
Add a new property to hold list of group ids
Add the GroupIds in the constructor to avoid null exception, something like this:
Now go to internal ICriteria GenerateCriteria(bool isCount, string sortExpression) method
Locate the following code:
and replace with:
For testing I have set the groupIds from Admin/People/Users/Default.aspx.cs like this:
You have to take selected ids from multi select box.
Hope it helps.
Include the following using statement at the top
Code: Select all
using System.Collections.Generic;
Code: Select all
/// <summary>
/// Gets or sets the groups of the user to search for
/// </summary>
public List<int> GroupIds { get; set; }
Code: Select all
/// <summary>
/// Initializes a new instance of the UserSearchCriteria class.
/// </summary>
public UserSearchCriteria()
{
// DEFAULT VALUE
this.ShowAssignedToGroup = true;
this.GroupIds = new List<int>();
}
Locate the following code:
Code: Select all
// BUILD THE WHERE CRITERIA
if (this.GroupId > 0)
{
if (this.ShowAssignedToGroup)
{
criteria.CreateCriteria("UserGroups", "UG", NHibernate.SqlCommand.JoinType.InnerJoin)
.Add(Restrictions.Eq("UG.GroupId", this.GroupId));
}
else
{
DetachedCriteria subQuery = DetachedCriteria.For<UserGroup>("UG")
.Add(Restrictions.Eq("UG.GroupId", this.GroupId))
.SetProjection(Projections.Property("UG.UserId"));
criteria.Add(Subqueries.PropertyNotIn("U.Id", subQuery));
}
}
Code: Select all
// BUILD THE WHERE CRITERIA
if (this.GroupId > 0)
{
if (this.ShowAssignedToGroup)
{
criteria.CreateCriteria("UserGroups", "UG", NHibernate.SqlCommand.JoinType.InnerJoin)
.Add(Restrictions.Eq("UG.GroupId", this.GroupId));
}
else
{
DetachedCriteria subQuery = DetachedCriteria.For<UserGroup>("UG")
.Add(Restrictions.Eq("UG.GroupId", this.GroupId))
.SetProjection(Projections.Property("UG.UserId"));
criteria.Add(Subqueries.PropertyNotIn("U.Id", subQuery));
}
}
else if(GroupIds.Count > 0)
{
if (this.ShowAssignedToGroup)
{
criteria.CreateCriteria("UserGroups", "UG", NHibernate.SqlCommand.JoinType.InnerJoin)
.Add(Restrictions.In("UG.GroupId", this.GroupIds.ToArray()));
}
else
{
DetachedCriteria subQuery = DetachedCriteria.For<UserGroup>("UG")
.Add(Restrictions.In("UG.GroupId", this.GroupIds.ToArray()))
.SetProjection(Projections.Property("UG.UserId"));
criteria.Add(Subqueries.PropertyNotIn("U.Id", subQuery));
}
}
Code: Select all
criteria.GroupIds.AddRange(new List<int>() { 1, 2, 3, 4, 5 });
Hope it helps.