internal void CastReductoBlockSpell(SpellParams model, ContentArea contentArea) { var currentPage = _pageRouteHelper.Page; var editableContent = _contentRepository.Get <PageData>(currentPage.ContentLink).CreateWritableClone(); foreach (var property in currentPage.Property) { if (property.PropertyValueType != typeof(ContentArea) || property.Value?.Equals(contentArea) != true) { continue; } for (int i = 0; i <= model.Index; i++) { ((ContentArea)editableContent.Property[property.Name].Value).Items.RemoveAt(0); } _contentRepository.Save(editableContent, EPiServer.DataAccess.SaveAction.CheckOut, EPiServer.Security.AccessLevel.Edit); } }
public override ActionResult Index(Models.ReductoBlock currentContent) { var spellParams = new SpellParams(); var spellCaster = new BlockSpells(); var contentArea = spellCaster.GetBlockArea(ControllerContext); spellParams.Count = contentArea.Items.Count; spellParams.Index = spellCaster.GetCurrentBlockIndex(contentArea, currentContent); // only cast spell when there are blocks to destroy and they are in front of you if (spellParams.Count <= 1 || spellParams.Index < 1) { return(PartialView("~/EPiServer/eGandalf.Spellbook.ReductoBlock/Views/ReductoBlock/index.cshtml", currentContent)); } spellCaster.CastReductoBlockSpell(spellParams, contentArea); return(PartialView("~/EPiServer/eGandalf.Spellbook.ReductoBlock/Views/ReductoBlock/index.cshtml", currentContent)); }