public async Task <ProductWithIngredients> InsertOrUpdate(ProductWithIngredients productWithIngredients)
        {
            var filter = Builders <ProductWithIngredients> .Filter.Eq(p => p.Id, productWithIngredients.Id);

            var options = new UpdateOptions {
                IsUpsert = true
            };

            await _mongoCollection.ReplaceOneAsync(filter, productWithIngredients, options);

            return(productWithIngredients);
        }
コード例 #2
0
        public async Task MergeProductWithIngredientsAsync(ProductToGet storeProduct)
        {
            var productIngredients = storeProduct.Items.Select(i => i.Name).ToList();
            var ingredients        = await _unitOfWork.IngredientsRepository.GetByNamesAsync(productIngredients);

            if (ingredients.Any() == false)
            {
                ingredients = _mapper.Map <IList <Ingredient> >(storeProduct.Items);
            }

            var productWithIngredients = new ProductWithIngredients
            {
                Id          = storeProduct.ProductId.ToString(),
                StoreId     = storeProduct.StoreId.ToString(),
                Ingredients = ingredients
            };

            await _unitOfWork.MergedProductsRepository.InsertOrUpdate(productWithIngredients);
        }