/// <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) { BlockType blockType; var rockContext = new RockContext(); BlockTypeService blockTypeService = new BlockTypeService(rockContext); int blockTypeId = int.Parse(hfBlockTypeId.Value); if (blockTypeId == 0) { blockType = new BlockType(); blockTypeService.Add(blockType); } else { BlockTypeCache.Flush(blockTypeId); blockType = blockTypeService.Get(blockTypeId); } blockType.Name = tbName.Text; blockType.Path = tbPath.Text; blockType.Description = tbDescription.Text; if (!blockType.IsValid) { // Controls will render the error messages return; } rockContext.SaveChanges(); NavigateToParentPage(); }
/// <summary> /// Shows the edit. /// </summary> /// <param name="blockTypeId">The block type id.</param> protected void ShowEdit(int blockTypeId) { pnlDetails.Visible = true; pnlList.Visible = false; BlockTypeService blockTypeService = new BlockTypeService(); BlockType blockType = blockTypeService.Get(blockTypeId); if (blockType != null) { lActionTitle.Text = ActionTitle.Edit(BlockType.FriendlyTypeName); hfBlockTypeId.Value = blockType.Id.ToString(); tbName.Text = blockType.Name; tbPath.Text = blockType.Path; tbDescription.Text = blockType.Description; } else { lActionTitle.Text = ActionTitle.Add(BlockType.FriendlyTypeName); hfBlockTypeId.Value = 0.ToString(); tbName.Text = string.Empty; tbPath.Text = string.Empty; tbDescription.Text = string.Empty; } }
/// <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) { BlockType blockType; BlockTypeService blockTypeService = new BlockTypeService(); int blockTypeId = int.Parse(hfBlockTypeId.Value); if (blockTypeId == 0) { blockType = new BlockType(); blockTypeService.Add(blockType, CurrentPersonId); } else { BlockTypeCache.Flush(blockTypeId); blockType = blockTypeService.Get(blockTypeId); } blockType.Name = tbName.Text; blockType.Path = tbPath.Text; blockType.Description = tbDescription.Text; if (!blockType.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { blockTypeService.Save(blockType, 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) { BlockType blockType; BlockTypeService blockTypeService = new BlockTypeService(); int blockTypeId = int.Parse(hfBlockTypeId.Value); if (blockTypeId == 0) { blockType = new BlockType(); blockTypeService.Add(blockType, CurrentPersonId); } else { BlockTypeCache.Flush(blockTypeId); blockType = blockTypeService.Get(blockTypeId); } blockType.Name = tbName.Text; blockType.Path = tbPath.Text; blockType.Description = tbDescription.Text; if (!blockType.IsValid) { // Controls will render the error messages return; } blockTypeService.Save(blockType, CurrentPersonId); BindGrid(); pnlDetails.Visible = false; pnlList.Visible = true; }
/// <summary> /// Reads the specified GUID. /// </summary> /// <param name="guid">The GUID.</param> /// <returns></returns> public static BlockTypeCache Read(Guid guid) { ObjectCache cache = MemoryCache.Default; object cacheObj = cache[guid.ToString()]; if (cacheObj != null) { return(Read((int)cacheObj)); } else { var blockTypeService = new BlockTypeService(); var blockTypeModel = blockTypeService.Get(guid); if (blockTypeModel != null) { blockTypeModel.LoadAttributes(); var blockType = new BlockTypeCache(blockTypeModel); var cachePolicy = new CacheItemPolicy(); AddChangeMonitor(cachePolicy, blockType.Path); cache.Set(BlockTypeCache.CacheKey(blockType.Id), blockType, cachePolicy); var guidCachePolicy = new CacheItemPolicy(); AddChangeMonitor(guidCachePolicy, blockType.Path); cache.Set(blockType.Guid.ToString(), blockType.Id, guidCachePolicy); return(blockType); } else { return(null); } } }
private static BlockTypeCache LoadById2(int id, RockContext rockContext) { var blockTypeService = new BlockTypeService(rockContext); var blockTypeModel = blockTypeService.Get(id); if (blockTypeModel != null) { return(new BlockTypeCache(blockTypeModel)); } return(null); }
/// <summary> /// Handles the Delete event of the gBlockTypes 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 gBlockTypes_Delete(object sender, RowEventArgs e) { BlockTypeService blockTypeService = new BlockTypeService(); BlockType blockType = blockTypeService.Get((int)gBlockTypes.DataKeys[e.RowIndex]["id"]); if (CurrentBlock != null) { blockTypeService.Delete(blockType, CurrentPersonId); blockTypeService.Save(blockType, CurrentPersonId); Rock.Web.Cache.BlockTypeCache.Flush(blockType.Id); } BindGrid(); }
/// <summary> /// Handles the Delete event of the gBlockTypes 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 gBlockTypes_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); BlockTypeService blockTypeService = new BlockTypeService(rockContext); BlockType blockType = blockTypeService.Get(e.RowKeyId); if (blockType != null) { string errorMessage; if (!blockTypeService.CanDelete(blockType, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } blockTypeService.Delete(blockType); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Handles the Delete event of the gBlockTypes 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 gBlockTypes_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { BlockTypeService blockTypeService = new BlockTypeService(); BlockType blockType = blockTypeService.Get((int)e.RowKeyValue); if (blockType != null) { string errorMessage; if (!blockTypeService.CanDelete(blockType, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } blockTypeService.Delete(blockType, CurrentPersonId); blockTypeService.Save(blockType, CurrentPersonId); Rock.Web.Cache.BlockTypeCache.Flush(blockType.Id); } }); BindGrid(); }
/// <summary> /// Returns Block Type object from cache. If block does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id"></param> /// <returns></returns> public static BlockTypeCache Read(int id) { string cacheKey = BlockTypeCache.CacheKey(id); ObjectCache cache = MemoryCache.Default; BlockTypeCache blockType = cache[cacheKey] as BlockTypeCache; if (blockType != null) { return(blockType); } else { var blockTypeService = new BlockTypeService(); var blockTypeModel = blockTypeService.Get(id); if (blockTypeModel != null) { blockTypeModel.LoadAttributes(); blockType = new BlockTypeCache(blockTypeModel); var cachePolicy = new CacheItemPolicy(); AddChangeMonitor(cachePolicy, blockType.Path); cache.Set(cacheKey, blockType, cachePolicy); var guidCachePolicy = new CacheItemPolicy(); AddChangeMonitor(guidCachePolicy, blockType.Path); cache.Set(blockType.Guid.ToString(), blockType.Id, guidCachePolicy); return(blockType); } else { return(null); } } }