public void RemoveResource(long resourceId) { var resource = m_resourceRepository.FindById <Resource>(resourceId); var pageResource = m_resourceRepository.GetLatestResourceVersion <PageResource>(resourceId); var trackResource = m_resourceRepository.GetLatestResourceVersion <TrackResource>(resourceId); resource.IsRemoved = true; m_resourceRepository.Update(resource); if (pageResource != null) { var textResourceVersion = m_resourceRepository.GetLatestPageText(resourceId); TryRemoveResource(textResourceVersion); var imageResourceVersion = m_resourceRepository.GetLatestPageImage(resourceId); TryRemoveResource(imageResourceVersion); var chapterResourcesVersion = m_resourceRepository.GetLatestChaptersByPages(new[] { resourceId }); TryRemoveResources(chapterResourcesVersion); } if (trackResource != null) { var audioResourceVersion = m_resourceRepository.GetAudioRecordingsByTrack(resourceId); TryRemoveResources(audioResourceVersion); } }
protected override long ExecuteWorkImplementation() { var timeNow = DateTime.UtcNow; var latestPageVersion = m_resourceRepository.GetLatestResourceVersion <PageResource>(m_pageId); if (latestPageVersion == null) { throw new MainServiceException(MainServiceErrorCode.EntityNotFound, $"PageResource with ResourceId={m_pageId} was not found"); } var latestTextVersion = m_resourceRepository.GetLatestPageText(m_pageId); if (latestTextVersion != null) { throw new MainServiceException( MainServiceErrorCode.ChangeInConflict, $"Conflict. Text already exists for specified page with ID {m_pageId}." ); } var newResource = new Resource { Project = latestPageVersion.Resource.Project, Name = $"{latestPageVersion.Name}.md", ContentType = ContentTypeEnum.Page, NamedResourceGroup = null, ResourceType = ResourceTypeEnum.Text, }; var newVersion = new TextResource { CreatedByUser = m_resourceRepository.Load <User>(m_userId), CreateTime = timeNow, ExternalId = null, ResourcePage = latestPageVersion.Resource, Resource = newResource, VersionNumber = 1, }; newVersion.Resource.LatestVersion = newVersion; m_resourceRepository.Create(newVersion); var externalTextId = m_fulltextStorage.CreateNewTextVersion(newVersion, m_data.Text); newVersion.ExternalId = externalTextId; m_resourceRepository.Update(newVersion); return(newResource.Id); }