/// <summary> /// Handles the Delete event of the rGrid 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 rGrid_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); var service = new ScheduleCategoryExclusionService(rockContext); var exclusion = service.Get(e.RowKeyId); if (exclusion != null) { string errorMessage = string.Empty; if (service.CanDelete(exclusion, out errorMessage)) { int categoryId = exclusion.CategoryId; service.Delete(exclusion); rockContext.SaveChanges(); CategoryCache.Flush(categoryId); Rock.CheckIn.KioskDevice.FlushAll(); } else { nbMessage.Text = errorMessage; nbMessage.Visible = true; } } BindGrid(); }
/// <summary> /// Handles the Delete event of the gCategories 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 gCategories_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); var service = new CategoryService(rockContext); var category = service.Get(e.RowKeyId); if (category != null) { string errorMessage = string.Empty; if (service.CanDelete(category, out errorMessage)) { int categoryId = category.Id; service.Delete(category); rockContext.SaveChanges(); CategoryCache.Flush(categoryId); } else { nbMessage.Text = errorMessage; nbMessage.Visible = true; } } BindGrid(); }
void gCategories_GridReorder(object sender, GridReorderEventArgs e) { var rockContext = new RockContext(); var categories = GetCategories(rockContext); if (categories != null) { var changedIds = new CategoryService(rockContext).Reorder(categories.ToList(), e.OldIndex, e.NewIndex); rockContext.SaveChanges(); foreach (int id in changedIds) { CategoryCache.Flush(id); } } BindGrid(); }
/// <summary> /// Handles the SaveClick event of the modalDetails 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 modalDetails_SaveClick(object sender, EventArgs e) { int?exclusionId = hfIdValue.ValueAsInt(); var rockContext = new RockContext(); var service = new ScheduleCategoryExclusionService(rockContext); ScheduleCategoryExclusion exclusion = null; if (exclusionId.HasValue) { exclusion = service.Get(exclusionId.Value); } if (exclusion == null) { exclusion = new ScheduleCategoryExclusion(); service.Add(exclusion); } exclusion.CategoryId = _categoryId.Value; exclusion.Title = tbTitle.Text; if (drpExclusion.LowerValue.HasValue) { exclusion.StartDate = drpExclusion.LowerValue.Value.Date; } if (drpExclusion.UpperValue.HasValue) { exclusion.EndDate = drpExclusion.UpperValue.Value.Date.AddDays(1).AddSeconds(-1); } if (exclusion.IsValid) { rockContext.SaveChanges(); CategoryCache.Flush(exclusion.CategoryId); Rock.CheckIn.KioskDevice.FlushAll(); hfIdValue.Value = string.Empty; modalDetails.Hide(); BindGrid(); } }
/// <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?parentCategoryId = null; var rockContext = new RockContext(); var categoryService = new CategoryService(rockContext); var category = categoryService.Get(int.Parse(hfCategoryId.Value)); if (category != null) { string errorMessage; if (!categoryService.CanDelete(category, out errorMessage)) { ShowReadonlyDetails(category); mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); } else { parentCategoryId = category.ParentCategoryId; CategoryCache.Flush(category.Id); categoryService.Delete(category); rockContext.SaveChanges(); // reload page, selecting the deleted category's parent var qryParams = new Dictionary <string, string>(); if (parentCategoryId != null) { qryParams["CategoryId"] = parentCategoryId.ToString(); } NavigateToPage(RockPage.Guid, qryParams); } } }
/// <summary> /// Handles the SaveClick event of the modalDetails 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 mdDetails_SaveClick(object sender, EventArgs e) { int categoryId = 0; if (hfIdValue.Value != string.Empty && !int.TryParse(hfIdValue.Value, out categoryId)) { categoryId = 0; } var rockContext = new RockContext(); var service = new CategoryService(rockContext); Category category = null; if (categoryId != 0) { category = service.Get(categoryId); } if (category == null) { category = new Category(); category.EntityTypeId = _entityTypeId; category.EntityTypeQualifierColumn = _entityCol; category.EntityTypeQualifierValue = _entityVal; var lastCategory = GetUnorderedCategories() .OrderByDescending(c => c.Order).FirstOrDefault(); category.Order = lastCategory != null ? lastCategory.Order + 1 : 0; service.Add(category); } category.Name = tbName.Text; category.Description = tbDescription.Text; category.ParentCategoryId = catpParentCategory.SelectedValueAsInt(); category.IconCssClass = tbIconCssClass.Text; category.HighlightColor = tbHighlightColor.Text; category.LoadAttributes(rockContext); Rock.Attribute.Helper.GetEditValues(phAttributes, category); List <int> orphanedBinaryFileIdList = new List <int>(); if (category.IsValid) { BinaryFileService binaryFileService = new BinaryFileService(rockContext); foreach (int binaryFileId in orphanedBinaryFileIdList) { var binaryFile = binaryFileService.Get(binaryFileId); if (binaryFile != null) { // marked the old images as IsTemporary so they will get cleaned up later binaryFile.IsTemporary = true; } } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); category.SaveAttributeValues(rockContext); }); CategoryCache.Flush(category.Id); hfIdValue.Value = string.Empty; mdDetails.Hide(); BindGrid(); } }
/// <summary> /// Handles the SaveClick event of the modalDetails 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 modalDetails_SaveClick(object sender, EventArgs e) { int categoryId = 0; if (hfIdValue.Value != string.Empty && !int.TryParse(hfIdValue.Value, out categoryId)) { categoryId = 0; } var rockContext = new RockContext(); var service = new CategoryService(rockContext); Category category = null; if (categoryId != 0) { CategoryCache.Flush(categoryId); category = service.Get(categoryId); } if (category == null) { category = new Category(); category.EntityTypeId = EntityTypeCache.Read(typeof(Rock.Model.Attribute)).Id; category.EntityTypeQualifierColumn = "EntityTypeId"; var lastCategory = GetUnorderedCategories(category.EntityTypeId) .OrderByDescending(c => c.Order).FirstOrDefault(); category.Order = lastCategory != null ? lastCategory.Order + 1 : 0; service.Add(category); } category.Name = tbName.Text; category.Description = tbDescription.Text; string QualifierValue = null; if ((entityTypePicker.SelectedEntityTypeId ?? 0) != 0) { QualifierValue = entityTypePicker.SelectedEntityTypeId.ToString(); } category.EntityTypeQualifierValue = QualifierValue; category.IconCssClass = tbIconCssClass.Text; category.HighlightColor = tbHighlightColor.Text; List <int> orphanedBinaryFileIdList = new List <int>(); if (category.IsValid) { BinaryFileService binaryFileService = new BinaryFileService(rockContext); foreach (int binaryFileId in orphanedBinaryFileIdList) { var binaryFile = binaryFileService.Get(binaryFileId); if (binaryFile != null) { // marked the old images as IsTemporary so they will get cleaned up later binaryFile.IsTemporary = true; } } rockContext.SaveChanges(); hfIdValue.Value = string.Empty; modalDetails.Hide(); BindFilter(); 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) { Category category; var rockContext = new RockContext(); CategoryService categoryService = new CategoryService(rockContext); int categoryId = hfCategoryId.ValueAsInt(); if (categoryId == 0) { category = new Category(); category.IsSystem = false; category.EntityTypeId = entityTypeId; category.EntityTypeQualifierColumn = entityTypeQualifierProperty; category.EntityTypeQualifierValue = entityTypeQualifierValue; category.Order = 0; categoryService.Add(category); } else { category = categoryService.Get(categoryId); } category.Name = tbName.Text; category.ParentCategoryId = cpParentCategory.SelectedValueAsInt(); category.IconCssClass = tbIconCssClass.Text; category.HighlightColor = tbHighlightColor.Text; List <int> orphanedBinaryFileIdList = new List <int>(); if (!Page.IsValid) { return; } // if the category IsValid is false, and the UI controls didn't report any errors, it is probably because the custom rules of category didn't pass. // So, make sure a message is displayed in the validation summary cvCategory.IsValid = category.IsValid; if (!cvCategory.IsValid) { cvCategory.ErrorMessage = category.ValidationResults.Select(a => a.ErrorMessage).ToList().AsDelimited("<br />"); return; } BinaryFileService binaryFileService = new BinaryFileService(rockContext); foreach (int binaryFileId in orphanedBinaryFileIdList) { var binaryFile = binaryFileService.Get(binaryFileId); if (binaryFile != null) { // marked the old images as IsTemporary so they will get cleaned up later binaryFile.IsTemporary = true; } } rockContext.SaveChanges(); CategoryCache.Flush(category.Id); var qryParams = new Dictionary <string, string>(); qryParams["CategoryId"] = category.Id.ToString(); NavigateToPage(RockPage.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; var rockContext = new RockContext(); CategoryService categoryService = new CategoryService(rockContext); int categoryId = hfCategoryId.ValueAsInt(); if (categoryId == 0) { category = new Category(); category.IsSystem = false; category.EntityTypeId = entityTypeId; category.EntityTypeQualifierColumn = entityTypeQualifierProperty; category.EntityTypeQualifierValue = entityTypeQualifierValue; category.Order = 0; categoryService.Add(category); } else { category = categoryService.Get(categoryId); } category.Name = tbName.Text; category.ParentCategoryId = cpParentCategory.SelectedValueAsInt(); category.IconCssClass = tbIconCssClass.Text; List <int> orphanedBinaryFileIdList = new List <int>(); if (!Page.IsValid) { return; } if (!category.IsValid) { // Controls will render the error messages return; } BinaryFileService binaryFileService = new BinaryFileService(rockContext); foreach (int binaryFileId in orphanedBinaryFileIdList) { var binaryFile = binaryFileService.Get(binaryFileId); if (binaryFile != null) { // marked the old images as IsTemporary so they will get cleaned up later binaryFile.IsTemporary = true; } } rockContext.SaveChanges(); CategoryCache.Flush(category.Id); var qryParams = new Dictionary <string, string>(); qryParams["CategoryId"] = category.Id.ToString(); NavigateToPage(RockPage.Guid, qryParams); }