Exemple #1
0
        /// <summary>
        /// Updates the specified catalog.
        /// </summary>
        /// <param name="catalog">The instance of <see cref="Catalog" /> type to update.</param>
        /// <returns>The updated instance of <see cref="Catalog"/> type.</returns>
        public async Task <Catalog> UpdateCatalog(Catalog catalog)
        {
            CatalogDocument catalogDocument       = null;
            CatalogDocument parentCatalogDocument = null;

            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                ICatalogDocumentRepository repository = scope.GetRepository <ICatalogDocumentRepository>();

                catalogDocument = await repository.GetAsync(catalog.ID);

                catalogDocument = await this.mapper.MapAsync(catalog, catalogDocument);

                if (catalogDocument.IsChanged)
                {
                    catalogDocument = await repository.SaveAsync(catalogDocument);
                }

                if ((catalog.Parent?.ID).HasValue)
                {
                    parentCatalogDocument = await repository.GetAsync(catalog.Parent.ID);
                }
            }

            catalog = await this.mapper.MapAsync(catalogDocument, catalog);

            catalog.Parent = await this.mapper.MapAsync(parentCatalogDocument, catalog.Parent);

            return(catalog);
        }
Exemple #2
0
        /// <summary>
        /// Creates the specified storage.
        /// </summary>
        /// <param name="storage">The instance of <see cref="Storage" /> type to create.</param>
        /// <returns>The newly created instance of <see cref="Storage" /> type.</returns>
        public async Task <Storage> CreateStorage(Storage storage)
        {
            CatalogDocument catalogDocument = null;

            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                ICatalogDocumentRepository repository = scope.GetRepository <ICatalogDocumentRepository>();

                catalogDocument = await this.mapper.MapNewAsync <Storage, CatalogDocument>(storage);

                catalogDocument = await repository.SaveAsync(catalogDocument);
            }

            return(await this.mapper.MapAsync(catalogDocument, storage));
        }