/// <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) { Report report = null; using (new UnitOfWorkScope()) { ReportService service = new ReportService(); int reportId = int.Parse(hfReportId.Value); if (reportId == 0) { report = new Report(); report.IsSystem = false; } else { report = service.Get(reportId); } report.Name = tbName.Text; report.Description = tbDescription.Text; report.CategoryId = cpCategory.SelectedValueAsInt(); report.EntityTypeId = ddlEntityType.SelectedValueAsInt(); report.DataViewId = ddlDataView.SelectedValueAsInt(); if (!Page.IsValid) { return; } if (!report.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { if (report.Id.Equals(0)) { service.Add(report, CurrentPersonId); } service.Save(report, CurrentPersonId); }); } var qryParams = new Dictionary <string, string>(); qryParams["ReportId"] = report.Id.ToString(); NavigateToPage(this.CurrentPage.Guid, qryParams); }
/// <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) { Category category; CategoryService categoryService = new CategoryService(); int categoryId = hfCategoryId.ValueAsInt(); if (categoryId == 0) { category = new Category(); category.IsSystem = false; category.EntityTypeId = entityTypeId; category.EntityTypeQualifierColumn = entityTypeQualifierProperty; category.EntityTypeQualifierValue = entityTypeQualifierValue; } else { category = categoryService.Get(categoryId); } category.Name = tbName.Text; category.ParentCategoryId = cpParentCategory.SelectedValueAsInt(); category.IconCssClass = tbIconCssClass.Text; category.IconSmallFileId = imgIconSmall.ImageId; category.IconLargeFileId = imgIconLarge.ImageId; if (!Page.IsValid) { return; } if (!category.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { if (category.Id.Equals(0)) { categoryService.Add(category, CurrentPersonId); } categoryService.Save(category, CurrentPersonId); }); var qryParams = new Dictionary <string, string>(); qryParams["CategoryId"] = category.Id.ToString(); NavigateToPage(this.CurrentPage.Guid, qryParams); }
/// <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; // NOTE: Very similar code in GroupList.gGroups_Delete RockTransactionScope.WrapTransaction(() => { GroupService groupService = new GroupService(); AuthService authService = new AuthService(); Group group = groupService.Get(int.Parse(hfGroupId.Value)); if (group != null) { parentGroupId = group.ParentGroupId; string errorMessage; if (!groupService.CanDelete(group, out errorMessage)) { mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); return; } bool isSecurityRoleGroup = group.IsSecurityRole; if (isSecurityRoleGroup) { foreach (var auth in authService.Queryable().Where(a => a.GroupId.Equals(group.Id)).ToList()) { authService.Delete(auth, CurrentPersonId); authService.Save(auth, CurrentPersonId); } } groupService.Delete(group, CurrentPersonId); groupService.Save(group, CurrentPersonId); if (isSecurityRoleGroup) { Rock.Security.Authorization.Flush(); Rock.Security.Role.Flush(group.Id); } } }); // reload page, selecting the deleted group's parent var qryParams = new Dictionary <string, string>(); if (parentGroupId != null) { qryParams["groupId"] = parentGroupId.ToString(); } NavigateToPage(this.CurrentPage.Guid, qryParams); }
/// <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) { PersonBadge PersonBadge = null; var rockContext = new RockContext(); PersonBadgeService PersonBadgeService = new PersonBadgeService(rockContext); if (PersonBadgeId != 0) { PersonBadge = PersonBadgeService.Get(PersonBadgeId); } if (PersonBadge == null) { PersonBadge = new PersonBadge(); PersonBadgeService.Add(PersonBadge); } PersonBadge.Name = tbName.Text; PersonBadge.Description = tbDescription.Text; if (!string.IsNullOrWhiteSpace(compBadgeType.SelectedValue)) { var badgeType = EntityTypeCache.Read(compBadgeType.SelectedValue.AsGuid()); if (badgeType != null) { PersonBadge.EntityTypeId = badgeType.Id; } } PersonBadge.LoadAttributes(rockContext); Rock.Attribute.Helper.GetEditValues(phAttributes, PersonBadge); if (!Page.IsValid) { return; } if (!PersonBadge.IsValid) { return; } RockTransactionScope.WrapTransaction(() => { rockContext.SaveChanges(); PersonBadge.SaveAttributeValues(rockContext); }); PersonBadgeCache.Flush(PersonBadge.Id); 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) { Group group; GroupService groupService = new GroupService(); int groupId = int.Parse(hfGroupId.Value); if (groupId == 0) { group = new Group(); group.IsSystem = false; groupService.Add(group, CurrentPersonId); } else { // just in case this group is or was a SecurityRole Rock.Security.Role.Flush(groupId); group = groupService.Get(groupId); } 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 = ddlParentGroup.SelectedValue.Equals(None.IdValue) ? (int?)null : int.Parse(ddlParentGroup.SelectedValue); group.IsSecurityRole = cbIsSecurityRole.Checked; // check for duplicates within GroupType if (groupService.Queryable().Where(g => g.GroupTypeId.Equals(group.GroupTypeId)).Count(a => a.Name.Equals(group.Name, StringComparison.OrdinalIgnoreCase) && !a.Id.Equals(group.Id)) > 0) { tbName.ShowErrorMessage(WarningMessage.DuplicateFoundMessage("name", Group.FriendlyTypeName)); return; } if (!group.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { groupService.Save(group, CurrentPersonId); }); // just in case this group is or was a SecurityRole Rock.Security.Authorization.Flush(); NavigateToParentPage(); }
/// <summary> /// Handles the Click event of the btnSaveDefinedValue 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 btnSaveDefinedValue_Click(object sender, EventArgs e) { DefinedValue definedValue; DefinedValueService definedValueService = new DefinedValueService(); int definedValueId = hfDefinedValueId.ValueAsInt(); if (definedValueId.Equals(0)) { definedValue = new DefinedValue { Id = 0 }; definedValue.DefinedTypeId = hfDefinedTypeId.ValueAsInt(); definedValue.IsSystem = false; } else { definedValue = definedValueService.Get(definedValueId); } definedValue.Name = tbValueName.Text; definedValue.Description = tbValueDescription.Text; definedValue.LoadAttributes(); Rock.Attribute.Helper.GetEditValues(phDefinedValueAttributes, definedValue); if (!Page.IsValid) { return; } if (!definedValue.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { if (definedValue.Id.Equals(0)) { definedValueService.Add(definedValue, CurrentPersonId); } definedValueService.Save(definedValue, CurrentPersonId); Rock.Attribute.Helper.SaveAttributeValues(definedValue, CurrentPersonId); }); pnlDetails.Visible = true; pnlDefinedValueEditor.Visible = false; BindDefinedValuesGrid(); }
/// <summary> /// Handles the Click event of the btnSaveFinancialBatch 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 btnSaveFinancialBatch_Click(object sender, EventArgs e) { using (new Rock.Data.UnitOfWorkScope()) { var financialBatchService = new FinancialBatchService(); FinancialBatch financialBatch = null; int financialBatchId = 0; if (!string.IsNullOrEmpty(hfBatchId.Value)) { financialBatchId = int.Parse(hfBatchId.Value); } if (financialBatchId == 0) { financialBatch = new Rock.Model.FinancialBatch(); financialBatch.CreatedByPersonId = CurrentPersonId.Value; financialBatchService.Add(financialBatch, CurrentPersonId); } else { financialBatch = financialBatchService.Get(financialBatchId); } financialBatch.Name = tbName.Text; financialBatch.BatchStartDateTime = dtBatchDate.LowerValue; financialBatch.BatchEndDateTime = dtBatchDate.UpperValue; financialBatch.CampusId = cpCampus.SelectedCampusId; financialBatch.Status = (BatchStatus)ddlStatus.SelectedIndex; decimal fcontrolamt = 0; decimal.TryParse(tbControlAmount.Text, out fcontrolamt); financialBatch.ControlAmount = fcontrolamt; if (!financialBatch.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { financialBatchService.Save(financialBatch, CurrentPersonId); hfBatchId.SetValue(financialBatch.Id); }); } var savedFinancialBatch = new FinancialBatchService().Get(hfBatchId.ValueAsInt()); ShowReadOnly(savedFinancialBatch); }
/// <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) { if (Page.IsValid) { LayoutService layoutService = new LayoutService(); Layout layout; int layoutId = int.Parse(hfLayoutId.Value); // if adding a new layout if (layoutId.Equals(0)) { layout = new Layout { Id = 0 }; layout.SiteId = hfSiteId.ValueAsInt(); } else { //load existing group member layout = layoutService.Get(layoutId); } layout.Name = tbLayoutName.Text; layout.Description = tbDescription.Text; layout.FileName = ddlLayout.SelectedValue; if (!layout.IsValid) { return; } RockTransactionScope.WrapTransaction(() => { if (layout.Id.Equals(0)) { layoutService.Add(layout, CurrentPersonId); } layoutService.Save(layout, CurrentPersonId); }); LayoutCache.Flush(layout.Id); Dictionary <string, string> qryString = new Dictionary <string, string>(); qryString["siteId"] = hfSiteId.Value; NavigateToParentPage(qryString); } }
/// <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) { CompetencyPersonProject competencyPersonProject; ResidencyService <CompetencyPersonProject> competencyPersonProjectService = new ResidencyService <CompetencyPersonProject>(); int competencyPersonProjectId = int.Parse(hfCompetencyPersonProjectId.Value); if (competencyPersonProjectId == 0) { competencyPersonProject = new CompetencyPersonProject(); competencyPersonProjectService.Add(competencyPersonProject, CurrentPersonId); // these inputs are only editable on Add competencyPersonProject.ProjectId = ddlProject.SelectedValueAsInt() ?? 0; competencyPersonProject.CompetencyPersonId = hfCompetencyPersonId.ValueAsInt(); } else { competencyPersonProject = competencyPersonProjectService.Get(competencyPersonProjectId); } if (!string.IsNullOrWhiteSpace(tbMinAssessmentCountOverride.Text)) { competencyPersonProject.MinAssessmentCount = tbMinAssessmentCountOverride.Text.AsInteger(); } else { competencyPersonProject.MinAssessmentCount = null; } if (!competencyPersonProject.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { competencyPersonProjectService.Save(competencyPersonProject, CurrentPersonId); }); var qryParams = new Dictionary <string, string>(); qryParams["competencyPersonProjectId"] = competencyPersonProject.Id.ToString(); NavigateToPage(this.CurrentPage.Guid, qryParams); }
/// <summary> /// Handles the Click event of the btnSaveWorkflowTypeAttribute 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 btnSaveWorkflowTypeAttribute_Click(object sender, EventArgs e) { Attribute attribute = null; AttributeService attributeService = new AttributeService(); if (edtWorkflowTypeAttributes.AttributeId.HasValue) { attribute = attributeService.Get(edtWorkflowTypeAttributes.AttributeId.Value); } if (attribute == null) { attribute = new Attribute(); } edtWorkflowTypeAttributes.GetAttributeProperties(attribute); // Controls will show warnings if (!attribute.IsValid) { return; } RockTransactionScope.WrapTransaction(() => { if (attribute.Id.Equals(0)) { attribute.EntityTypeId = Rock.Web.Cache.EntityTypeCache.Read(typeof(Workflow)).Id; attribute.EntityTypeQualifierColumn = "WorkflowTypeId"; attribute.EntityTypeQualifierValue = hfWorkflowTypeId.Value; attributeService.Add(attribute, CurrentPersonId); } Rock.Web.Cache.AttributeCache.Flush(attribute.Id); attributeService.Save(attribute, CurrentPersonId); }); pnlDetails.Visible = true; pnlWorkflowTypeAttributes.Visible = false; // reload page so that other blocks respond to any data that was changed var qryParams = new Dictionary <string, string>(); qryParams["workflowTypeId"] = hfWorkflowTypeId.Value; NavigateToPage(this.CurrentPage.Guid, qryParams); }
/// <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) { BinaryFile BinaryFile; BinaryFileService BinaryFileService = new BinaryFileService(); AttributeService attributeService = new AttributeService(); int BinaryFileId = int.Parse(hfBinaryFileId.Value); if (BinaryFileId == 0) { BinaryFile = new BinaryFile(); BinaryFileService.Add(BinaryFile, CurrentPersonId); } else { BinaryFile = BinaryFileService.Get(BinaryFileId); } BinaryFile.IsTemporary = false; BinaryFile.FileName = tbName.Text; BinaryFile.Description = tbDescription.Text; BinaryFile.MimeType = tbMimeType.Text; BinaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt(); BinaryFile.LoadAttributes(); Rock.Attribute.Helper.GetEditValues(phAttributes, BinaryFile); if (!Page.IsValid) { return; } if (!BinaryFile.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { BinaryFileService.Save(BinaryFile, CurrentPersonId); Rock.Attribute.Helper.SaveAttributeValues(BinaryFile, CurrentPersonId); }); 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) { if (dpStartDate.SelectedDate > dpEndDate.SelectedDate) { dpStartDate.ShowErrorMessage(WarningMessage.DateRangeEndDateBeforeStartDate()); return; } Period period; ResidencyService <Period> periodService = new ResidencyService <Period>(); int periodId = int.Parse(hfPeriodId.Value); if (periodId == 0) { period = new Period(); periodService.Add(period, CurrentPersonId); } else { period = periodService.Get(periodId); } period.Name = tbName.Text; period.Description = tbDescription.Text; period.StartDate = dpStartDate.SelectedDate; period.EndDate = dpEndDate.SelectedDate; if (!period.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { periodService.Save(period, CurrentPersonId); }); var qryParams = new Dictionary <string, string>(); qryParams["periodId"] = period.Id.ToString(); NavigateToPage(this.CurrentPage.Guid, qryParams); }
/// <summary> /// Handles the Click event of the btnSaveType 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 btnSaveType_Click(object sender, EventArgs e) { DefinedType definedType = null; DefinedTypeService typeService = new DefinedTypeService(); int definedTypeId = hfDefinedTypeId.ValueAsInt(); if (definedTypeId == 0) { definedType = new DefinedType(); definedType.IsSystem = false; definedType.Order = 0; typeService.Add(definedType, CurrentPersonId); } else { DefinedTypeCache.Flush(definedTypeId); definedType = typeService.Get(definedTypeId); } definedType.Name = tbTypeName.Text; definedType.Category = tbTypeCategory.Text; definedType.Description = tbTypeDescription.Text; definedType.FieldTypeId = int.Parse(ddlTypeFieldType.SelectedValue); if (!definedType.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { typeService.Save(definedType, CurrentPersonId); // get it back to make sure we have a good Id definedType = typeService.Get(definedType.Guid); }); var qryParams = new Dictionary <string, string>(); qryParams["definedTypeId"] = definedType.Id.ToString(); NavigateToPage(this.CurrentPage.Guid, qryParams); }
/// <summary> /// Handles the Click event of the btnSaveDefinedTypeAttribute 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 btnSaveDefinedTypeAttribute_Click(object sender, EventArgs e) { Attribute attribute = null; AttributeService attributeService = new AttributeService(); if (edtDefinedTypeAttributes.AttributeId.HasValue) { attribute = attributeService.Get(edtDefinedTypeAttributes.AttributeId.Value); } if (attribute == null) { attribute = new Attribute(); } edtDefinedTypeAttributes.GetAttributeProperties(attribute); // Controls will show warnings if (!attribute.IsValid) { return; } RockTransactionScope.WrapTransaction(() => { if (attribute.Id.Equals(0)) { attribute.EntityTypeId = Rock.Web.Cache.EntityTypeCache.Read(typeof(DefinedValue)).Id; attribute.EntityTypeQualifierColumn = "DefinedTypeId"; attribute.EntityTypeQualifierValue = hfDefinedTypeId.Value; attributeService.Add(attribute, CurrentPersonId); } Rock.Web.Cache.AttributeCache.Flush(attribute.Id); attributeService.Save(attribute, CurrentPersonId); }); pnlDetails.Visible = true; pnlDefinedTypeAttributes.Visible = false; BindDefinedTypeAttributesGrid(); BindDefinedValuesGrid(); }
/// <summary> /// Handles the Delete event of the gList control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void gList_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { var groupMemberService = new GroupMemberService(); int groupMemberId = (int)e.RowKeyValue; GroupMember groupMember = groupMemberService.Get(groupMemberId); if (groupMember != null) { // check if person can be removed from the Group and also check if person can be removed from all the person assigned competencies string errorMessage; if (!groupMemberService.CanDelete(groupMember, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } var competencyPersonService = new ResidencyService <CompetencyPerson>(); var personCompetencyList = competencyPersonService.Queryable().Where(a => a.PersonId.Equals(groupMember.PersonId)); foreach (var item in personCompetencyList) { if (!competencyPersonService.CanDelete(item, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } } // if you made it this far, delete all person's assigned competencies, and finally delete from Group foreach (var item in personCompetencyList) { competencyPersonService.Delete(item, CurrentPersonId); competencyPersonService.Save(item, CurrentPersonId); } groupMemberService.Delete(groupMember, CurrentPersonId); groupMemberService.Save(groupMember, CurrentPersonId); } }); BindGrid(); }
/// <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) { Competency competency; ResidencyService <Competency> competencyService = new ResidencyService <Competency>(); int competencyId = int.Parse(hfCompetencyId.Value); if (competencyId == 0) { competency = new Competency(); competencyService.Add(competency, CurrentPersonId); } else { competency = competencyService.Get(competencyId); } competency.Name = tbName.Text; competency.Description = tbDescription.Text; competency.TrackId = hfTrackId.ValueAsInt(); competency.TeacherOfRecordPersonId = ppTeacherOfRecord.PersonId; competency.FacilitatorPersonId = ppFacilitator.PersonId; competency.Goals = tbGoals.Text; competency.CreditHours = tbCreditHours.Text.AsInteger(false); competency.SupervisionHours = tbSupervisionHours.Text.AsInteger(false); competency.ImplementationHours = tbImplementationHours.Text.AsInteger(false); if (!competency.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { competencyService.Save(competency, CurrentPersonId); }); var qryParams = new Dictionary <string, string>(); qryParams["competencyId"] = competency.Id.ToString(); NavigateToPage(this.CurrentPage.Guid, qryParams); }
/// <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 Delete event of the gDefinedType control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gDefinedType_Delete(object sender, RowEventArgs e) { var definedValueService = new DefinedValueService(); var definedTypeService = new DefinedTypeService(); DefinedType type = definedTypeService.Get(e.RowKeyId); if (type != null) { string errorMessage; if (!definedTypeService.CanDelete(type, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } // if this DefinedType has DefinedValues, see if they can be deleted var definedValues = definedValueService.GetByDefinedTypeId(type.Id).ToList(); foreach (var value in definedValues) { if (!definedValueService.CanDelete(value, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } } RockTransactionScope.WrapTransaction(() => { foreach (var value in definedValues) { definedValueService.Delete(value, CurrentPersonId); definedValueService.Save(value, CurrentPersonId); } definedTypeService.Delete(type, CurrentPersonId); definedTypeService.Save(type, CurrentPersonId); }); } gDefinedType_Bind(); }
/// <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) { Track track; ResidencyService <Track> trackService = new ResidencyService <Track>(); int trackId = hfTrackId.ValueAsInt(); int periodId = hfPeriodId.ValueAsInt(); if (trackId == 0) { track = new Track(); trackService.Add(track, CurrentPersonId); int maxDisplayOrder = trackService.Queryable() .Where(a => a.PeriodId.Equals(periodId)) .Select(a => a.DisplayOrder).DefaultIfEmpty(0).Max(); track.DisplayOrder = maxDisplayOrder + 1; } else { track = trackService.Get(trackId); } track.Name = tbName.Text; track.Description = tbDescription.Text; track.PeriodId = periodId; if (!track.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { trackService.Save(track, CurrentPersonId); }); var qryParams = new Dictionary <string, string>(); qryParams["trackId"] = track.Id.ToString(); NavigateToPage(this.CurrentPage.Guid, qryParams); }
/// <summary> /// Handles the Delete event of the grdScheduledJobs control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gScheduledJobs_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { ServiceJobService jobService = new ServiceJobService(); ServiceJob job = jobService.Get((int)e.RowKeyValue); string errorMessage; if (!jobService.CanDelete(job, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } jobService.Delete(job, CurrentPersonId); jobService.Save(job, CurrentPersonId); }); BindGrid(); }
/// <summary> /// Handles the Click event of the btnSaveType 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 btnSaveType_Click(object sender, EventArgs e) { DefinedType definedType = null; DefinedTypeService typeService = new DefinedTypeService(); int definedTypeId = hfDefinedTypeId.ValueAsInt(); if (definedTypeId == 0) { definedType = new DefinedType(); definedType.IsSystem = false; definedType.Order = 0; typeService.Add(definedType, CurrentPersonId); } else { Rock.Web.Cache.DefinedTypeCache.Flush(definedTypeId); definedType = typeService.Get(definedTypeId); } definedType.Name = tbTypeName.Text; definedType.Category = tbTypeCategory.Text; definedType.Description = tbTypeDescription.Text; definedType.FieldTypeId = int.Parse(ddlTypeFieldType.SelectedValue); if (!definedType.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { typeService.Save(definedType, CurrentPersonId); // get it back to make sure we have a good Id definedType = typeService.Get(definedType.Guid); }); ShowReadonlyDetails(definedType); }
/// <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) { Recording recording; var service = new RecordingService(); int recordingId = 0; if (!Int32.TryParse(hfRecordingId.Value, out recordingId)) { recordingId = 0; } if (recordingId == 0) { recording = new Recording(); service.Add(recording, CurrentPersonId); } else { recording = service.Get(recordingId); } recording.CampusId = cpCampus.SelectedCampusId; recording.App = tbApp.Text; recording.Date = dpDate.SelectedDate; recording.StreamName = tbStream.Text; recording.Label = tbLabel.Text; recording.RecordingName = tbRecording.Text; if (recordingId == 0 && cbStartRecording.Visible && cbStartRecording.Checked) { SendRequest("start", recording); } RockTransactionScope.WrapTransaction(() => { service.Save(recording, CurrentPersonId); }); NavigateToParentPage(); }
/// <summary> /// Handles the Delete event of the gGroups control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gGroups_Delete(object sender, RowEventArgs e) { // NOTE: Very similar code in GroupDetail.btnDelete_Click RockTransactionScope.WrapTransaction(() => { GroupService groupService = new GroupService(); AuthService authService = new AuthService(); Group group = groupService.Get((int)e.RowKeyValue); if (group != null) { string errorMessage; if (!groupService.CanDelete(group, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } bool isSecurityRoleGroup = group.IsSecurityRole; if (isSecurityRoleGroup) { foreach (var auth in authService.Queryable().Where(a => a.GroupId == group.Id).ToList()) { authService.Delete(auth, CurrentPersonId); authService.Save(auth, CurrentPersonId); } } groupService.Delete(group, CurrentPersonId); groupService.Save(group, CurrentPersonId); if (isSecurityRoleGroup) { Rock.Security.Authorization.Flush(); Rock.Security.Role.Flush(group.Id); } } }); BindGrid(); }
/// <summary> /// Handles the Delete event of the gWorkflows control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gWorkflows_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { WorkflowService workflowService = new WorkflowService(); Workflow workflow = workflowService.Get((int)e.RowKeyValue); if (workflow != null) { string errorMessage; if (!workflowService.CanDelete(workflow, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } workflowService.Delete(workflow, CurrentPersonId); workflowService.Save(workflow, CurrentPersonId); } }); BindGrid(); }
/// <summary> /// Handles the Delete event of the gCampuses control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gCampuses_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { CampusService campusService = new CampusService(); Campus campus = campusService.Get((int)e.RowKeyValue); if (campus != null) { string errorMessage; if (!campusService.CanDelete(campus, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } campusService.Delete(campus, CurrentPersonId); campusService.Save(campus, CurrentPersonId); } }); BindGrid(); }
/// <summary> /// Handles the Delete event of the rGridAccount control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void rGridAccount_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { var accountService = new FinancialAccountService(); var account = accountService.Get((int)e.RowKeyValue); if (account != null) { string errorMessage; if (!accountService.CanDelete(account, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } accountService.Delete(account, CurrentPersonId); accountService.Save(account, CurrentPersonId); } }); BindGrid(); }
/// <summary> /// Handles the Delete event of the gMarketingCampaignAds control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gMarketingCampaignAds_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService(); MarketingCampaignAd marketingCampaignAd = marketingCampaignAdService.Get(e.RowKeyId); if (marketingCampaignAd != null) { string errorMessage; if (!marketingCampaignAdService.CanDelete(marketingCampaignAd, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } marketingCampaignAdService.Delete(marketingCampaignAd, CurrentPersonId); marketingCampaignAdService.Save(marketingCampaignAd, CurrentPersonId); } }); BindGrid(); }
/// <summary> /// Handles the Delete event of the gSchedules control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gSchedules_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { ScheduleService scheduleService = new ScheduleService(); Schedule schedule = scheduleService.Get((int)e.RowKeyValue); if (schedule != null) { string errorMessage; if (!scheduleService.CanDelete(schedule, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } scheduleService.Delete(schedule, CurrentPersonId); scheduleService.Save(schedule, CurrentPersonId); } }); BindGrid(); }
/// <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> /// <exception cref="System.NotImplementedException"></exception> protected void btnSave_Click(object sender, EventArgs e) { using (new UnitOfWorkScope()) { RockTransactionScope.WrapTransaction(() => { var pledgeService = new FinancialPledgeService(); var person = FindPerson(); var pledges = GetPledges(person).ToList(); // Does this person already have a pledge for these accounts? // If so, give them the option to create a new one? var personPledgeAccountIds = pledgeService.Queryable() .Where(p => p.PersonId == person.Id) .Select(p => p.AccountId) .ToList(); if (Accounts.Any(a => personPledgeAccountIds.Contains(a.Id))) { pnlConfirm.Visible = true; Session.Add("CachedPledges", pledges); return; } foreach (var pledge in pledges) { if (!pledge.IsValid) { continue; } pledgeService.Add(pledge, person.Id); pledgeService.Save(pledge, person.Id); } ShowReceipt(pledges.Select(p => p.Id)); }); } }