public ServiceJob GetAddTestJob(JobNotificationStatus jobNotificationStatus = JobNotificationStatus.None) { var testJob = new ServiceJob { IsSystem = true, IsActive = true, Name = "Test Job", Description = "This job is used for testing RockJobListener", Class = "Rock.Tests.Integration.Jobs.RockJobListenerTestJob", CronExpression = "0 0 1 * * ?", NotificationStatus = jobNotificationStatus, Guid = "84AE12A7-968B-4D28-AB39-81D36D1F230E".AsGuid(), NotificationEmails = "*****@*****.**" }; using (var rockContext = new RockContext()) { var serviceJobService = new ServiceJobService(rockContext); var job = serviceJobService.Get(testJob.Guid); if (job != null) { testJobId = job.Id; return(job); } serviceJobService.Add(testJob); rockContext.SaveChanges(); } testJobId = testJob.Id; return(testJob); }
/// <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; } RockTransactionScope.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; 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(); }