private Tuple <Resource, PageResource> TryCreateNewResource() { if (m_data.ResourcePageId == null) { throw new ArgumentException("Missing required parameters. Some parameters of ImageId, OriginalVersionId and ResourcePageId are required."); } var pageId = m_data.ResourcePageId.Value; var latestPageVersion = m_resourceRepository.GetLatestResourceVersion <PageResource>(pageId); if (latestPageVersion == null) { throw new MainServiceException(MainServiceErrorCode.EntityNotFound, $"PageResource with ResourceId={pageId} was not found"); } var latestImage = m_resourceRepository.GetLatestPageImage(pageId); if (latestImage != null) { throw new MainServiceException(MainServiceErrorCode.ChangeInConflict, $"Conflict. Image already exists for specified page with ID {pageId}."); } var newResource = new Resource { Project = latestPageVersion.Resource.Project, Name = m_data.FileName, ContentType = ContentTypeEnum.Page, NamedResourceGroup = null, ResourceType = ResourceTypeEnum.Image, }; return(new Tuple <Resource, PageResource>(newResource, latestPageVersion)); }
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); } }