コード例 #1
0
        /// <summary>
        /// Creates the specified catalog entry.
        /// </summary>
        /// <param name="stream">The stream of <see cref="CatalogEntryStream" /> type to create the entry from.</param>
        /// <returns>The newly created instance of <see cref="CatalogEntry" /> type.</returns>
        public async Task <CatalogEntry> CreateCatalogEntry(CatalogEntryStream stream)
        {
            CatalogEntry entry = stream.Entry;

            FileDocument fileDocument = await this.mapper.MapNewAsync <CatalogEntry, FileDocument>(entry);

            CatalogDocument catalogDocument = null;

            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                IFileDocumentRepository fileRepository = scope.GetRepository <IFileDocumentRepository>();
                fileDocument = await fileRepository.SaveAsync(fileDocument);

                if ((entry.Catalog?.ID).HasValue)
                {
                    ICatalogDocumentRepository catalogRepository = scope.GetRepository <ICatalogDocumentRepository>();
                    catalogDocument = await catalogRepository.GetAsync(entry.Catalog.ID);
                }
            }

            entry = await this.mapper.MapAsync(fileDocument, entry);

            entry.Catalog = await this.mapper.MapAsync(catalogDocument, entry.Catalog);

            return(entry);
        }
コード例 #2
0
        /// <summary>
        /// Gets a value indicating whether the specified catalog entry already exists.
        /// </summary>
        /// <param name="entry">The catalog entry.</param>
        /// <returns><c>true</c> if the catalog entry exists. Otherwise <c>false.</c></returns>
        public async Task <bool> CatalogEntryExists(CatalogEntry entry)
        {
            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                IFileDocumentRepository repository = scope.GetRepository <IFileDocumentRepository>();

                return((await repository.GetAsync(entry.ID)) != null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Deletes the specified catalog entry.
        /// </summary>
        /// <param name="entry">The instance of <see cref="CatalogEntry" /> type to delete.</param>
        /// <returns>
        /// The deleted instance of <see cref="CatalogEntry"/> type.
        /// </returns>
        public async Task <CatalogEntry> DeleteCatalogEntry(CatalogEntry entry)
        {
            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                IFileDocumentRepository repository = scope.GetRepository <IFileDocumentRepository>();

                await repository.DeleteAsync(entry.ID);
            }

            return(entry);
        }