/// <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 ) { ServiceJob job; ServiceJobService jobService = new ServiceJobService(); int jobId = int.Parse( hfId.Value ); if ( jobId == 0 ) { job = new ServiceJob(); jobService.Add( job, CurrentPersonId ); } else { job = jobService.Get( jobId ); } job.Name = tbName.Text; job.Description = tbDescription.Text; job.IsActive = cbActive.Checked; job.Assembly = tbAssembly.Text; job.Class = tbClass.Text; job.NotificationEmails = tbNotificationEmails.Text; job.NotificationStatus = (JobNotificationStatus)int.Parse( drpNotificationStatus.SelectedValue ); job.CronExpression = tbCronExpression.Text; if ( !job.IsValid ) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction( () => { jobService.Save( job, CurrentPersonId ); } ); BindGrid(); pnlDetails.Visible = false; pnlGrid.Visible = true; }
/// <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 ) { try { ExpressionDescriptor.GetDescription( tbCronExpression.Text ); } catch (Exception ex) { tbCronExpression.ShowErrorMessage( "Invalid Cron Expression: " + ex.Message ); return; } ServiceJob job; var rockContext = new RockContext(); ServiceJobService jobService = new ServiceJobService( rockContext ); int jobId = int.Parse( hfId.Value ); if ( jobId == 0 ) { job = new ServiceJob(); jobService.Add( job ); } else { job = jobService.Get( jobId ); } job.Name = tbName.Text; job.Description = tbDescription.Text; job.IsActive = cbActive.Checked; if (job.Class != ddlJobTypes.SelectedValue) { job.Class = ddlJobTypes.SelectedValue; //// if the Class has changed, the current Assembly value might not match, //// so set the Assembly to null to have Rock figure it out automatically job.Assembly = null; } job.NotificationEmails = tbNotificationEmails.Text; job.NotificationStatus = (JobNotificationStatus)int.Parse( ddlNotificationStatus.SelectedValue ); job.CronExpression = tbCronExpression.Text; if ( !job.IsValid ) { // Controls will render the error messages return; } rockContext.WrapTransaction( () => { rockContext.SaveChanges(); job.LoadAttributes( rockContext ); Rock.Attribute.Helper.GetEditValues( phAttributes, job ); job.SaveAttributeValues( rockContext ); } ); NavigateToParentPage(); }
/// <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 ) { ServiceJob job; var rockContext = new RockContext(); ServiceJobService jobService = new ServiceJobService( rockContext ); int jobId = int.Parse( hfId.Value ); if ( jobId == 0 ) { job = new ServiceJob(); jobService.Add( job ); } else { job = jobService.Get( jobId ); } job.Name = tbName.Text; job.Description = tbDescription.Text; job.IsActive = cbActive.Checked; job.Class = ddlJobTypes.SelectedValue; job.NotificationEmails = tbNotificationEmails.Text; job.NotificationStatus = (JobNotificationStatus)int.Parse( ddlNotificationStatus.SelectedValue ); job.CronExpression = tbCronExpression.Text; if ( !job.IsValid ) { // Controls will render the error messages return; } rockContext.WrapTransaction( () => { rockContext.SaveChanges(); job.LoadAttributes( rockContext ); Rock.Attribute.Helper.GetEditValues( phAttributes, job ); job.SaveAttributeValues( rockContext ); } ); NavigateToParentPage(); }