本文整理汇总了C#中Rock.Model.GroupService.Queryable方法的典型用法代码示例。如果您正苦于以下问题:C# GroupService.Queryable方法的具体用法?C# GroupService.Queryable怎么用?C# GroupService.Queryable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupService
的用法示例。
在下文中一共展示了GroupService.Queryable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindGrid
private void BindGrid()
{
string type = PageParameter( "SearchType" );
string term = PageParameter( "SearchTerm" );
var groupService = new GroupService( new RockContext() );
var groups = new List<Group>();
if ( !string.IsNullOrWhiteSpace( type ) && !string.IsNullOrWhiteSpace( term ) )
{
switch ( type.ToLower() )
{
case "name":
{
groups = groupService.Queryable()
.Where( g =>
g.GroupType.ShowInNavigation &&
g.Name.Contains( term ) )
.OrderBy( g => g.Order )
.ThenBy( g => g.Name )
.ToList();
break;
}
}
}
if ( groups.Count == 1 )
{
Response.Redirect( string.Format( "~/Group/{0}", groups[0].Id ), false );
Context.ApplicationInstance.CompleteRequest();
}
else
{
gGroups.EntityTypeId = EntityTypeCache.Read<Group>().Id;
gGroups.DataSource = groups
.Select( g => new
{
g.Id,
GroupType = g.GroupType.Name,
Structure = ParentStructure( g ),
MemberCount = g.Members.Count()
} )
.ToList();
gGroups.DataBind();
}
}
示例2: btnDelete_Click
/// <summary>
/// Handles the Click event of the btnDelete control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnDelete_Click( object sender, EventArgs e )
{
int? parentGroupId = null;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
AuthService authService = new AuthService( rockContext );
Group group = groupService.Get( hfGroupId.Value.AsInteger() );
if ( group != null )
{
if ( !group.IsAuthorized( Authorization.EDIT, this.CurrentPerson ) )
{
mdDeleteWarning.Show( "You are not authorized to delete this group.", ModalAlertType.Information );
return;
}
parentGroupId = group.ParentGroupId;
string errorMessage;
if ( !groupService.CanDelete( group, out errorMessage ) )
{
mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
bool isSecurityRoleGroup = group.IsActive && ( group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() ) );
if ( isSecurityRoleGroup )
{
Rock.Security.Role.Flush( group.Id );
foreach ( var auth in authService.Queryable().Where( a => a.GroupId == group.Id ).ToList() )
{
authService.Delete( auth );
}
}
// If group has a non-named schedule, delete the schedule record.
if ( group.ScheduleId.HasValue )
{
var scheduleService = new ScheduleService( rockContext );
var schedule = scheduleService.Get( group.ScheduleId.Value );
if ( schedule != null && schedule.ScheduleType != ScheduleType.Named )
{
// Make sure this is the only group trying to use this schedule.
if ( !groupService.Queryable().Where( g => g.ScheduleId == schedule.Id && g.Id != group.Id ).Any() )
{
scheduleService.Delete( schedule );
}
}
}
groupService.Delete( group );
rockContext.SaveChanges();
if ( isSecurityRoleGroup )
{
Rock.Security.Authorization.Flush();
}
}
// reload page, selecting the deleted group's parent
var qryParams = new Dictionary<string, string>();
if ( parentGroupId != null )
{
qryParams["GroupId"] = parentGroupId.ToString();
}
qryParams["ExpandedIds"] = PageParameter( "ExpandedIds" );
NavigateToPage( RockPage.Guid, qryParams );
}
示例3: ShowResults
/// <summary>
/// Binds the grid.
/// </summary>
private void ShowResults()
{
// Get the group types that we're interested in
Guid? groupTypeGuid = GetAttributeValue( "GroupType" ).AsGuidOrNull();
if ( !groupTypeGuid.HasValue )
{
ShowError( "A valid Group Type is required." );
return;
}
gGroups.Columns[1].Visible = GetAttributeValue( "ShowDescription" ).AsBoolean();
gGroups.Columns[2].Visible = GetAttributeValue( "ShowSchedule" ).AsBoolean();
gGroups.Columns[3].Visible = GetAttributeValue( "ShowCount" ).AsBoolean();
gGroups.Columns[4].Visible = GetAttributeValue( "ShowAge" ).AsBoolean();
bool showProximity = GetAttributeValue( "ShowProximity" ).AsBoolean();
gGroups.Columns[5].Visible = showProximity; // Distance
// Get query of groups of the selected group type
var rockContext = new RockContext();
var groupService = new GroupService( rockContext );
var groupQry = groupService
.Queryable( "GroupLocations.Location" )
.Where( g => g.IsActive && g.GroupType.Guid.Equals( groupTypeGuid.Value ) && g.IsPublic );
var groupParameterExpression = groupService.ParameterExpression;
var schedulePropertyExpression = Expression.Property( groupParameterExpression, "Schedule" );
var dowFilterControl = phFilterControls.FindControl( "filter_dow" );
if ( dowFilterControl != null )
{
var field = FieldTypeCache.Read( Rock.SystemGuid.FieldType.DAY_OF_WEEK ).Field;
var filterValues = field.GetFilterValues( dowFilterControl, null, Rock.Reporting.FilterMode.SimpleFilter );
var expression = field.PropertyFilterExpression( null, filterValues, schedulePropertyExpression, "WeeklyDayOfWeek", typeof( DayOfWeek? ) );
groupQry = groupQry.Where( groupParameterExpression, expression, null );
}
var timeFilterControl = phFilterControls.FindControl( "filter_time" );
if ( timeFilterControl != null )
{
var field = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TIME ).Field;
var filterValues = field.GetFilterValues( timeFilterControl, null, Rock.Reporting.FilterMode.SimpleFilter );
var expression = field.PropertyFilterExpression( null, filterValues, schedulePropertyExpression, "WeeklyTimeOfDay", typeof( TimeSpan? ) );
groupQry = groupQry.Where( groupParameterExpression, expression, null );
}
// Filter query by any configured attribute filters
if ( AttributeFilters != null && AttributeFilters.Any() )
{
var attributeValueService = new AttributeValueService( rockContext );
var parameterExpression = attributeValueService.ParameterExpression;
foreach ( var attribute in AttributeFilters )
{
var filterControl = phFilterControls.FindControl( "filter_" + attribute.Id.ToString() );
if ( filterControl != null )
{
var filterValues = attribute.FieldType.Field.GetFilterValues( filterControl, attribute.QualifierValues, Rock.Reporting.FilterMode.SimpleFilter );
var expression = attribute.FieldType.Field.AttributeFilterExpression( attribute.QualifierValues, filterValues, parameterExpression );
if ( expression != null )
{
var attributeValues = attributeValueService
.Queryable()
.Where( v => v.Attribute.Id == attribute.Id );
attributeValues = attributeValues.Where( parameterExpression, expression, null );
groupQry = groupQry.Where( w => attributeValues.Select( v => v.EntityId ).Contains( w.Id ) );
}
}
}
}
List<GroupLocation> fences = null;
List<Group> groups = null;
// Run query to get list of matching groups
SortProperty sortProperty = gGroups.SortProperty;
if ( sortProperty != null )
{
groups = groupQry.Sort( sortProperty ).ToList();
}
else
{
groups = groupQry.OrderBy( g => g.Name ).ToList();
}
int? fenceGroupTypeId = GetGroupTypeId( GetAttributeValue( "GeofencedGroupType" ).AsGuidOrNull() );
bool showMap = GetAttributeValue( "ShowMap" ).AsBoolean();
bool showFences = showMap && GetAttributeValue( "ShowFence" ).AsBoolean();
var distances = new Dictionary<int, double>();
// If we care where these groups are located...
if ( fenceGroupTypeId.HasValue || showMap || showProximity )
//.........这里部分代码省略.........
示例4: LoadDropDowns
/// <summary>
/// Loads the drop downs.
/// </summary>
private void LoadDropDowns()
{
// Controls on Main Campaign Panel
GroupService groupService = new GroupService( new RockContext() );
List<Group> groups = groupService.Queryable().Where( a => a.GroupType.Guid.Equals( new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_EVENTATTENDEES ) ) ).OrderBy( a => a.Name ).ToList();
groups.Insert( 0, new Group { Id = None.Id, Name = None.Text } );
ddlEventGroup.DataSource = groups;
ddlEventGroup.DataBind();
}
示例5: GetExpression
/// <summary>
/// Creates a Linq Expression that can be applied to an IQueryable to filter the result set.
/// </summary>
/// <param name="entityType">The type of entity in the result set.</param>
/// <param name="serviceInstance">A service instance that can be queried to obtain the result set.</param>
/// <param name="parameterExpression">The input parameter that will be injected into the filter expression.</param>
/// <param name="selection">A formatted string representing the filter settings.</param>
/// <returns>
/// A Linq Expression that can be used to filter an IQueryable.
/// </returns>
public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
{
var settings = new SelectSettings( selection );
var context = (RockContext)serviceInstance.Context;
//
// Evaluate the Data View that defines the candidate Groups.
//
var dataView = DataComponentSettingsHelper.GetDataViewForFilterComponent( settings.DataViewGuid, context );
var groupService = new GroupService( context );
var groupQuery = groupService.Queryable();
if (dataView != null)
{
groupQuery = DataComponentSettingsHelper.FilterByDataView( groupQuery, dataView, groupService );
}
else
{
// Apply a default Group filter to only show Groups that would be visible in a Group List.
groupQuery = groupQuery.Where( x => x.GroupType.ShowInGroupList );
}
var groupKeys = groupQuery.Select( x => x.Id );
//
// Construct the Query to return the list of Group Members matching the filter conditions.
//
var groupMemberQuery = new GroupMemberService( context ).Queryable();
// Filter By Group.
groupMemberQuery = groupMemberQuery.Where( x => groupKeys.Contains( x.GroupId ) );
// Filter By Group Role Type.
switch ( settings.RoleType )
{
case RoleTypeSpecifier.Member:
groupMemberQuery = groupMemberQuery.Where( x => !x.GroupRole.IsLeader );
break;
case RoleTypeSpecifier.Leader:
groupMemberQuery = groupMemberQuery.Where( x => x.GroupRole.IsLeader );
break;
}
// Filter by Group Member Status.
if ( settings.MemberStatus.HasValue )
{
groupMemberQuery = groupMemberQuery.Where( x => x.GroupMemberStatus == settings.MemberStatus.Value );
}
//
// Create a Select Expression to return the Person records referenced by the Group Members.
//
var personGroupsQuery = new PersonService( context ).Queryable()
.Where( p => groupMemberQuery.Select( gm => gm.PersonId ).Contains( p.Id ) );
var selectExpression = FilterExpressionExtractor.Extract<Model.Person>( personGroupsQuery, parameterExpression, "p" );
return selectExpression;
}
示例6: MapAttendance
/// <summary>
/// Maps the attendance.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
//private DateTime? StartDateTime { get; set;}
private void MapAttendance( IQueryable<Row> tableData )
{
var lookupContext = new RockContext();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying Attendance import ({0:N0} found).", totalRows ) );
var attendanceList = new List<Rock.Model.Attendance>();
var groupService = new GroupService( lookupContext );
var existingGroupList = new List<Group>();
existingGroupList = groupService.Queryable().ToList();
foreach ( var row in tableData )
{
DateTime? startTime = row["Start_Date_Time"] as DateTime?;
if ( startTime != null && startTime != DateTime.MinValue)
{
DateTime startDateTime = (DateTime)startTime;
if ( startDateTime.Year == 2014 && startDateTime.Month >= 1 && startDateTime.Month <= 8 )
{
//startDateTime = BruteForceDateTime(startTime);
var attendance = new Rock.Model.Attendance();
attendance.CreatedByPersonAliasId = ImportPersonAlias.Id;
attendance.ModifiedByPersonAliasId = ImportPersonAlias.Id;
attendance.CreatedDateTime = DateTime.Today;
attendance.ModifiedDateTime = DateTime.Today;
attendance.StartDateTime = startDateTime; //(DateTime)startTime;
attendance.DidAttend = true;
attendance.CampusId = 1; //Campus is needed for attendance to show in attendance analysis.
//string position = row["CheckedInAs"] as string;
//string jobTitle = row["Job_Title"] as string;
//string machineName = row["Checkin_Machine_Name"] as string;
int? rlcId = row["RLC_ID"] as int?;
int? individualId = row["Individual_ID"] as int?;
if ( individualId != null )
{
attendance.PersonAliasId = GetPersonAliasId( individualId );
}
DateTime? checkInTime = row["Check_In_Time"] as DateTime?;
if ( checkInTime != null )
{
// set the start time to the time they actually checked in. If null it maintains Start_Date_Time
attendance.StartDateTime = (DateTime)checkInTime; //BruteForceDateTime( checkInTime );
}
DateTime? checkOutTime = row["Check_Out_Time"] as DateTime?;
if ( checkOutTime != null )
{
attendance.EndDateTime = (DateTime)checkOutTime; //BruteForceDateTime( checkOutTime );
}
//string f1AttendanceCode = row["Tag_Code"] as string;
//if ( f1AttendanceCode != null )
//{
// attendance.AttendanceCode = new Rock.Model.AttendanceCode();
// attendance.AttendanceCode.Code = f1AttendanceCode;
//}
string f1AttendanceCheckedInAs = row["CheckedInAs"] as string;
if ( f1AttendanceCheckedInAs != null )
{
attendance.Note = f1AttendanceCheckedInAs;
}
// look up location, schedule, and device -- all of these fields can be null if need be
attendance.LocationId = GetLocationId( Convert.ToInt32( rlcId ) );
//look up Group
Group rlcGroup = existingGroupList.Where( g => g.ForeignId == ( rlcId.ToString() ) ).FirstOrDefault();
if ( rlcGroup != null )
{
attendance.GroupId = rlcGroup.Id;
}
var dvService = new DefinedValueService( lookupContext );
attendance.SearchTypeValueId = dvService.Queryable().Where( dv => dv.Value == "Phone Number" ).FirstOrDefault().Id;
//ReportProgress( 0, string.Format( "{0},{1},{2},{3},{4},{5},{6},{7},{8}", individualId,rlcId,rlcGroup.Name,attendance.CreatedByPersonAliasId,attendance.ModifiedByPersonAliasId,attendance.StartDateTime,attendance.DidAttend,attendance.AttendanceCode,attendance.LocationId ) );
//look into creating DeviceIds and Locations (Generic)
// Other Attributes to create:
// Tag_Comment
// BreakoutGroup_Name
// Pager_Code
//.........这里部分代码省略.........
示例7: Map
private void Map()
{
string mapStylingFormat = @"
<style>
#map_wrapper {{
height: {0}px;
}}
#map_canvas {{
width: 100%;
height: 100%;
border-radius: 8px;
}}
</style>";
lMapStyling.Text = string.Format( mapStylingFormat, GetAttributeValue( "MapHeight" ) );
string settingGroupTypeId = GetAttributeValue( "GroupType" );
string queryStringGroupTypeId = PageParameter( "GroupTypeId" );
if ( ( string.IsNullOrWhiteSpace(settingGroupTypeId) && string.IsNullOrWhiteSpace(queryStringGroupTypeId) ) )
{
pnlMap.Visible = false;
lMessages.Text = "<div class='alert alert-warning'><strong>Group Mapper</strong> Please configure a group type to display as a block setting or pass a GroupTypeId as a query parameter.</div>";
}
else
{
var rockContext = new RockContext();
pnlMap.Visible = true;
int groupsMapped = 0;
int groupsWithNoGeo = 0;
StringBuilder sbGroupJson = new StringBuilder();
StringBuilder sbGroupsWithNoGeo = new StringBuilder();
Guid? groupType = null;
int groupTypeId = -1;
if ( !string.IsNullOrWhiteSpace( settingGroupTypeId ) )
{
groupType = new Guid( settingGroupTypeId );
}
else
{
if ( !string.IsNullOrWhiteSpace( queryStringGroupTypeId ) && Int32.TryParse( queryStringGroupTypeId, out groupTypeId ) )
{
groupType = new GroupTypeService( rockContext ).Get( groupTypeId ).Guid;
}
}
if ( groupType != null )
{
Template template = null;
if ( GetAttributeValue( "ShowMapInfoWindow" ).AsBoolean() )
{
template = Template.Parse( GetAttributeValue( "InfoWindowContents" ).Trim() );
}
else
{
template = Template.Parse( string.Empty );
}
var groupPageRef = new PageReference( GetAttributeValue( "GroupDetailPage" ) );
// create group detail link for use in map's info window
var personPageParams = new Dictionary<string, string>();
personPageParams.Add( "PersonId", string.Empty );
var personProfilePage = LinkedPageUrl( "PersonProfilePage", personPageParams );
var groupEntityType = EntityTypeCache.Read( typeof( Group ) );
var dynamicGroups = new List<dynamic>();
// Create query to get attribute values for selected attribute keys.
var attributeKeys = GetAttributeValue( "Attributes" ).SplitDelimitedValues().ToList();
var attributeValues = new AttributeValueService( rockContext ).Queryable( "Attribute" )
.Where( v =>
v.Attribute.EntityTypeId == groupEntityType.Id &&
attributeKeys.Contains( v.Attribute.Key ) );
GroupService groupService = new GroupService( rockContext );
var groups = groupService.Queryable()
.Where( g => g.GroupType.Guid == groupType )
.Select( g => new
{
Group = g,
GroupId = g.Id,
GroupName = g.Name,
GroupGuid = g.Guid,
GroupMemberTerm = g.GroupType.GroupMemberTerm,
GroupCampus = g.Campus.Name,
IsActive = g.IsActive,
GroupLocation = g.GroupLocations
.Where( l => l.Location.GeoPoint != null )
.Select( l => new
{
l.Location.Street1,
l.Location.Street2,
//.........这里部分代码省略.........
示例8: LoadDropDowns
/// <summary>
/// Loads the groups.
/// </summary>
private void LoadDropDowns()
{
var groupEntityType = EntityTypeCache.Read( typeof( Group ) );
var currentGroup = RockPage.GetCurrentContext( groupEntityType ) as Group;
var groupIdString = Request.QueryString["groupId"];
if ( groupIdString != null )
{
var groupId = groupIdString.AsInteger();
if ( currentGroup == null || currentGroup.Id != groupId )
{
currentGroup = SetGroupContext( groupId, false );
}
}
var parts = ( GetAttributeValue( "GroupFilter" ) ?? string.Empty ).Split( '|' );
Guid? groupTypeGuid = null;
Guid? rootGroupGuid = null;
if ( parts.Length >= 1 )
{
groupTypeGuid = parts[0].AsGuidOrNull();
if ( parts.Length >= 2 )
{
rootGroupGuid = parts[1].AsGuidOrNull();
}
}
var rockContext = new RockContext();
var groupService = new GroupService( rockContext );
var groupTypeService = new GroupTypeService( rockContext );
IQueryable<Group> qryGroups = null;
// if rootGroup is set, use that as the filter. Otherwise, use GroupType as the filter
if ( rootGroupGuid.HasValue )
{
var rootGroup = groupService.Get( rootGroupGuid.Value );
if ( rootGroup != null )
{
qryGroups = groupService.GetAllDescendents( rootGroup.Id ).AsQueryable();
}
}
else if ( groupTypeGuid.HasValue )
{
SetGroupTypeContext( groupTypeGuid );
if ( GetAttributeValue( "IncludeGroupTypeChildren" ).AsBoolean() )
{
var childGroupTypeGuids = groupTypeService.Queryable().Where( t => t.ParentGroupTypes.Select( p => p.Guid ).Contains( groupTypeGuid.Value ) )
.Select( t => t.Guid ).ToList();
qryGroups = groupService.Queryable().Where( a => childGroupTypeGuids.Contains( a.GroupType.Guid ) );
}
else
{
qryGroups = groupService.Queryable().Where( a => a.GroupType.Guid == groupTypeGuid.Value );
}
}
// no results
if ( qryGroups == null )
{
nbSelectGroupTypeWarning.Visible = true;
lCurrentSelection.Text = string.Empty;
rptGroups.Visible = false;
}
else
{
nbSelectGroupTypeWarning.Visible = false;
rptGroups.Visible = true;
lCurrentSelection.Text = currentGroup != null ? currentGroup.ToString() : GetAttributeValue( "NoGroupText" );
var groupList = qryGroups.OrderBy( a => a.Order )
.ThenBy( a => a.Name ).ToList()
.Select( a => new GroupItem() { Name = a.Name, Id = a.Id } )
.ToList();
// check if the group can be unselected
if ( !string.IsNullOrEmpty( GetAttributeValue( "ClearSelectionText" ) ) )
{
var blankGroup = new GroupItem
{
Name = GetAttributeValue( "ClearSelectionText" ),
Id = Rock.Constants.All.Id
};
groupList.Insert( 0, blankGroup );
}
rptGroups.DataSource = groupList;
rptGroups.DataBind();
}
}
示例9: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
Group group;
bool wasSecurityRole = false;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
ScheduleService scheduleService = new ScheduleService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
CategoryService categoryService = new CategoryService( rockContext );
if ( ( ddlGroupType.SelectedValueAsInt() ?? 0 ) == 0 )
{
ddlGroupType.ShowErrorMessage( Rock.Constants.WarningMessage.CannotBeBlank( GroupType.FriendlyTypeName ) );
return;
}
int groupId = int.Parse( hfGroupId.Value );
if ( groupId == 0 )
{
group = new Group();
group.IsSystem = false;
group.Name = string.Empty;
}
else
{
group = groupService.Queryable( "Schedule,GroupLocations.Schedules" ).Where( g => g.Id == groupId ).FirstOrDefault();
wasSecurityRole = group.IsSecurityRole;
var selectedLocations = GroupLocationsState.Select( l => l.Guid );
foreach ( var groupLocation in group.GroupLocations.Where( l => !selectedLocations.Contains( l.Guid ) ).ToList() )
{
group.GroupLocations.Remove( groupLocation );
groupLocationService.Delete( groupLocation );
}
}
foreach ( var groupLocationState in GroupLocationsState )
{
GroupLocation groupLocation = group.GroupLocations.Where( l => l.Guid == groupLocationState.Guid ).FirstOrDefault();
if ( groupLocation == null )
{
groupLocation = new GroupLocation();
group.GroupLocations.Add( groupLocation );
}
else
{
groupLocationState.Id = groupLocation.Id;
groupLocationState.Guid = groupLocation.Guid;
var selectedSchedules = groupLocationState.Schedules.Select( s => s.Guid ).ToList();
foreach( var schedule in groupLocation.Schedules.Where( s => !selectedSchedules.Contains( s.Guid)).ToList())
{
groupLocation.Schedules.Remove( schedule );
}
}
groupLocation.CopyPropertiesFrom( groupLocationState );
var existingSchedules = groupLocation.Schedules.Select( s => s.Guid ).ToList();
foreach ( var scheduleState in groupLocationState.Schedules.Where( s => !existingSchedules.Contains( s.Guid )).ToList())
{
var schedule = scheduleService.Get( scheduleState.Guid );
if ( schedule != null )
{
groupLocation.Schedules.Add( schedule );
}
}
}
group.Name = tbName.Text;
group.Description = tbDescription.Text;
group.CampusId = ddlCampus.SelectedValue.Equals( None.IdValue ) ? (int?)null : int.Parse( ddlCampus.SelectedValue );
group.GroupTypeId = int.Parse( ddlGroupType.SelectedValue );
group.ParentGroupId = gpParentGroup.SelectedValue.Equals( None.IdValue ) ? (int?)null : int.Parse( gpParentGroup.SelectedValue );
group.IsSecurityRole = cbIsSecurityRole.Checked;
group.IsActive = cbIsActive.Checked;
string iCalendarContent = string.Empty;
// If unique schedule option was selected, but a schedule was not defined, set option to 'None'
var scheduleType = rblScheduleSelect.SelectedValueAsEnum<ScheduleType>( ScheduleType.None );
if ( scheduleType == ScheduleType.Custom )
{
iCalendarContent = sbSchedule.iCalendarContent;
var calEvent = ScheduleICalHelper.GetCalenderEvent( iCalendarContent );
if ( calEvent == null || calEvent.DTStart == null )
{
scheduleType = ScheduleType.None;
}
}
//.........这里部分代码省略.........
示例10: LoadRegistration
private void LoadRegistration()
{
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
AttendanceService attendanceService = new AttendanceService( rockContext );
// get list of groups of this type
var groups = groupService.Queryable()
.Where( g =>
g.GroupTypeId == _groupType.Id
&& g.IsActive == true )
.ToList();
var groupIds = groups.Select( g => g.Id ).ToList();
// get listing of possible attendance for groups of this type
var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues( GetAttributeValue( "DateRange" ) ?? "-1||" );
_schedules = attendanceService.Queryable()
.Where( a =>
a.GroupId.HasValue
&& groupIds.Contains( a.GroupId.Value )
&& a.StartDateTime >= dateRange.Start.Value
&& a.StartDateTime <= dateRange.End.Value
&& a.LocationId == _location.Id )
.Select( a => new ScheduleResult
{
Group = a.Group,
Schedule = a.Schedule,
Date = a.StartDateTime
} )
.Distinct()
.ToList();
// get personal schedules (things you already signed up for)
_personalSchedules = attendanceService.Queryable()
.Where( a =>
a.GroupId.HasValue
&& groupIds.Contains( a.GroupId.Value )
&& a.StartDateTime >= dateRange.Start.Value
&& a.StartDateTime <= dateRange.End.Value
&& a.PersonAlias.PersonId == CurrentPersonId
&& a.LocationId == _location.Id
&& a.RSVP == RSVP.Yes)
.Select( a => new ScheduleResult
{
Group = a.Group,
Schedule = a.Schedule,
Date = a.StartDateTime
} )
.Distinct()
.ToList();
rptScheduleDates.DataSource = _schedules.Select( s => s.Date.Date ).Distinct();
rptScheduleDates.DataBind();
}
示例11: Execute
/// <summary>
/// Executes the specified workflow.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="action">The workflow action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public override bool Execute( RockContext rockContext, Model.WorkflowAction action, Object entity, out List<string> errorMessages )
{
var checkInState = GetCheckInState( entity, out errorMessages );
if ( checkInState != null && checkInState.CheckIn.SearchType != null )
{
var personService = new PersonService( rockContext );
var memberService = new GroupMemberService( rockContext );
GroupService groupService = new GroupService( rockContext );
PhoneNumberService phoneNumberService = new PhoneNumberService( rockContext );
int familyGroupTypeId = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() ).Id;
var dvInactive = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid() );
if ( checkInState.CheckIn.SearchType.Guid.Equals( new Guid( SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER ) ) )
{
string numericPhone = checkInState.CheckIn.SearchValue.AsNumeric();
var personRecordTypeId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid() ).Id;
// Find the families with any member who has a phone number that contains selected value
var familyQry = phoneNumberService.Queryable().AsNoTracking();
if ( checkInState.CheckInType == null || checkInState.CheckInType.PhoneSearchType == PhoneSearchType.EndsWith )
{
char[] charArray = numericPhone.ToCharArray();
Array.Reverse( charArray );
familyQry = familyQry.Where( o =>
o.NumberReversed.StartsWith( new string( charArray ) ) );
}
else
{
familyQry = familyQry.Where( o =>
o.Number.Contains( numericPhone ) );
}
var tmpQry = familyQry.Join( personService.Queryable().AsNoTracking(),
o => new { PersonId = o.PersonId, IsDeceased = false, RecordTypeValueId = personRecordTypeId },
p => new { PersonId = p.Id, IsDeceased = p.IsDeceased, RecordTypeValueId = p.RecordTypeValueId.Value },
( pn, p ) => new { Person = p, PhoneNumber = pn } )
.Join( memberService.Queryable().AsNoTracking(),
pn => pn.Person.Id,
m => m.PersonId,
( o, m ) => new { PersonNumber = o.PhoneNumber, GroupMember = m } );
var familyIdQry = groupService.Queryable().Where( g => tmpQry.Any( o => o.GroupMember.GroupId == g.Id ) && g.GroupTypeId == familyGroupTypeId )
.Select( g => g.Id )
.Distinct();
int maxResults = checkInState.CheckInType != null ? checkInState.CheckInType.MaxSearchResults : 100;
if ( maxResults > 0 )
{
familyIdQry = familyIdQry.Take( maxResults );
}
var familyIds = familyIdQry.ToList();
// Load the family members
var familyMembers = memberService
.Queryable( "Group,GroupRole,Person" ).AsNoTracking()
.Where( m => familyIds.Contains( m.GroupId ) )
.ToList();
// Add each family
foreach ( int familyId in familyIds )
{
// Get each of the members for this family
var familyMemberQry = familyMembers
.Where( m =>
m.GroupId == familyId &&
m.Person.NickName != null );
if ( checkInState.CheckInType != null && checkInState.CheckInType.PreventInactivePeopele && dvInactive != null )
{
familyMemberQry = familyMemberQry
.Where( m =>
m.Person.RecordStatusValueId != dvInactive.Id );
}
var thisFamilyMembers = familyMemberQry.ToList();
if ( thisFamilyMembers.Any() )
{
var group = thisFamilyMembers
.Select( m => m.Group )
.FirstOrDefault();
var firstNames = thisFamilyMembers
.OrderBy( m => m.GroupRole.Order )
.ThenBy( m => m.Person.BirthYear )
.ThenBy( m => m.Person.BirthMonth )
.ThenBy( m => m.Person.BirthDay )
//.........这里部分代码省略.........
示例12: MapGroupsAttendance
/// <summary>
/// Maps the group attendance.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
//private DateTime? StartDateTime { get; set;}
private void MapGroupsAttendance( IQueryable<Row> tableData )
{
var lookupContext = new RockContext();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying Attendance import ({0:N0} found).", totalRows ) );
var attendanceList = new List<Rock.Model.Attendance>();
var groupService = new GroupService( lookupContext );
var existingGroupList = new List<Group>();
existingGroupList = groupService.Queryable().Where(g => g.ForeignId != null).ToList();
foreach ( var row in tableData )
{
DateTime? startTime = row["StartDateTime"] as DateTime?;
if ( startTime != null && startTime != DateTime.MinValue )
{
int? groupId = row["GroupID"] as int?;
if ( existingGroupList.Find(g => g.ForeignId == groupId.ToString()) != null ) //making sure the group has been created.
{
DateTime startDateTime = (DateTime)startTime;
DateTime? endTime = row["EndDateTime"] as DateTime?;
int? met = row["Met"] as int?;
bool didAttend = true;
if ( met == 0 ) { didAttend = false; }
string comments = row["Comments"] as string;
var attendance = new Rock.Model.Attendance();
attendance.CreatedByPersonAliasId = ImportPersonAlias.Id;
attendance.ModifiedByPersonAliasId = ImportPersonAlias.Id;
attendance.CreatedDateTime = DateTime.Today;
attendance.ModifiedDateTime = DateTime.Today;
attendance.StartDateTime = startDateTime;
attendance.EndDateTime = endTime;
attendance.DidAttend = didAttend;
attendance.Note = comments;
attendance.CampusId = 1; //Campus is needed for attendance to show in attendance analysis.
attendance.GroupId = existingGroupList.Find( g => g.ForeignId == groupId.ToString() ).Id;
int? individualId = row["IndividualID"] as int?;
if ( individualId != null )
{
attendance.PersonAliasId = GetPersonAliasId( individualId );
}
////look up Group
//int? groupId = row["GroupID"] as int?;
//Group group = existingGroupList.Where( g => g.ForeignId == ( groupId.ToString() ) ).FirstOrDefault();
//if ( group != null )
//{
// attendance.GroupId = group.Id;
//}
//no other search type right now; small group attendance not currently set up in Rock.
var dvService = new DefinedValueService( lookupContext );
attendance.SearchTypeValueId = dvService.Queryable().Where( dv => dv.Value == "Phone Number" ).FirstOrDefault().Id;
completed++;
if ( completed % percentage < 1 )
{
int percentComplete = completed / percentage;
ReportProgress( percentComplete, string.Format( "Completed: {0:N0} Percent Completed: {0:N0} ", completed, percentComplete ) );
}
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.Attendances.Add( attendance );
rockContext.SaveChanges( DisableAudit );
} );
ReportPartialProgress();
}
}
}
}
示例13: gp_SelectItem
/// <summary>
/// Handles the SelectItem event of the gp control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void gp_SelectItem( object sender, EventArgs e )
{
var rockContext = new RockContext();
var groupIdList = gp.SelectedValues.AsIntegerList();
var groupService = new GroupService( rockContext );
var qryGroups = groupService.GetByIds( groupIdList );
if ( qryGroups.Any() )
{
var groupTypeRoleService = new GroupTypeRoleService( rockContext );
var qryGroupTypeRoles = groupTypeRoleService.Queryable();
List<int> selectedGroupTypeIds = qryGroups.Select( a => a.GroupTypeId ).Distinct().ToList();
if ( cbChildGroups.Checked )
{
List<int> childGroupTypeIds = new List<int>();
foreach ( var groupId in qryGroups.Select( a => a.Id ).ToList() )
{
if ( cbChildGroupsPlusDescendants.Checked )
{
// get all children and descendants of the selected group(s)
var descendants = groupService.GetAllDescendents( groupId );
if ( !cbIncludeInactiveGroups.Checked )
{
descendants = descendants.Where( a => a.IsActive == true );
}
childGroupTypeIds.AddRange( descendants.Select( a => a.GroupTypeId ).Distinct().ToList() );
}
else
{
// get only immediate children of the selected group(s)
var childGroups = groupService.Queryable().Where( a => a.ParentGroupId == groupId );
if ( !cbIncludeInactiveGroups.Checked )
{
childGroups = childGroups.Where( a => a.IsActive == true );
}
childGroupTypeIds.AddRange( childGroups.Select( a => a.GroupTypeId ).Distinct().ToList() );
}
}
childGroupTypeIds = childGroupTypeIds.Distinct().ToList();
if ( cbIncludeSelectedGroup.Checked )
{
qryGroupTypeRoles = qryGroupTypeRoles.Where( a => a.GroupTypeId.HasValue && ( selectedGroupTypeIds.Contains( a.GroupTypeId.Value ) || childGroupTypeIds.Contains( a.GroupTypeId.Value ) ) );
}
else
{
qryGroupTypeRoles = qryGroupTypeRoles.Where( a => a.GroupTypeId.HasValue && childGroupTypeIds.Contains( a.GroupTypeId.Value ) );
}
}
else
{
qryGroupTypeRoles = qryGroupTypeRoles.Where( a => a.GroupTypeId.HasValue && selectedGroupTypeIds.Contains( a.GroupTypeId.Value ) );
}
var list = qryGroupTypeRoles.OrderBy( a => a.GroupType.Order ).ThenBy( a => a.GroupType.Name ).ThenBy( a => a.Order ).ThenBy( a => a.Name ).ToList();
cblRole.Items.Clear();
foreach ( var item in list )
{
cblRole.Items.Add( new ListItem( string.Format( "{0} ({1})", item.Name, item.GroupType.Name ), item.Guid.ToString() ) );
}
cblRole.Visible = list.Count > 0;
}
else
{
cblRole.Visible = false;
}
}
示例14: GetExpression
/// <summary>
/// Gets the expression.
/// </summary>
/// <param name="entityType">Type of the entity.</param>
/// <param name="serviceInstance">The service instance.</param>
/// <param name="parameterExpression">The parameter expression.</param>
/// <param name="selection">The selection.</param>
/// <returns></returns>
public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
{
string[] selectionValues = selection.Split( '|' );
if ( selectionValues.Length >= 2 )
{
GroupMemberService groupMemberService = new GroupMemberService( (RockContext)serviceInstance.Context );
List<Guid> groupGuids = selectionValues[0].Split( ',' ).AsGuidList();
var groupService = new GroupService( (RockContext)serviceInstance.Context );
var groupIds = groupService.GetByGuids( groupGuids ).Select( a => a.Id ).Distinct().ToList();
bool includeChildGroups = false;
bool includeChildGroupsIncludeSelected = false;
bool includeChildGroupsPlusDescendants = false;
bool includeInactiveGroups = false;
if ( selectionValues.Length >= 3 )
{
includeChildGroups = selectionValues[2].AsBooleanOrNull() ?? false;
}
if ( selectionValues.Length >= 6 )
{
includeChildGroupsIncludeSelected = selectionValues[4].AsBooleanOrNull() ?? false;
includeChildGroupsPlusDescendants = selectionValues[5].AsBooleanOrNull() ?? false;
}
else if ( includeChildGroups )
{
// in case the selection was saved before these options where added
includeChildGroupsIncludeSelected = true;
includeChildGroupsPlusDescendants = true;
}
if ( selectionValues.Length >= 7 )
{
includeInactiveGroups = selectionValues[6].AsBooleanOrNull() ?? true; ;
}
else
{
// if options where saved before this option was added, set to false, even though it would have included inactive before
includeInactiveGroups = false;
}
GroupMemberStatus? groupMemberStatus = null;
if ( selectionValues.Length >= 4 )
{
groupMemberStatus = selectionValues[3].ConvertToEnumOrNull<GroupMemberStatus>();
}
var groupMemberServiceQry = groupMemberService.Queryable();
if ( includeChildGroups )
{
List<int> childGroupIds = new List<int>();
foreach ( var groupId in groupIds )
{
if ( includeChildGroupsPlusDescendants )
{
// get all children and descendants of the selected group(s)
var descendants = groupService.GetAllDescendents( groupId );
if ( !includeInactiveGroups )
{
descendants = descendants.Where( a => a.IsActive == true );
}
childGroupIds.AddRange( descendants.Select( a => a.Id ).Distinct().ToList() );
}
else
{
// get only immediate children of the selected group(s)
var childGroups = groupService.Queryable().Where( a => a.ParentGroupId == groupId );
if ( !includeInactiveGroups )
{
childGroups = childGroups.Where( a => a.IsActive == true );
}
childGroupIds.AddRange( childGroups.Select( a => a.Id ) );
}
}
if ( includeChildGroupsIncludeSelected )
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => groupIds.Contains( xx.GroupId ) || childGroupIds.Contains( xx.GroupId ) );
}
else
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => childGroupIds.Contains( xx.GroupId ) );
}
}
else
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => groupIds.Contains( xx.GroupId ) );
}
//.........这里部分代码省略.........
示例15: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
Group group;
bool wasSecurityRole = false;
bool triggersUpdated = false;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
GroupRequirementService groupRequirementService = new GroupRequirementService( rockContext );
GroupMemberWorkflowTriggerService groupMemberWorkflowTriggerService = new GroupMemberWorkflowTriggerService( rockContext );
ScheduleService scheduleService = new ScheduleService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
CategoryService categoryService = new CategoryService( rockContext );
var roleGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() );
int roleGroupTypeId = roleGroupType != null ? roleGroupType.Id : int.MinValue;
if ( CurrentGroupTypeId == 0 )
{
ddlGroupType.ShowErrorMessage( Rock.Constants.WarningMessage.CannotBeBlank( GroupType.FriendlyTypeName ) );
return;
}
int groupId = hfGroupId.Value.AsInteger();
if ( groupId == 0 )
{
group = new Group();
group.IsSystem = false;
group.Name = string.Empty;
}
else
{
group = groupService.Queryable( "Schedule,GroupLocations.Schedules" ).Where( g => g.Id == groupId ).FirstOrDefault();
wasSecurityRole = group.IsActive && ( group.IsSecurityRole || group.GroupTypeId == roleGroupTypeId );
// remove any locations that removed in the UI
var selectedLocations = GroupLocationsState.Select( l => l.Guid );
foreach ( var groupLocation in group.GroupLocations.Where( l => !selectedLocations.Contains( l.Guid ) ).ToList() )
{
group.GroupLocations.Remove( groupLocation );
groupLocationService.Delete( groupLocation );
}
// remove any group requirements that removed in the UI
var selectedGroupRequirements = GroupRequirementsState.Select( a => a.Guid );
foreach ( var groupRequirement in group.GroupRequirements.Where( a => !selectedGroupRequirements.Contains( a.Guid ) ).ToList() )
{
group.GroupRequirements.Remove( groupRequirement );
groupRequirementService.Delete( groupRequirement );
}
// Remove any triggers that were removed in the UI
var selectedTriggerGuids = MemberWorkflowTriggersState.Select( r => r.Guid );
foreach ( var trigger in group.GroupMemberWorkflowTriggers.Where( r => !selectedTriggerGuids.Contains( r.Guid ) ).ToList() )
{
group.GroupMemberWorkflowTriggers.Remove( trigger );
groupMemberWorkflowTriggerService.Delete( trigger );
triggersUpdated = true;
}
}
// add/update any group requirements that were added or changed in the UI (we already removed the ones that were removed above)
foreach ( var groupRequirementState in GroupRequirementsState )
{
GroupRequirement groupRequirement = group.GroupRequirements.Where( a => a.Guid == groupRequirementState.Guid ).FirstOrDefault();
if ( groupRequirement == null )
{
groupRequirement = new GroupRequirement();
group.GroupRequirements.Add( groupRequirement );
}
groupRequirement.CopyPropertiesFrom( groupRequirementState );
}
// add/update any group locations that were added or changed in the UI (we already removed the ones that were removed above)
foreach ( var groupLocationState in GroupLocationsState )
{
GroupLocation groupLocation = group.GroupLocations.Where( l => l.Guid == groupLocationState.Guid ).FirstOrDefault();
if ( groupLocation == null )
{
groupLocation = new GroupLocation();
group.GroupLocations.Add( groupLocation );
}
else
{
groupLocationState.Id = groupLocation.Id;
groupLocationState.Guid = groupLocation.Guid;
var selectedSchedules = groupLocationState.Schedules.Select( s => s.Guid ).ToList();
foreach ( var schedule in groupLocation.Schedules.Where( s => !selectedSchedules.Contains( s.Guid ) ).ToList() )
{
//.........这里部分代码省略.........