Пример #1
0
        public IActionResult Create(Guid productId, [FromBody] ProductOptionViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var product = _productRepository.GetSingle(productId);

            if (product == null)
            {
                return(NotFound());
            }

            var newOption = _mapper.Map <ProductOptionViewModel, ProductOption>(model);

            newOption.ProductId = productId;
            newOption.Product   = product;

            _productOptionRepository.Add(newOption);

            try
            {
                _productOptionRepository.Commit();
            }
            catch (DbUpdateException e)
            {
                _logger.LogCritical(e.Message);
                throw e;
            }

            var newModel = _mapper.Map <ProductOption, ProductOptionViewModel>(newOption);

            return(CreatedAtRoute("GetOption", new { productId = productId, id = newModel.Id }, newModel));
        }
Пример #2
0
        public void Handle(CreateProductOptionCommand command)
        {
            _productOptionRepository.Add(new Model.ProductOption()
            {
                Name        = command.Name,
                Description = command.Description
            });

            Commit();
        }
Пример #3
0
        public ProductOption CreateOption(Guid productId, ProductOption productOption)
        {
            if (productOption == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            try
            {
                productOption.ProductId = productId;
                return(_productOptionRepository.Add(productOption));
            }
            catch (FluentValidation.ValidationException)
            {
                //TODO: here we can add a lot of code
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
        public async Task <IActionResult> AddProductOption([FromBody] ProductOptionDto productOptionDto)
        {
            if (await productOptionRepository.GetProductOption(productOptionDto.PublicId) != null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"ProductOption with this PublicId == {productOptionDto.PublicId} already exists"));
            }
            var productOption = new ProductOption(productOptionDto.ProductId,
                                                  productOptionDto.Name, productOptionDto.IsMultiple, productOptionDto.PublicId);

            productOption.SetAccountingName(productOptionDto.AccountingName);
            productOption.SetNomenclatureId(productOptionDto.NomenclatureId);
            //productOption.SetKindId(productOptionDto.KindId);

            await productOptionRepository.Add(productOption);

            await unitOfWork.SaveEntitiesAsync();

            return(Ok());
        }