public void Create(FullProductDto combined)
        {
            Product        product;
            ProductVersion productVersion;
            var            sameNameProductVersion = _productVersionRepository.GetMany(x => x.Name.Equals(combined.Name) && !x.SoftDelete && !Guid.Equals(x.Id, combined.ProductVersionId));

            if (sameNameProductVersion.Count() != 0)
            {
                throw new BusinessException(ExceptionCode.DuplicateProductNames);
            }

            combined.SplitCombinedProduct(out productVersion, out product);
            _productRepository.Create(product);
            _productVersionRepository.Create(productVersion);
        }
Ejemplo n.º 2
0
        public void Create(FullProductDto combined)
        {
            Product        product;
            ProductVersion productVersion;

            if (_productVersionRepository.Count() > 0)
            {
                var sameNameProductVersion = _productVersionRepository.GetMany(x => x.Name.Equals(combined.Name) && !x.SoftDelete && !Guid.Equals(x.Id, combined.ProductVersionId));

                if (sameNameProductVersion.Count() != 0)
                {
                    throw new BusinessException(ExceptionCode.DuplicateProductNames);
                }
            }

            combined.SplitCombinedProduct(out productVersion, out product);

            if (product != null && productVersion != null)
            {
                using (var scope = _productVersionRepository.DatabaseFacade.BeginTransaction())
                {
                    try
                    {
                        _productRepository.Create(product);
                        _productRepository.SaveChanges();
                        _productVersionRepository.Create(productVersion);
                        _productVersionRepository.SaveChanges();
                        scope.Commit();
                    }
                    catch (Exception e)
                    {
                        throw new BusinessException(ExceptionCode.Unhandled);
                    }
                }
            }
            else
            {
                throw new BusinessException(ExceptionCode.Unhandled);
            }
        }