/// <summary> /// Deletes an element. /// </summary> /// <param name="tenantId">The tenant that element to delete belongs to.</param> /// <param name="elementTypeId">Identifies the type of element to delete.</param> /// <param name="elementId">Identifies the element to delete.</param> /// <param name="unitOfWork">Unit of work.</param> public void Delete(long tenantId, Guid elementTypeId, long elementId, IUnitOfWork unitOfWork = null) { try { IAdvancedElementService customElementService = (IAdvancedElementService)_elementFactory.GetElementService(elementTypeId); ICustomElementValidator customElementValidator = _elementFactory.GetElementValidator(elementTypeId); IUnitOfWork localUnitOfWork = (unitOfWork == null && customElementService != null) ? _unitOfWorkFactory.CreateUnitOfWork() : null; try { if (customElementValidator != null) { customElementValidator.ValidateDelete(tenantId, elementTypeId, elementId, unitOfWork ?? localUnitOfWork); } if (customElementService != null) { customElementService.Delete(tenantId, elementId, unitOfWork ?? localUnitOfWork); } _elementRepository.Delete(tenantId, elementId, unitOfWork ?? localUnitOfWork); if (localUnitOfWork != null) { localUnitOfWork.Commit(); } } catch { if (localUnitOfWork != null) { localUnitOfWork.Rollback(); } throw; } finally { if (localUnitOfWork != null) { localUnitOfWork.Dispose(); } } } catch (ValidationErrorException) { throw; } catch (Exception ex) { throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex); } }