本文整理汇总了C#中Rock.Model.ScheduleService.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ScheduleService.Add方法的具体用法?C# ScheduleService.Add怎么用?C# ScheduleService.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.ScheduleService
的用法示例。
在下文中一共展示了ScheduleService.Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 );
MetricPartitionService metricPartitionService = new MetricPartitionService( rockContext );
int metricId = hfMetricId.Value.AsInteger();
if ( metricId == 0 )
{
metric = new Metric();
}
else
{
metric = metricService.Get( metricId );
// remove any metricPartitions that were removed in the UI
var selectedMetricPartitionGuids = MetricPartitionsState.Select( r => r.Guid );
foreach ( var item in metric.MetricPartitions.Where( r => !selectedMetricPartitionGuids.Contains( r.Guid ) ).ToList() )
{
metric.MetricPartitions.Remove( item );
metricPartitionService.Delete( item );
}
}
metric.MetricPartitions = metric.MetricPartitions ?? new List<MetricPartition>();
if ( MetricPartitionsState.Count() > 1 && MetricPartitionsState.Any(a => !a.EntityTypeId.HasValue ))
{
mdMetricPartitionsEntityTypeWarning.Text = "If multiple partitions are defined for a metric, all the partitions must have an EntityType assigned";
mdMetricPartitionsEntityTypeWarning.Visible = true;
pwMetricPartitions.Expanded = true;
return;
}
mdMetricPartitionsEntityTypeWarning.Visible = false;
foreach ( var metricPartitionState in MetricPartitionsState )
{
MetricPartition metricPartition = metric.MetricPartitions.Where( r => r.Guid == metricPartitionState.Guid ).FirstOrDefault();
if ( metricPartition == null )
{
metricPartition = new MetricPartition();
metric.MetricPartitions.Add( metricPartition );
}
else
{
metricPartitionState.Id = metricPartition.Id;
metricPartitionState.Guid = metricPartition.Guid;
}
metricPartition.CopyPropertiesFrom( metricPartitionState );
}
// ensure there is at least one partition
if ( !metric.MetricPartitions.Any() )
{
var metricPartition = new MetricPartition();
metricPartition.EntityTypeId = null;
metricPartition.IsRequired = true;
metricPartition.Order = 0;
metric.MetricPartitions.Add( metricPartition );
}
metric.Title = tbTitle.Text;
metric.Subtitle = tbSubtitle.Text;
metric.Description = tbDescription.Text;
metric.IconCssClass = tbIconCssClass.Text;
metric.SourceValueTypeId = ddlSourceType.SelectedValueAsId();
metric.YAxisLabel = tbYAxisLabel.Text;
metric.IsCumulative = cbIsCumulative.Checked;
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 )
//.........这里部分代码省略.........
示例2: 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 )
{
Schedule schedule;
var rockContext = new RockContext();
ScheduleService scheduleService = new ScheduleService( rockContext );
int scheduleId = int.Parse( hfScheduleId.Value );
if ( scheduleId == 0 )
{
schedule = new Schedule();
scheduleService.Add( schedule );
}
else
{
schedule = scheduleService.Get( scheduleId );
}
schedule.Name = tbScheduleName.Text;
schedule.Description = tbScheduleDescription.Text;
schedule.iCalendarContent = sbSchedule.iCalendarContent;
schedule.CategoryId = cpCategory.SelectedValueAsInt();
int offsetMins = int.MinValue;
if ( int.TryParse( nbStartOffset.Text, out offsetMins ) )
{
schedule.CheckInStartOffsetMinutes = offsetMins;
}
else
{
schedule.CheckInStartOffsetMinutes = null;
}
offsetMins = int.MinValue;
if ( int.TryParse( nbEndOffset.Text, out offsetMins ) )
{
schedule.CheckInEndOffsetMinutes = offsetMins;
}
else
{
schedule.CheckInEndOffsetMinutes = null;
}
if ( !schedule.IsValid )
{
// Controls will render the error messages
return;
}
rockContext.SaveChanges();
var qryParams = new Dictionary<string, string>();
qryParams["ScheduleId"] = schedule.Id.ToString();
NavigateToPage( RockPage.Guid, qryParams );
}
示例3: btnSave_Click
//.........这里部分代码省略.........
return;
}
// do a WrapTransaction since we are doing multiple SaveChanges()
rockContext.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;
}
// 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 ) )
{
示例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 );
int metricId = hfMetricId.Value.AsInteger( false ) ?? 0;
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;
metric.EntityTypeId = etpEntityType.SelectedEntityTypeId;
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;
metric.SourceSql = ceSourceSql.Text;
metric.DataViewId = ddlDataView.SelectedValueAsId();
if ( rblScheduleSelect.SelectedValueAsEnum<ScheduleSelectionType>() == ScheduleSelectionType.NamedSchedule )
{
metric.ScheduleId = ddlSchedule.SelectedValueAsId();
}
else
{
metric.ScheduleId = hfUniqueScheduleId.ValueAsInt();
}
if ( !Page.IsValid )
{
return;
}
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();
//.........这里部分代码省略.........