public void AddNewProduct(Product product)
 {
     if (!AlreadyExists(product.Name))
     {
         productStorage.Add(product);
     }
 }
        public async Task <ProductOutcomeDTO> Add(ProductDTO newProduct)
        {
            if (!await _productStorage.IsValidName(_mapper.Map <ProductEntity>(newProduct)))
            {
                throw new AppValidationException($"Product {newProduct.Name} is already exist!");
            }

            return(_mapper.Map <ProductOutcomeDTO>(await _productStorage.Add(_mapper.Map <ProductEntity>(newProduct))));
        }
示例#3
0
        public void Add(Product product)
        {
            // Always upsert underlying product repository and update cache
            _inner.Add(product);
            _cache.Set(product.Id.ToCacheKey(), product);

            // See if all was previously cached as a list
            if (_cache.TryGetValue(AllCacheKey, out IList <Product> all) == true)
            {
                // We need to upsert the cached product as the full list has now been modified
                IList <Product> newAll = all
                                         .Where(p => p.Id != product.Id)
                                         .ToList();
                newAll.Add(product);

                _cache.Set(AllCacheKey, newAll);
            }
        }
示例#4
0
        public void Add(Product product)
        {
            EnsureAdministrator();

            _inner.Add(product);
        }