public async Task Delete(string uniqueId) { var request = new DeleteElementRequest { ElementId = uniqueId }; await m_elementService.Delete(new List <DeleteElementRequest> { request }); }
/// <summary> /// Deletes elements that are no longer in-use (i.e. not referenced by a master page or a page). /// </summary> /// <param name="tenantId">Identifies website.</param> /// <param name="elements">Element identifiers.</param> /// <param name="unitOfWork">Unit of work.</param> private void DeleteElementsThatAreNoLongerInUse(long tenantId, HashSet <long> elements, IUnitOfWork unitOfWork) { foreach (long elementId in elements) { if (!ElementInUse(tenantId, elementId, unitOfWork)) { _elementService.Delete(tenantId, elementId, unitOfWork); } } }
public IActionResult DeleteElement([FromForm] string nameElement) { try { _elementService.Delete(nameElement); } catch (Exception ex) { return(RedirectToAction(actionName: "Delete")); } return(RedirectToAction(actionName: "List")); }
public Response <ElementDto> DeleteById(string name) { Response <ElementDto> response = new Response <ElementDto>(); try { response.Object = _elementService.Delete(name); } catch (Exception ex) { response.Errored = true; response.ErrorMessage = ex.Message; _logger.LogError($"{typeof(ElementController).FullName}.{nameof(DeleteById)}", null); } return(response); }
/// <summary> /// Updates a configurable page zone. Creates new elements and removes old elements. Re-orders existing elements. /// </summary> /// <param name="tenantId">Website that page belongs to.</param> /// <param name="pageId">Page identifier.</param> /// <param name="pageZoneId">Page zone identifier.</param> /// <param name="pageZoneElements">New page zone contents.</param> /// <param name="unitOfWork">Unit of work.</param> public void UpdateZone(long tenantId, long pageId, long pageZoneId, List <PageZoneElementInfo> pageZoneElements, IUnitOfWork unitOfWork = null) { // If we don't have a unit of work in place, create one now so that we can rollback all changes in case of failure IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null; // Do the page update try { // Get page, master page and page zone that we administering Page page = Read(tenantId, pageId, unitOfWork ?? localUnitOfWork); MasterPage masterPage = _masterPageService.Read(tenantId, page.MasterPageId, unitOfWork ?? localUnitOfWork); PageZone pageZone = page.PageZones.Where(z => z.PageZoneId == pageZoneId).FirstOrDefault(); // Perform validation _pageValidator.ValidateUpdateZone(masterPage, page, pageZoneId, pageZoneElements); // Construct new list of page zone elements List <PageZoneElement> newPageZoneElements = new List <PageZoneElement>(); foreach (PageZoneElementInfo info in pageZoneElements) { // Create new page zone element? if (info.PageZoneElementId == 0) { IElementSettings element = _elementService.New(tenantId, info.ElementTypeId); element.Name = info.Name; long elementId = _elementService.Create(element, unitOfWork ?? localUnitOfWork); newPageZoneElements.Add(new PageZoneElement { TenantId = tenantId, PageId = pageId, PageZoneId = pageZoneId, PageZoneElementId = 0, SortOrder = info.SortOrder, ElementTypeId = info.ElementTypeId, ElementId = elementId, Element = element }); } // Update existing page zone element? if (info.PageZoneElementId != 0) { IElementSettings element = _elementService.New(tenantId, info.ElementTypeId); element.Name = info.Name; PageZoneElement pageZoneElement = pageZone.PageZoneElements.Where(e => e.PageZoneElementId == info.PageZoneElementId).First(); pageZoneElement.SortOrder = info.SortOrder; pageZoneElement.Element = element; newPageZoneElements.Add(pageZoneElement); } } // Do the page zone element update _pageRepository.UpdatePageZoneElements(tenantId, pageId, pageZoneId, newPageZoneElements, unitOfWork ?? localUnitOfWork); // Get elements that might be removed List <ElementKeyValue> elementsToDelete = new List <ElementKeyValue>(); foreach (PageZoneElement pageZoneElement in pageZone.PageZoneElements) { PageZoneElementInfo pageZoneElementInfo = pageZoneElements.Where(e => e.PageZoneElementId == pageZoneElement.PageZoneElementId).FirstOrDefault(); if (pageZoneElementInfo == null) { elementsToDelete.Add(new ElementKeyValue { ElementId = pageZoneElement.ElementId, ElementTypeId = pageZoneElement.ElementTypeId }); } } // Delete elements if no longer in use foreach (ElementKeyValue elementKeyValue in elementsToDelete) { if (!ElementInUse(tenantId, elementKeyValue.ElementId, unitOfWork ?? localUnitOfWork)) { _elementService.Delete(tenantId, elementKeyValue.ElementTypeId, elementKeyValue.ElementId, unitOfWork ?? localUnitOfWork); } } // Commit work if local unit of work in place if (localUnitOfWork != null) { localUnitOfWork.Commit(); } } catch (ValidationErrorException) { if (localUnitOfWork != null) { localUnitOfWork.Rollback(); } throw; } catch (Exception ex) { if (localUnitOfWork != null) { localUnitOfWork.Rollback(); } throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex); } }
public void DeleteElement(int id) { _elementService.Delete(id); }