本文整理汇总了C#中Rock.Model.ScheduleService.Queryable方法的典型用法代码示例。如果您正苦于以下问题:C# ScheduleService.Queryable方法的具体用法?C# ScheduleService.Queryable怎么用?C# ScheduleService.Queryable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.ScheduleService
的用法示例。
在下文中一共展示了ScheduleService.Queryable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddScheduleColumns
/// <summary>
/// Adds the schedule columns.
/// </summary>
private void AddScheduleColumns()
{
ScheduleService scheduleService = new ScheduleService();
// limit Schedules to ones that have a CheckInStartOffsetMinutes
var scheduleQry = scheduleService.Queryable().Where( a => a.CheckInStartOffsetMinutes != null );
// limit Schedules to the Category from the Filter
int scheduleCategoryId = rFilter.GetUserPreference( "Category" ).AsInteger() ?? Rock.Constants.All.Id;
if ( scheduleCategoryId != Rock.Constants.All.Id )
{
scheduleQry = scheduleQry.Where( a => a.CategoryId == scheduleCategoryId );
}
else
{
// NULL (or 0) means Shared, so specifically filter so to show only Schedules with CategoryId NULL
scheduleQry = scheduleQry.Where( a => a.CategoryId == null );
}
// clear out any existing schedule columns and add the ones that match the current filter setting
var scheduleList = scheduleQry.ToList().OrderBy( a => a.ToString() ).ToList();
var checkBoxEditableFields = gGroupLocationSchedule.Columns.OfType<CheckBoxEditableField>().ToList();
foreach ( var field in checkBoxEditableFields )
{
gGroupLocationSchedule.Columns.Remove( field );
}
foreach ( var item in scheduleList )
{
string dataFieldName = string.Format( "scheduleField_{0}", item.Id );
CheckBoxEditableField field = new CheckBoxEditableField { HeaderText = item.Name, DataField = dataFieldName };
gGroupLocationSchedule.Columns.Add( field );
}
if ( !scheduleList.Any() )
{
nbNotification.Text = nbNotification.Text = String.Format( "<p><strong>Warning</strong></p>No schedules found. Consider <a class='alert-link' href='{0}'>adding a schedule</a> or a different schedule category.", ResolveUrl( "~/Schedules" ) );
nbNotification.Visible = true;
}
else
{
nbNotification.Visible = false;
}
}
示例2: BindGrid
/// <summary>
/// Binds the grid.
/// </summary>
private void BindGrid()
{
ScheduleService scheduleService = new ScheduleService( new RockContext() );
SortProperty sortProperty = gSchedules.SortProperty;
var qry = scheduleService.Queryable().Select( a =>
new
{
a.Id,
a.Name,
CategoryName = a.Category.Name
} );
if ( sortProperty != null )
{
gSchedules.DataSource = qry.Sort( sortProperty ).ToList();
}
else
{
gSchedules.DataSource = qry.OrderBy( s => s.Name ).ToList();
}
gSchedules.EntityTypeId = EntityTypeCache.Read<Schedule>().Id;
gSchedules.DataBind();
}
示例3: btnSave_Click
//.........这里部分代码省略.........
// make it an "Unnamed" metrics schedule
schedule.Name = string.Empty;
schedule.CategoryId = metricScheduleCategoryId;
}
// if the schedule was a unique schedule (configured in the Metric UI, set the schedule's ical content to the schedule builder UI's value
if ( scheduleSelectionType == ScheduleSelectionType.Unique )
{
schedule.iCalendarContent = sbSchedule.iCalendarContent;
}
if ( !schedule.HasSchedule() && scheduleSelectionType == ScheduleSelectionType.Unique )
{
// don't save as a unique schedule if the schedule doesn't do anything
schedule = null;
}
else
{
if ( schedule.Id == 0 )
{
scheduleService.Add( schedule );
// save to make sure we have a scheduleId
rockContext.SaveChanges();
}
}
if ( schedule != null )
{
metric.ScheduleId = schedule.Id;
}
else
{
metric.ScheduleId = null;
}
if ( metric.Id == 0 )
{
metricService.Add( metric );
// save to make sure we have a metricId
rockContext.SaveChanges();
}
// update MetricCategories for Metric
metric.MetricCategories = metric.MetricCategories ?? new List<MetricCategory>();
var selectedCategoryIds = cpMetricCategories.SelectedValuesAsInt();
// delete any categories that were removed
foreach ( var metricCategory in metric.MetricCategories.ToList() )
{
if ( !selectedCategoryIds.Contains( metricCategory.CategoryId ) )
{
metricCategoryService.Delete( metricCategory );
}
}
// add any categories that were added
foreach ( int categoryId in selectedCategoryIds )
{
if ( !metric.MetricCategories.Any( a => a.CategoryId == categoryId ) )
{
metricCategoryService.Add( new MetricCategory { CategoryId = categoryId, MetricId = metric.Id } );
}
}
rockContext.SaveChanges();
// delete any orphaned Unnamed metric schedules
var metricIdSchedulesQry = metricService.Queryable().Select( a => a.ScheduleId );
int? metricScheduleId = schedule != null ? schedule.Id : (int?)null;
var orphanedSchedules = scheduleService.Queryable()
.Where( a => a.CategoryId == metricScheduleCategoryId && a.Name == string.Empty && a.Id != ( metricScheduleId ?? 0 ) )
.Where( s => !metricIdSchedulesQry.Any( m => m == s.Id ) );
foreach ( var item in orphanedSchedules )
{
scheduleService.Delete( item );
}
if ( orphanedSchedules.Any() )
{
rockContext.SaveChanges();
}
} );
var qryParams = new Dictionary<string, string>();
qryParams["MetricId"] = metric.Id.ToString();
if ( hfMetricCategoryId.ValueAsInt() == 0 )
{
int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsIntegerOrNull();
int? metricCategoryId = new MetricCategoryService( new RockContext() ).Queryable().Where( a => a.MetricId == metric.Id && a.CategoryId == parentCategoryId ).Select( a => a.Id ).FirstOrDefault();
hfMetricCategoryId.Value = metricCategoryId.ToString();
}
qryParams["MetricCategoryId"] = hfMetricCategoryId.Value;
qryParams["ExpandedIds"] = PageParameter( "ExpandedIds" );
NavigateToPage( RockPage.Guid, qryParams );
}
示例4: 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 )
{
Metric metric;
var rockContext = new RockContext();
MetricService metricService = new MetricService( rockContext );
MetricCategoryService metricCategoryService = new MetricCategoryService( rockContext );
MetricValueService metricValueService = new MetricValueService( rockContext );
bool deleteValuesOnSave = sender == btnDeleteValuesAndSave;
int metricId = hfMetricId.Value.AsInteger();
if ( metricId == 0 )
{
metric = new Metric();
}
else
{
metric = metricService.Get( metricId );
}
metric.Title = tbTitle.Text;
metric.Subtitle = tbSubtitle.Text;
metric.Description = tbDescription.Text;
metric.IconCssClass = tbIconCssClass.Text;
metric.SourceValueTypeId = ddlSourceType.SelectedValueAsId();
metric.XAxisLabel = tbXAxisLabel.Text;
metric.YAxisLabel = tbYAxisLabel.Text;
metric.IsCumulative = cbIsCumulative.Checked;
var origEntityType = metric.EntityTypeId.HasValue ? EntityTypeCache.Read( metric.EntityTypeId.Value ) : null;
var newEntityType = etpEntityType.SelectedEntityTypeId.HasValue ? EntityTypeCache.Read( etpEntityType.SelectedEntityTypeId.Value ) : null;
if ( origEntityType != null && !deleteValuesOnSave )
{
if ( newEntityType == null || newEntityType.Id != origEntityType.Id )
{
// if the EntityTypeId of this metric has changed to NULL or to another EntityType, warn about the EntityId values being wrong
bool hasEntityValues = metricValueService.Queryable().Any( a => a.MetricId == metric.Id && a.EntityId.HasValue );
if ( hasEntityValues )
{
nbEntityTypeChanged.Text = string.Format(
"Warning: You can't change the series partition to {0} when there are values associated with {1}. Do you want to delete existing values?",
newEntityType != null ? newEntityType.FriendlyName : "<none>",
origEntityType.FriendlyName );
mdEntityTypeChanged.Show();
nbEntityTypeChanged.Visible = true;
return;
}
}
}
metric.EntityTypeId = etpEntityType.SelectedEntityTypeId;
int sourceTypeDataView = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.METRIC_SOURCE_VALUE_TYPE_DATAVIEW.AsGuid() ).Id;
int sourceTypeSQL = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.METRIC_SOURCE_VALUE_TYPE_SQL.AsGuid() ).Id;
var personService = new PersonService( rockContext );
var metricChampionPerson = personService.Get( ppMetricChampionPerson.SelectedValue ?? 0 );
metric.MetricChampionPersonAliasId = metricChampionPerson != null ? metricChampionPerson.PrimaryAliasId : null;
var adminPerson = personService.Get( ppAdminPerson.SelectedValue ?? 0 );
metric.AdminPersonAliasId = adminPerson != null ? adminPerson.PrimaryAliasId : null;
if ( metric.SourceValueTypeId == sourceTypeSQL )
{
metric.SourceSql = ceSourceSql.Text;
}
else
{
metric.SourceSql = string.Empty;
}
if ( metric.SourceValueTypeId == sourceTypeDataView )
{
metric.DataViewId = ddlDataView.SelectedValueAsId();
}
else
{
metric.DataViewId = null;
}
var scheduleSelectionType = rblScheduleSelect.SelectedValueAsEnum<ScheduleSelectionType>();
if ( scheduleSelectionType == ScheduleSelectionType.NamedSchedule )
{
metric.ScheduleId = ddlSchedule.SelectedValueAsId();
}
else
{
metric.ScheduleId = hfUniqueScheduleId.ValueAsInt();
}
if ( !Page.IsValid )
{
return;
}
//.........这里部分代码省略.........
示例5: GetGroupOccurrences
/// <summary>
/// Gets occurrence data for the selected group
/// </summary>
/// <param name="group">The group.</param>
/// <param name="fromDateTime">From date time.</param>
/// <param name="toDateTime">To date time.</param>
/// <param name="locationIds">The location ids.</param>
/// <param name="scheduleIds">The schedule ids.</param>
/// <param name="loadSummaryData">if set to <c>true</c> [load summary data].</param>
/// <returns></returns>
public List<ScheduleOccurrence> GetGroupOccurrences( Group group, DateTime? fromDateTime, DateTime? toDateTime,
List<int> locationIds, List<int> scheduleIds, bool loadSummaryData )
{
var occurrences = new List<ScheduleOccurrence>();
if ( group != null )
{
var rockContext = (RockContext)this.Context;
var attendanceService = new AttendanceService( rockContext );
var scheduleService = new ScheduleService( rockContext );
var locationService = new LocationService( rockContext );
// Set up an 'occurrences' query for the group
var qry = attendanceService
.Queryable().AsNoTracking()
.Where( a => a.GroupId == group.Id );
// Filter by date range
if ( fromDateTime.HasValue )
{
var fromDate = fromDateTime.Value.Date;
qry = qry.Where( a => DbFunctions.TruncateTime( a.StartDateTime ) >= ( fromDate ) );
}
if ( toDateTime.HasValue )
{
var toDate = toDateTime.Value.Date;
qry = qry.Where( a => DbFunctions.TruncateTime( a.StartDateTime ) < ( toDate ) );
}
// Location Filter
if ( locationIds.Any() )
{
qry = qry.Where( a =>
a.LocationId.HasValue &&
locationIds.Contains( a.LocationId.Value ) );
}
// Schedule Filter
if ( scheduleIds.Any() )
{
qry = qry.Where( a =>
a.ScheduleId.HasValue &&
scheduleIds.Contains( a.ScheduleId.Value ) );
}
// Get the unique combination of location/schedule/date for the selected group
var occurrenceDates = qry
.Select( a => new
{
a.LocationId,
a.ScheduleId,
Date = DbFunctions.TruncateTime( a.StartDateTime )
} )
.Distinct()
.ToList();
// Get the locations for each unique location id
var selectedlocationIds = occurrenceDates.Select( o => o.LocationId ).Distinct().ToList();
var locations = locationService
.Queryable().AsNoTracking()
.Where( l => selectedlocationIds.Contains( l.Id ) )
.Select( l => new { l.Id, l.ParentLocationId, l.Name } )
.ToList();
var locationNames = new Dictionary<int, string>();
locations.ForEach( l => locationNames.Add( l.Id, l.Name ) );
// Get the parent location path for each unique location
var parentlocationPaths = new Dictionary<int, string>();
locations
.Where( l => l.ParentLocationId.HasValue )
.Select( l => l.ParentLocationId.Value )
.Distinct()
.ToList()
.ForEach( l => parentlocationPaths.Add( l, locationService.GetPath( l ) ) );
var locationPaths = new Dictionary<int, string>();
locations
.Where( l => l.ParentLocationId.HasValue )
.ToList()
.ForEach( l => locationPaths.Add( l.Id, parentlocationPaths[l.ParentLocationId.Value] ) );
// Get the schedules for each unique schedule id
var selectedScheduleIds = occurrenceDates.Select( o => o.ScheduleId ).Distinct().ToList();
var schedules = scheduleService
.Queryable().AsNoTracking()
.Where( s => selectedScheduleIds.Contains( s.Id ) )
.ToList();
var scheduleNames = new Dictionary<int, string>();
var scheduleStartTimes = new Dictionary<int, TimeSpan>();
schedules
.ForEach( s => {
//.........这里部分代码省略.........
示例6: btnSave_Click
//.........这里部分代码省略.........
if ( !metric.IsValid )
{
// Controls will render the error messages
return;
}
if ( !cpMetricCategories.SelectedValuesAsInt().Any() )
{
cpMetricCategories.ShowErrorMessage( "Must select at least one category" );
return;
}
// do a WrapTransaction since we are doing multiple SaveChanges()
RockTransactionScope.WrapTransaction( () =>
{
var scheduleService = new ScheduleService( rockContext );
var schedule = scheduleService.Get( metric.ScheduleId ?? 0 );
int metricScheduleCategoryId = new CategoryService( rockContext ).Get( Rock.SystemGuid.Category.SCHEDULE_METRICS.AsGuid() ).Id;
if ( schedule == null )
{
schedule = new Schedule();
// make it an "Unnamed" metrics schedule
schedule.Name = string.Empty;
schedule.CategoryId = metricScheduleCategoryId;
}
schedule.iCalendarContent = sbSchedule.iCalendarContent;
if ( schedule.Id == 0 )
{
scheduleService.Add( schedule );
// save to make sure we have a scheduleId
rockContext.SaveChanges();
}
metric.ScheduleId = schedule.Id;
if ( metric.Id == 0 )
{
metricService.Add( metric );
// save to make sure we have a metricId
rockContext.SaveChanges();
}
// update MetricCategories for Metric
metric.MetricCategories = metric.MetricCategories ?? new List<MetricCategory>();
var selectedCategoryIds = cpMetricCategories.SelectedValuesAsInt();
// delete any categories that were removed
foreach ( var metricCategory in metric.MetricCategories )
{
if ( !selectedCategoryIds.Contains( metricCategory.CategoryId ) )
{
metricCategoryService.Delete( metricCategory );
}
}
// add any categories that were added
foreach ( int categoryId in selectedCategoryIds )
{
if ( !metric.MetricCategories.Any( a => a.CategoryId == categoryId ) )
{
metricCategoryService.Add( new MetricCategory { CategoryId = categoryId, MetricId = metric.Id } );
}
}
rockContext.SaveChanges();
// delete any orphaned Unnamed metric schedules
var metricIdSchedulesQry = metricService.Queryable().Select( a => a.ScheduleId );
var orphanedSchedules = scheduleService.Queryable()
.Where( a => a.CategoryId == metricScheduleCategoryId && a.Name == string.Empty && a.Id != schedule.Id )
.Where( s => !metricIdSchedulesQry.Any( m => m == s.Id ) );
foreach ( var item in orphanedSchedules )
{
scheduleService.Delete( item );
}
if ( orphanedSchedules.Any() )
{
rockContext.SaveChanges();
}
} );
var qryParams = new Dictionary<string, string>();
qryParams["MetricId"] = metric.Id.ToString();
if ( hfMetricCategoryId.ValueAsInt() == 0 )
{
int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsInteger();
int? metricCategoryId = new MetricCategoryService( new RockContext() ).Queryable().Where( a => a.MetricId == metric.Id && a.CategoryId == parentCategoryId ).Select( a => a.Id ).FirstOrDefault();
hfMetricCategoryId.Value = metricCategoryId.ToString();
}
qryParams["MetricCategoryId"] = hfMetricCategoryId.Value;
NavigateToPage( RockPage.Guid, qryParams );
}