/// <summary> /// Deletes a collection of <see cref="IContentType"/> objects. /// </summary> /// <param name="contentTypes">Collection of <see cref="IContentType"/> to delete</param> /// <param name="userId">Optional id of the user issueing the delete</param> /// <remarks> /// Deleting a <see cref="IContentType"/> will delete all the <see cref="IContent"/> objects based on this <see cref="IContentType"/> /// </remarks> public void Delete(IEnumerable <IContentType> contentTypes, int userId = 0) { var asArray = contentTypes.ToArray(); if (DeletingContentType.IsRaisedEventCancelled(new DeleteEventArgs <IContentType>(asArray), this)) { return; } using (new WriteLock(Locker)) { foreach (var contentType in asArray) { _contentService.DeleteContentOfType(contentType.Id); } var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateContentTypeRepository(uow)) { foreach (var contentType in asArray) { repository.Delete(contentType); } uow.Commit(); DeletedContentType.RaiseEvent(new DeleteEventArgs <IContentType>(asArray, false), this); } Audit.Add(AuditTypes.Delete, string.Format("Delete ContentTypes performed by user"), userId, -1); } }
/// <summary> /// Deletes a single <see cref="IContentType"/> object /// </summary> /// <param name="contentType"><see cref="IContentType"/> to delete</param> /// <param name="userId">Optional id of the user issueing the delete</param> /// <remarks>Deleting a <see cref="IContentType"/> will delete all the <see cref="IContent"/> objects based on this <see cref="IContentType"/></remarks> public void Delete(IContentType contentType, int userId = 0) { if (DeletingContentType.IsRaisedEventCancelled(new DeleteEventArgs <IContentType>(contentType), this)) { return; } using (new WriteLock(Locker)) { _contentService.DeleteContentOfType(contentType.Id); var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateContentTypeRepository(uow)) { repository.Delete(contentType); uow.Commit(); DeletedContentType.RaiseEvent(new DeleteEventArgs <IContentType>(contentType, false), this); } Audit.Add(AuditTypes.Delete, string.Format("Delete ContentType performed by user"), userId, contentType.Id); } }