Esempio n. 1
0
        public ProductDto CreateProductSale(CreateProductSaleInput input)
        {
            Logger.Info("Start CreateProductSale");

            CreateProductSaleValidator validator = new CreateProductSaleValidator(_productRepository);

            ValidationResult resultValidator = validator.Validate(input);

            if (!resultValidator.IsValid)
            {
                throw new UserFriendlyException(resultValidator.Errors.ToJsonString());
            }

            var product = _objectMapper.Map <Product>(input);

            _productDomainService.ActiveProduct(product);

            _productRepository.Insert(product);

            var productSale = _productDomainService.CreateProductSale(product);

            _productSaleRepository.Insert(productSale);

            var currency = _objectMapper.Map <Currency>(input);

            var productSalePrice = _productDomainService.AssingPrice(productSale, input.Price, currency);

            _productSalePriceRepository.InsertOrUpdate(productSalePrice);

            Logger.Info("Finish CreateProductSale");

            return(_objectMapper.Map <ProductDto>(product));
        }